open-index/open-npm huggingface dataset:
npm package: @hoge1e3/unload
Description: A utility to handle the beforeunload event, preventing accidental page exits with an optional cancellation callback.
Latest version: 1.0.0

# @hoge1e3/unload

A utility to handle the beforeunload event, preventing accidental page exits with an optional cancellation callback.

## Installation

`npm install @hoge1e3/unload`

## Usage

~~~javascript
import setUnload from "@hoge1e3/unload";
const unloadHandler = setUnload({
    oncancel: () => console.log("Unload prevented!")
});
// To force allow unloading:
unloadHandler.setForce(true);
~~~

## API

- setUnload(options?: { oncancel?: () => void })
  - `options.oncancel` (optional): A function to be called when the unload action is canceled.
- Returns an object with:
  - `setForce(force: boolean)`: Allows forced unloading when true.


## License

MIT