https://github.com/revington/zd-once
Zero deps, Ensure a function is only called once
https://github.com/revington/zd-once
once
Last synced: 4 months ago
JSON representation
Zero deps, Ensure a function is only called once
- Host: GitHub
- URL: https://github.com/revington/zd-once
- Owner: revington
- License: mit
- Created: 2018-04-24T08:04:08.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2025-09-16T09:43:50.000Z (9 months ago)
- Last Synced: 2025-09-18T16:43:09.098Z (9 months ago)
- Topics: once
- Language: JavaScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/revington/zd-once)
[](https://snyk.io/test/github/revington/zd-once?targetFile=package.json)
[](https://coveralls.io/github/revington/zd-once?branch=master)
# zd-once
Ensure a function is only called once. Zero deps and simple codebase.
## Install
```
$ npm install zd-once
```
## Usage
```
const {
once
} = require('zd-once');
function sum(a, b) {
return a + b;
}
let sumOnce = once(sum);
console.log(sumOnce(1, 2)); // prints 3
console.log(sumOnce(1, 2)); // prints nothing
```
## API
* `once(fn)` ensures a function is called only once.
* `onceStrict(fn)` similar to `once(fn)`. It will throw an error if called more than once.