• Home
Name Date Size #Lines LOC

..--

LICENSED12-May-2024765 1612

README.mdD12-May-2024685 3727

package.jsonD12-May-20241.3 KiB6564

wrappy.jsD12-May-2024905 3424

README.md

1# wrappy
2
3Callback wrapping utility
4
5## USAGE
6
7```javascript
8var wrappy = require("wrappy")
9
10// var wrapper = wrappy(wrapperFunction)
11
12// make sure a cb is called only once
13// See also: http://npm.im/once for this specific use case
14var once = wrappy(function (cb) {
15  var called = false
16  return function () {
17    if (called) return
18    called = true
19    return cb.apply(this, arguments)
20  }
21})
22
23function printBoo () {
24  console.log('boo')
25}
26// has some rando property
27printBoo.iAmBooPrinter = true
28
29var onlyPrintOnce = once(printBoo)
30
31onlyPrintOnce() // prints 'boo'
32onlyPrintOnce() // does nothing
33
34// random property is retained!
35assert.equal(onlyPrintOnce.iAmBooPrinter, true)
36```
37