when-exit

Execute a function right before the process, or the browser's tab, is about to exit.

MIT 8 个版本
安装
npm install when-exit
yarn add when-exit
pnpm add when-exit
bun add when-exit
README

WhenExit

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

版本列表
2.1.5 2025-10-28
2.1.4 2025-01-12
2.1.3 2024-06-30
2.1.2 2023-12-09
2.1.1 2023-08-03
2.1.0 2023-02-15
2.0.0 2022-04-06
1.0.0 2022-02-08