You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

function-once

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

function-once

Wraps a function so that it's only ever executed once.

3.0.1
latest
Source
npmnpm
Version published
Weekly downloads
6K
-5.05%
Maintainers
1
Weekly downloads
 
Created
Source

Function Once

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.

Install

npm install function-once

Usage

import 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.3344627371267874

License

MIT © Fabio Spampinato

Keywords

once

FAQs

Package last updated on 17 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts