CB-12003 updated node_modules

This commit is contained in:
Steve Gill
2016-10-17 10:50:30 -07:00
parent 2e37d2c253
commit 0b710a86a9
36 changed files with 602 additions and 299 deletions
+28
View File
@@ -49,3 +49,31 @@ function load (cb) {
})
}
```
## `once.strict(func)`
Throw an error if the function is called twice.
Some functions are expected to be called only once. Using `once` for them would
potentially hide logical errors.
In the example below, the `greet` function has to call the callback only once:
```javascript
function greet (name, cb) {
// return is missing from the if statement
// when no name is passed, the callback is called twice
if (!name) cb('Hello anonymous')
cb('Hello ' + name)
}
function log (msg) {
console.log(msg)
}
// this will print 'Hello anonymous' but the logical error will be missed
greet(null, once(msg))
// once.strict will print 'Hello anonymous' and throw an error when the callback will be called the second time
greet(null, once.strict(msg))
```
Generated Vendored
+21
View File
@@ -1,5 +1,6 @@
var wrappy = require('wrappy')
module.exports = wrappy(once)
module.exports.strict = wrappy(onceStrict)
once.proto = once(function () {
Object.defineProperty(Function.prototype, 'once', {
@@ -8,6 +9,13 @@ once.proto = once(function () {
},
configurable: true
})
Object.defineProperty(Function.prototype, 'onceStrict', {
value: function () {
return onceStrict(this)
},
configurable: true
})
})
function once (fn) {
@@ -19,3 +27,16 @@ function once (fn) {
f.called = false
return f
}
function onceStrict (fn) {
var f = function () {
if (f.called)
throw new Error(f.onceError)
f.called = true
return f.value = fn.apply(this, arguments)
}
var name = fn.name || 'Function wrapped with `once`'
f.onceError = name + " shouldn't be called more than once"
f.called = false
return f
}
+17 -11
View File
@@ -14,16 +14,20 @@
]
],
"_from": "once@>=1.3.0 <2.0.0",
"_id": "once@1.3.3",
"_id": "once@1.4.0",
"_inCache": true,
"_installable": true,
"_location": "/once",
"_nodeVersion": "4.0.0",
"_nodeVersion": "6.5.0",
"_npmOperationalInternal": {
"host": "packages-12-west.internal.npmjs.com",
"tmp": "tmp/once-1.4.0.tgz_1473196269128_0.537820661207661"
},
"_npmUser": {
"name": "isaacs",
"email": "i@izs.me"
},
"_npmVersion": "3.3.2",
"_npmVersion": "3.10.7",
"_phantomChildren": {},
"_requested": {
"raw": "once@^1.3.0",
@@ -35,11 +39,13 @@
"type": "range"
},
"_requiredBy": [
"/cli/glob",
"/glob",
"/inflight"
"/inflight",
"/istanbul"
],
"_resolved": "http://registry.npmjs.org/once/-/once-1.3.3.tgz",
"_shasum": "b2e261557ce4c314ec8304f3fa82663e4297ca20",
"_resolved": "http://registry.npmjs.org/once/-/once-1.4.0.tgz",
"_shasum": "583b1aa775961d4b113ac17d9c50baef9dd76bd1",
"_shrinkwrap": null,
"_spec": "once@^1.3.0",
"_where": "/Users/steveng/repo/cordova/cordova-android/node_modules/glob",
@@ -56,19 +62,19 @@
},
"description": "Run a function exactly one time",
"devDependencies": {
"tap": "^1.2.0"
"tap": "^7.0.1"
},
"directories": {
"test": "test"
},
"dist": {
"shasum": "b2e261557ce4c314ec8304f3fa82663e4297ca20",
"tarball": "https://registry.npmjs.org/once/-/once-1.3.3.tgz"
"shasum": "583b1aa775961d4b113ac17d9c50baef9dd76bd1",
"tarball": "https://registry.npmjs.org/once/-/once-1.4.0.tgz"
},
"files": [
"once.js"
],
"gitHead": "2ad558657e17fafd24803217ba854762842e4178",
"gitHead": "0e614d9f5a7e6f0305c625f6b581f6d80b33b8a6",
"homepage": "https://github.com/isaacs/once#readme",
"keywords": [
"once",
@@ -94,5 +100,5 @@
"scripts": {
"test": "tap test/*.js"
},
"version": "1.3.3"
"version": "1.4.0"
}