mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
[log-process-errors] Add type definitions for 'log-process-errors' (#35464)
* Add base type definitions for log-process-errors. * Correct return type of LogProcessErrors function. * Add log-process-errors tests. * Add tsconfig and tslint for log-process-errors. * Correct import path for log-process-errors-tests.ts. * Define minimal compatible TypeScript version for log-process-errors * Correct placement of log-process-errors type definitions. * Make options in LogProcessErrors function optional * Define `testing` and `colors` properties of LogProcessErrorsOptions as optional. * Use camelCase for logProcessErrors function to be more inline with log-process-errors' documentation. * Correct log-process-errors exports. * Remove redundant exports from logProcessErrors namespace.
This commit is contained in:
committed by
Nathan Shively-Sanders
parent
7dda14dff5
commit
695b694eb9
Vendored
+68
@@ -0,0 +1,68 @@
|
||||
// Type definitions for log-process-errors 4.1
|
||||
// Project: https://git.io/fhSGY
|
||||
// Definitions by: Jørgen Vatle <https://github.com/JorgenVatle>
|
||||
// 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> | void;
|
||||
|
||||
/**
|
||||
* Which log level to use for different exceptions.
|
||||
*
|
||||
* https://github.com/ehmicky/log-process-errors/blob/master/docs/API.md#log
|
||||
*/
|
||||
level?: Partial<Record<ExceptionType, LogLevel>> & {
|
||||
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;
|
||||
@@ -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();
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user