Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wrappy

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wrappy

Callback wrapping utility

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is wrappy?

The wrappy npm package is a simple utility module designed to wrap asynchronous functions. It ensures that the callback provided to the wrapped function is only called once, which can be useful in preventing issues where a callback might accidentally be called multiple times due to programming errors.

What are wrappy's main functionalities?

Callback wrapping

This code demonstrates how to use wrappy to wrap a callback function so that it can only be called once. The 'once' function wraps the provided function 'fn' using wrappy, ensuring that subsequent calls to 'wrapped' after the first one have no effect.

const wrappy = require('wrappy')

function once (fn) {
  return wrappy(function () {
    if (fn === null) return
    var callFn = fn
    fn = null
    callFn.apply(this, arguments)
  })
}

var wrapped = once(function (a) {
  console.log('Called with', a)
})

wrapped('first call')
wrapped('second call') // This will not be called

Other packages similar to wrappy

FAQs

Package last updated on 17 May 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc