mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[@types/statuses] Update definitions to 2.0 (#45567)
* Update definitions to version 2.0 * Add v1 for backward compatibility
This commit is contained in:
parent
b0ba89b995
commit
42b35aebe5
21
types/statuses/index.d.ts
vendored
21
types/statuses/index.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
// Type definitions for statuses 1.5
|
||||
// Type definitions for statuses 2.0
|
||||
// Project: https://github.com/jshttp/statuses
|
||||
// Definitions by: Tanguy Krotoff <https://github.com/tkrotoff>
|
||||
// BendingBender <https://github.com/BendingBender>
|
||||
@ -6,22 +6,15 @@
|
||||
|
||||
export = status;
|
||||
|
||||
declare const status: Status & CodesToMessages & MessagesToCodes;
|
||||
declare const status: Status;
|
||||
|
||||
interface Status {
|
||||
STATUS_CODES: { [code: number]: string };
|
||||
(code_msg: number | string): number | string;
|
||||
|
||||
codes: number[];
|
||||
redirect: { [code: number]: boolean | undefined };
|
||||
code: { [msg: string]: number | undefined };
|
||||
empty: { [code: number]: boolean | undefined };
|
||||
message: { [code: number]: string | undefined };
|
||||
redirect: { [code: number]: boolean | undefined };
|
||||
retry: { [code: number]: boolean | undefined };
|
||||
|
||||
(code: number | string): number;
|
||||
}
|
||||
|
||||
interface CodesToMessages {
|
||||
[code: number]: string | undefined;
|
||||
}
|
||||
|
||||
interface MessagesToCodes {
|
||||
[msg: string]: number | undefined;
|
||||
}
|
||||
|
||||
@ -1,23 +1,22 @@
|
||||
import status = require('statuses');
|
||||
|
||||
status.STATUS_CODES[404]; // $ExpectType string
|
||||
let code_msg: number | string;
|
||||
|
||||
let code: number | undefined;
|
||||
|
||||
code = status(403); // => 403
|
||||
code = status('403'); // => 403
|
||||
code = status('forbidden'); // => 403
|
||||
code = status('Forbidden'); // => 403
|
||||
code = status(306); // throws, as it's not supported by node.js
|
||||
code_msg = status(403); // => 'Forbidden'
|
||||
code_msg = status('403'); // => 'Forbidden'
|
||||
code_msg = status('forbidden'); // => 403
|
||||
code_msg = status('Forbidden'); // => 403
|
||||
code_msg = status(306); // throws
|
||||
|
||||
let codes: number[];
|
||||
codes = status.codes;
|
||||
|
||||
let msg: string | undefined;
|
||||
msg = status[404]; // => 'Not Found'
|
||||
msg = status.message[404]; // => 'Not Found'
|
||||
|
||||
code = status['not found']; // => 404
|
||||
code = status['Not Found']; // => 404
|
||||
let code: number | undefined;
|
||||
code = status.code['not found']; // => 404
|
||||
code = status.code['Not Found']; // => 404
|
||||
|
||||
let isRedirect: boolean | undefined;
|
||||
isRedirect = status.redirect[200]; // => undefined
|
||||
|
||||
27
types/statuses/v1/index.d.ts
vendored
Normal file
27
types/statuses/v1/index.d.ts
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
// Type definitions for statuses 1.5
|
||||
// Project: https://github.com/jshttp/statuses
|
||||
// Definitions by: Tanguy Krotoff <https://github.com/tkrotoff>
|
||||
// BendingBender <https://github.com/BendingBender>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export = status;
|
||||
|
||||
declare const status: Status & CodesToMessages & MessagesToCodes;
|
||||
|
||||
interface Status {
|
||||
STATUS_CODES: { [code: number]: string };
|
||||
codes: number[];
|
||||
redirect: { [code: number]: boolean | undefined };
|
||||
empty: { [code: number]: boolean | undefined };
|
||||
retry: { [code: number]: boolean | undefined };
|
||||
|
||||
(code: number | string): number;
|
||||
}
|
||||
|
||||
interface CodesToMessages {
|
||||
[code: number]: string | undefined;
|
||||
}
|
||||
|
||||
interface MessagesToCodes {
|
||||
[msg: string]: number | undefined;
|
||||
}
|
||||
33
types/statuses/v1/statuses-tests.ts
Normal file
33
types/statuses/v1/statuses-tests.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import status = require('statuses');
|
||||
|
||||
status.STATUS_CODES[404]; // $ExpectType string
|
||||
|
||||
let code: number | undefined;
|
||||
|
||||
code = status(403); // => 403
|
||||
code = status('403'); // => 403
|
||||
code = status('forbidden'); // => 403
|
||||
code = status('Forbidden'); // => 403
|
||||
code = status(306); // throws, as it's not supported by node.js
|
||||
|
||||
let codes: number[];
|
||||
codes = status.codes;
|
||||
|
||||
let msg: string | undefined;
|
||||
msg = status[404]; // => 'Not Found'
|
||||
|
||||
code = status['not found']; // => 404
|
||||
code = status['Not Found']; // => 404
|
||||
|
||||
let isRedirect: boolean | undefined;
|
||||
isRedirect = status.redirect[200]; // => undefined
|
||||
isRedirect = status.redirect[301]; // => true
|
||||
|
||||
let isEmpty: boolean | undefined;
|
||||
isEmpty = status.empty[200]; // => undefined
|
||||
isEmpty = status.empty[204]; // => true
|
||||
isEmpty = status.empty[304]; // => true
|
||||
|
||||
let isRetry: boolean | undefined;
|
||||
isRetry = status.retry[501]; // => undefined
|
||||
isRetry = status.retry[503]; // => true
|
||||
31
types/statuses/v1/tsconfig.json
Normal file
31
types/statuses/v1/tsconfig.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"statuses": [
|
||||
"statuses/v1"
|
||||
],
|
||||
"statuses/*": [
|
||||
"statuses/v1/*"
|
||||
]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"statuses-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/statuses/v1/tslint.json
Normal file
1
types/statuses/v1/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user