Execute a function right before the process, or the browser's tab, is about to exit.
- Types
- ESM
- License
- MIT
- Deps
- 0
- Install Size
- 6.9 kB
- Vulns
- 0
- Published
$
npm install when-exit$
pnpm add when-exit$
yarn add when-exit$
bun add when-exit$
deno add npm:when-exit$
vlt install when-exit$
vp add when-exitWhenExit
Execute a function right before the process, or the browser's tab, is about to exit.
Install
npm install when-exit
Usage
import whenExit from 'when-exit';
// Registering multiple callbacks
onExit ( () => {
console.log ( 'Callback 1' );
});
onExit ( () => {
console.log ( 'Callback 2' );
});
// Registering and disposing a callback
const disposer = onExit ( () => {
console.log ( 'Callback 3' );
});
disposer ();
// Triggering the process to exit
process.exit (); // Callback 1 and 2 are called before exiting
License
MIT © Fabio Spampinato