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
npm install one-time
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
9 Stars
44 Commits
3 Forks
5 Watching
1 Branches
3 Contributors
Updated on 10 Jul 2023
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-9.9%
1,655,148
Compared to previous day
Last week
0.4%
9,847,288
Compared to previous week
Last month
6.5%
41,576,137
Compared to previous month
Last year
4.4%
436,006,638
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
25 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
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