package
Wraps a function so that it's only ever executed once.
npm install function-onceGitHub-flavored package documentation.
Across all versions, last 30 days.
164,104 in 30 days
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
2.7 kB
Includes dependencies.
Wraps a function so that it's only ever executed once.
Note: this is always set to undefined and only functions that don't accept any arguments are supported, as using those with a function that's only ever executed once is practically just a footgun. If you need different this or different arguments you should probably use memoization instead.
npm install function-onceimport once from 'function-once';
// Let's make sure a function is at most executed only once
const rand = once (() => Math.random ());
rand (); // => 0.3344627371267874
rand (); // => 0.3344627371267874MIT © Fabio Spampinato