wrappy (1.0.2)

Published 2026-02-24 14:08:51 +00:00 by atheaadmin

Installation

registry=
npm install wrappy@1.0.2
"wrappy": "1.0.2"

About this package

wrappy

Callback wrapping utility

USAGE

var wrappy = require("wrappy")

// var wrapper = wrappy(wrapperFunction)

// make sure a cb is called only once
// See also: http://npm.im/once for this specific use case
var once = wrappy(function (cb) {
  var called = false
  return function () {
    if (called) return
    called = true
    return cb.apply(this, arguments)
  }
})

function printBoo () {
  console.log('boo')
}
// has some rando property
printBoo.iAmBooPrinter = true

var onlyPrintOnce = once(printBoo)

onlyPrintOnce() // prints 'boo'
onlyPrintOnce() // does nothing

// random property is retained!
assert.equal(onlyPrintOnce.iAmBooPrinter, true)

Dependencies

Development Dependencies

ID Version
tap ^2.3.1
Details
npm
2026-02-24 14:08:51 +00:00
0
Isaac Z. Schlueter
ISC
latest
1.6 KiB
Assets (1)
Versions (1) View all
1.0.2 2026-02-24