node/deps/npm/node_modules/wrappy
Rebecca Turner d538811fc8 deps: upgrade npm to 3.10.2
Contains the following npm releases:
- https://github.com/npm/npm/releases/tag/v3.9.6
- https://github.com/npm/npm/releases/tag/v3.10.0
- https://github.com/npm/npm/releases/tag/v3.10.1
- https://github.com/npm/npm/releases/tag/v3.10.2

PR-URL: https://github.com/nodejs/node/pull/7410
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-06-27 11:46:15 +02:00
..
LICENSE npm: Upgrade to v2.1.6 2014-11-05 10:35:43 -08:00
README.md npm: Upgrade to v2.1.6 2014-11-05 10:35:43 -08:00
package.json deps: upgrade npm to 3.10.2 2016-06-27 11:46:15 +02:00
wrappy.js npm: Upgrade to v2.1.6 2014-11-05 10:35:43 -08:00

README.md

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)