# function-once

> Wraps a function so that it's only ever executed once.

Latest version **3.0.1** (published 2025-01-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install function-once
pnpm add function-once
yarn add function-once
bun add function-once
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2025-01-17 |
| First published | 2023-08-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Maintainers | fabiospampinato |
| Keywords | once, function, call |

## Links

- npm: https://www.npmjs.com/package/function-once
- Repository: https://github.com/fabiospampinato/function-once
- Homepage: https://github.com/fabiospampinato/function-once#readme
- Issues: https://github.com/fabiospampinato/function-once/issues
- npm.io page: https://npm.io/package/function-once

## Recent versions

- 3.0.1 (latest) — 2025-01-17
- 3.0.0 — 2023-08-09

## README

# Function Once

Wraps a function so that it's only ever executed once.

Note: `this` is always set to `undefined` and only functions that don't accept any arguments are supported, as using those with a function that's only ever executed once is practically just a footgun. If you need different `this` or different arguments you should probably use memoization instead.

## Install

```sh
npm install function-once
```

## Usage

```ts
import once from 'function-once';

// Let's make sure a function is at most executed only once

const rand = once (() => Math.random ());

rand (); // => 0.3344627371267874
rand (); // => 0.3344627371267874
```

## License

MIT © Fabio Spampinato

---
_Source: https://npm.io/package/function-once · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
