diff --git a/http-assert/http-assert-tests.ts b/http-assert/http-assert-tests.ts new file mode 100644 index 0000000000..b95561b635 --- /dev/null +++ b/http-assert/http-assert-tests.ts @@ -0,0 +1,11 @@ +import * as httpAssert from 'http-assert'; +import { HttpError } from 'http-errors'; + +try { + httpAssert.equal('hello', 'hello'); + httpAssert(false, 401, 'authentication failed'); +} catch(err) { + console.log((err).status); + console.log((err).message); + console.log((err).expose); +} diff --git a/http-assert/index.d.ts b/http-assert/index.d.ts new file mode 100644 index 0000000000..47b283db92 --- /dev/null +++ b/http-assert/index.d.ts @@ -0,0 +1,52 @@ +// Type definitions for http-assert 1.2 +// Project: https://github.com/jshttp/http-assert +// Definitions by: jKey Lu +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * @param {number} [status] the status code + * @param {string} [msg] the message of the error, defaulting to node's text for that status code + * @param {object} [opts] custom properties to attach to the error object + */ +declare function assert(value: any, status?: number, msg?: string, opts?: {}): void; + +declare namespace assert { + /** + * @param {number} [status] the status code + * @param {string} [msg] the message of the error, defaulting to node's text for that status code + * @param {object} [opts] custom properties to attach to the error object + */ + function equal(a: T, b: T, status?: number, msg?: string, opts?: {}): void; + /** + * @param {number} [status] the status code + * @param {string} [msg] the message of the error, defaulting to node's text for that status code + * @param {object} [opts] custom properties to attach to the error object + */ + function notEqual(a: T, b: T, status?: number, msg?: string, opts?: {}): void; + /** + * @param {number} [status] the status code + * @param {string} [msg] the message of the error, defaulting to node's text for that status code + * @param {object} [opts] custom properties to attach to the error object + */ + function strictEqual(a: T, b: T, status?: number, msg?: string, opts?: {}): void; + /** + * @param {number} [status] the status code + * @param {string} [msg] the message of the error, defaulting to node's text for that status code + * @param {object} [opts] custom properties to attach to the error object + */ + function notStrictEqual(a: T, b: T, status?: number, msg?: string, opts?: {}): void; + /** + * @param {number} [status] the status code + * @param {string} [msg] the message of the error, defaulting to node's text for that status code + * @param {object} [opts] custom properties to attach to the error object + */ + function deepEqual(a: T, b: T, status?: number, msg?: string, opts?: {}): void; + /** + * @param {number} [status] the status code + * @param {string} [msg] the message of the error, defaulting to node's text for that status code + * @param {object} [opts] custom properties to attach to the error object + */ + function notDeepEqual(a: T, b: T, status?: number, msg?: string, opts?: {}): void; +} + +export = assert; diff --git a/http-assert/tsconfig.json b/http-assert/tsconfig.json new file mode 100644 index 0000000000..bef302b296 --- /dev/null +++ b/http-assert/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "http-assert-tests.ts" + ] +} diff --git a/http-assert/tslint.json b/http-assert/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/http-assert/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }