Skip to content

Commit

Permalink
feature(types): add type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
demurgos committed Oct 9, 2018
1 parent 1cc979f commit cd56ac0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
52 changes: 52 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
declare namespace signalExit {
export interface SignalExitOptions {
/**
* Run this handler after any other signal or exit handlers.
* This causes `process.emit` to be monkeypatched.
*
* Default: `false`
*/
alwaysLast?: boolean;
}

/**
* Removes the corresponding listener.
*/
export type RemoveListener = () => void;

/**
* The exit listener is passed two arguments.
*
* It is guaranteed that exactly one of them is `null` and the other not.
*
* - `code`: Exit code of the process. Present for example when Node exits
* normally (end of program) or after `process.exit(code)`.
* - `signal`: Signal causing the process to exit. Present for example
* when using `process.kill(process.pid, signal)`.
*/
export type SignalExitListener = (code: number | null, signal: NodeJS.Signals | null) => any;

export interface SignalExit {
/**
* Adds a listener fired when the current process exits, no matter how.
*
* Note that the function *only* fires for signals if the signal would
* cause the proces to exit. That is, there are no other listeners, and
* it is a fatal signal.
*
* @param listener See [[SignalExitListener]].
* @param options See [[SignalExitOptions]].
* @return Function to remove the listener.
*/
(listener: SignalExitListener, options?: Readonly<SignalExitOptions>): RemoveListener;

/**
* Returns the platform-dependent list of exit signals.
*/
signals(): NodeJS.Signals[];
}
}

declare const signalExit: signalExit.SignalExit;

export = signalExit;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "3.0.2",
"description": "when you want to fire an event no matter how a process exits.",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"pretest": "standard",
"test": "tap --timeout=240 ./test/*.js --cov",
Expand Down

0 comments on commit cd56ac0

Please sign in to comment.