Gathering detailed insights and metrics for onetime
Gathering detailed insights and metrics for onetime
Gathering detailed insights and metrics for onetime
Gathering detailed insights and metrics for onetime
npm install onetime
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
162 Stars
47 Commits
14 Forks
8 Watching
1 Branches
9 Contributors
Updated on 24 Aug 2024
Minified
Minified + Gzipped
JavaScript (81.2%)
TypeScript (18.8%)
Cumulative downloads
Total Downloads
Last day
-7.4%
13,478,302
Compared to previous day
Last week
0.9%
78,500,307
Compared to previous week
Last month
11.5%
325,718,647
Compared to previous month
Last year
30%
3,194,947,802
Compared to previous year
1
Ensure a function is only called once
When called multiple times it will return the return value from the first call.
Unlike the module once, this one isn't naughty and extending Function.prototype
.
1npm install onetime
1import onetime from 'onetime'; 2 3let index = 0; 4 5const foo = onetime(() => ++index); 6 7foo(); //=> 1 8foo(); //=> 1 9foo(); //=> 1 10 11onetime.callCount(foo); //=> 3
1import onetime from 'onetime'; 2 3const foo = onetime(() => {}, {throw: true}); 4 5foo(); 6 7foo(); 8//=> Error: Function `foo` can only be called once
Returns a function that only calls fn
once.
Type: Function
The function that should only be called once.
Type: object
Type: boolean
Default: false
Throw an error when called more than once.
Returns a number representing how many times fn
has been called.
Note: It throws an error if you pass in a function that is not wrapped by onetime
.
1import onetime from 'onetime'; 2 3const foo = onetime(() => {}); 4 5foo(); 6foo(); 7foo(); 8 9console.log(onetime.callCount(foo)); 10//=> 3
Type: Function
The function to get call count from.
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 8/30 approved changesets -- score normalized to 2
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
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
Score
Last Scanned on 2024-11-18
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