diff --git a/types/log-process-errors/index.d.ts b/types/log-process-errors/index.d.ts new file mode 100644 index 0000000000..8a9e494374 --- /dev/null +++ b/types/log-process-errors/index.d.ts @@ -0,0 +1,68 @@ +// Type definitions for log-process-errors 4.1 +// Project: https://git.io/fhSGY +// Definitions by: Jørgen Vatle +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +declare namespace logProcessErrors { + /** + * Log level + */ + type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent' | 'default'; + + /** + * Exception type. + */ + type ExceptionType = 'uncaughtException' | 'unhandledRejection' | 'rejectionHandled' | 'multipleResolves' | 'warning'; + + /** + * log-process-errors constructor options. + */ + interface Options { + /** + * Override logger + * + * @link https://github.com/ehmicky/log-process-errors/blob/master/docs/API.md#log + */ + log?(error: Error, level: LogLevel): Promise | void; + + /** + * Which log level to use for different exceptions. + * + * https://github.com/ehmicky/log-process-errors/blob/master/docs/API.md#log + */ + level?: Partial> & { + default?(error: Error): 'silent' | 'default'; + }; + + /** + * Which process should trigger `process.exit(1)` + * + * @link https://github.com/ehmicky/log-process-errors/blob/master/docs/API.md#exiton + */ + exitOn?: ExceptionType[]; + + /** + * When running tests, makes them fail if there are any process errors. + * + * @link https://github.com/ehmicky/log-process-errors/blob/master/docs/API.md#testing + */ + testing?: 'ava' | 'mocha' | 'jasmine' | 'tape' | 'node-tap'; + + /** + * Whether or not to colorize messages. + * + * @link https://github.com/ehmicky/log-process-errors/blob/master/docs/API.md#colors + */ + colors?: boolean; + } +} + +/** + * Log Process Errors + * + * @link https://github.com/ehmicky/log-process-errors/blob/master/docs/API.md#logprocesserrorsoptions + */ +declare function logProcessErrors(options?: logProcessErrors.Options): () => void; + +export = logProcessErrors; diff --git a/types/log-process-errors/log-process-errors-tests.ts b/types/log-process-errors/log-process-errors-tests.ts new file mode 100644 index 0000000000..5d8b88862c --- /dev/null +++ b/types/log-process-errors/log-process-errors-tests.ts @@ -0,0 +1,24 @@ +import * as LogProcessErrors from 'log-process-errors'; + +/** + * Initialize log-process-errors with example options. + */ +const reset = LogProcessErrors({ + log(error, level) { + const someErr: Error = error; + const someLogLevel: LogProcessErrors.LogLevel = level; + }, + + level: { multipleResolves: 'debug' }, + + exitOn: ['uncaughtException', 'unhandledRejection'], + + testing: 'ava', + + colors: false, +}); + +/** + * Restore default Node.js error handling functionality. + */ +reset(); diff --git a/types/log-process-errors/tsconfig.json b/types/log-process-errors/tsconfig.json new file mode 100644 index 0000000000..08dae10399 --- /dev/null +++ b/types/log-process-errors/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "log-process-errors-tests.ts" + ] +} diff --git a/types/log-process-errors/tslint.json b/types/log-process-errors/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/log-process-errors/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}