Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on Apr 18, 2024 via pnpm

once 1.4.0

Run a function exactly one time
Package summary
Share
0
issues
1
license
2
ISC
Package created
14 Aug 2012
Version published
6 Sep 2016
Maintainers
1
Total deps
2
Direct deps
1
License
ISC

Issues

0
This package has no issues

Licenses

ISC License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
Cannot
hold-liable
Must
include-copyright
include-license
2 Packages, Including:
once@1.4.0
wrappy@1.0.2
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

1
All Dependencies CSV
β“˜ This is a list of once 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities
wrappy1.0.21.64 kBISC
prod

Visualizations

Frequently Asked Questions

What does once do?

"once" is a JavaScript utility available via npm, designed to ensure a function is only executed a single time. This helps to prevent duplication of function calls, which can be particularly useful in scenarios where you need to ensure a process such as event handling, data loading, or an API call is only actioned a single time.

How do you use once?

To use "once", first you need to install it via npm using npm install once. You can then require('once') in your JavaScript file and use it to wrap the function you want to be executed only once.

Here's an example of using "once":

var once = require('once')

function load (file, cb) {
  cb = once(cb)
  loader.load('file')
  loader.once('load', cb)
  loader.once('error', cb)
}

"once" can also add to the Function.prototype, ensuring the function is called only once. This feature can be enabled by calling require('once').proto().

// this only needs to be done once
require('once').proto()

function load (file, cb) {
  cb = cb.once()
  loader.load('file')
  loader.once('load', cb)
  loader.once('error', cb)
}

The utility also provides a 'once.strict' function to enforce that a function can only be called once. This is particularly useful for debugging, as it will throw an error if a function is attempted to be called more than once. This can help identify logical errors in your code.

// once.strict will print 'Hello anonymous' 
// and throw an error when the callback will be called the second time
greet(null, once.strict(msg))

Where are the once docs?

The documentation for "once" can be found in the readme of their GitHub repository. It provides a comprehensive guide on how to use the utility, the functions it offers and the relevant syntax to ensure correct usage.