Gathering detailed insights and metrics for one-time
Gathering detailed insights and metrics for one-time
Gathering detailed insights and metrics for one-time
Gathering detailed insights and metrics for one-time
Run the supplied function exactly one time (once).
npm install one-time
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
1,741,872,305
Last Day
1,940,248
Last Week
10,423,158
Last Month
44,142,674
Last Year
471,240,978
MIT License
9 Stars
44 Commits
3 Forks
4 Watchers
1 Branches
3 Contributors
Updated on Jul 10, 2023
Minified
Minified + Gzipped
Latest Version
1.0.0
Package Id
one-time@1.0.0
Size
2.63 kB
NPM Version
6.4.0
Node Version
8.11.4
Published on
May 05, 2019
Cumulative downloads
Total Downloads
Last Day
45.7%
1,940,248
Compared to previous day
Last Week
4.7%
10,423,158
Compared to previous week
Last Month
-3.3%
44,142,674
Compared to previous month
Last Year
7.3%
471,240,978
Compared to previous year
Call the supplied function exactly one time. This prevents double callback
execution. This module can be used on both Node.js, React-Native, or browsers
using Browserify. No magical ES5/6 methods used unlike the once
module does
(except for the async version).
This module is published to the public npm registry and can be installed by running:
1npm install --save one-time
Simply supply the function with the function that should only be called one time:
1var one = require('one-time'); 2 3function load(file, fn) { 4 fn = one(fn); 5 6 eventemitter.once('load', fn); 7 eventemitter.once('error', fn); 8 9 // do stuff 10 eventemitter.emit('error', new Error('Failed to load, but still finished')); 11 eventemitter.emit('load'); 12} 13 14function example(fn) { 15 fn = one(fn); 16 17 fn(); 18 fn('also receives all arguments'); 19 fn('it returns the same value') === 'bar'; 20 fn('never'); 21 fn('gonna'); 22 fn('give'); 23 fn('you'); 24 fn('up'); 25} 26 27example(function () { 28 return 'bar' 29});
The same pattern is available for async functions as well, for that you
should import that one-time/async
version instead. This one is optimized
for async and await support. It following exactly the same as the
normal version but assumes it's an async function () {}
that it's wrapping
instead of a regular function, and it will return an async function() {}
instead of a regular function.
1import one from 'one-time/async'; 2 3const fn = one(async function () { 4 return await example(); 5}); 6 7await fn(); 8await fn(); 9await fn();
once
?The main reason is that once
cannot be used in a browser environment unless
it's ES5 compatible. For a module as simple as this I find that unacceptable. In
addition to that it super heavy on the dependency side. So it's totally not
suitable to be used in client side applications.
In addition to that we make sure that your code stays easy to debug as returned functions are named in the same way as your supplied functions. Making heap inspection and stack traces easier to understand.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/19 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
26 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More