Installations
npm install one-time
Releases
Unable to fetch releases
Developer
3rd-Eden
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
8.11.4
NPM Version
6.4.0
Statistics
9 Stars
44 Commits
3 Forks
5 Watching
1 Branches
3 Contributors
Updated on 10 Jul 2023
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
1,519,733,242
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
one-time
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).
Installation
This module is published to the public npm registry and can be installed by running:
1npm install --save one-time
Usage (normal)
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});
Usage (async)
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();
Why not 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.
License
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Reason
25 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.7
/10
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