diff options
author | Rebecca Turner <me@re-becca.org> | 2016-06-24 00:55:58 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2016-06-24 00:55:58 +0300 |
commit | e44d2db1ad0d860ca08e99c81135bd399fb733b1 (patch) | |
tree | cfc6fac144893ed4caccbee2e193cb729575688a /node_modules/aproba | |
parent | b9243ee60a3d60505c2502dc8633811b42c8aaea (diff) |
aproba@1.0.4
Better docs and some minor pure refactoring.
Credit: @iarna
Diffstat (limited to 'node_modules/aproba')
-rw-r--r-- | node_modules/aproba/.npmignore | 3 | ||||
-rw-r--r-- | node_modules/aproba/README.md | 8 | ||||
-rw-r--r-- | node_modules/aproba/index.js | 6 | ||||
-rw-r--r-- | node_modules/aproba/package.json | 71 | ||||
-rw-r--r-- | node_modules/aproba/test/index.js | 87 |
5 files changed, 50 insertions, 125 deletions
diff --git a/node_modules/aproba/.npmignore b/node_modules/aproba/.npmignore deleted file mode 100644 index 24001896d..000000000 --- a/node_modules/aproba/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -*~ -node_modules -.#* diff --git a/node_modules/aproba/README.md b/node_modules/aproba/README.md index f4df17429..8246a9cc6 100644 --- a/node_modules/aproba/README.md +++ b/node_modules/aproba/README.md @@ -1,7 +1,7 @@ aproba ====== -A rediculously light-weight function argument validator +A ridiculously light-weight function argument validator ``` var validate = require("aproba") @@ -34,7 +34,11 @@ E | instanceof Error OR null Validation failures throw one of three exception types, distinguished by a `code` property of `EMISSINGARG`, `EINVALIDTYPE` or `ETOOMANYARGS`. -If an error argument is found and is not null then the remaining arguments will not be validated. +If you pass in an invalid type then it will throw with a code of +`EUNKNOWNTYPE`. + +If an error argument is found and is not null then the remaining arguments +will not be validated. ### Why this exists diff --git a/node_modules/aproba/index.js b/node_modules/aproba/index.js index 6d1c17ece..bb5ac3cda 100644 --- a/node_modules/aproba/index.js +++ b/node_modules/aproba/index.js @@ -1,8 +1,12 @@ 'use strict' +function isArguments (thingy) { + return typeof thingy === 'object' && thingy.hasOwnProperty('callee') +} + var types = { '*': ['any', function () { return true }], - A: ['array', function (thingy) { return (Array.isArray && Array.isArray(thingy)) || (typeof thingy === 'object' && thingy.hasOwnProperty('callee')) }], + A: ['array', function (thingy) { return Array.isArray(thingy) || isArguments(thingy) }], S: ['string', function (thingy) { return typeof thingy === 'string' }], N: ['number', function (thingy) { return typeof thingy === 'number' }], F: ['function', function (thingy) { return typeof thingy === 'function' }], diff --git a/node_modules/aproba/package.json b/node_modules/aproba/package.json index 56452c406..b5e08a31c 100644 --- a/node_modules/aproba/package.json +++ b/node_modules/aproba/package.json @@ -2,51 +2,55 @@ "_args": [ [ { - "name": "aproba", - "raw": "aproba@latest", - "rawSpec": "latest", + "raw": "aproba@~1.0.3", "scope": null, - "spec": "latest", - "type": "tag" + "escapedName": "aproba", + "name": "aproba", + "rawSpec": "~1.0.3", + "spec": ">=1.0.3 <1.1.0", + "type": "range" }, - "/Users/zkat/Documents/code/npm" + "/Users/rebecca/code/npm" ] ], - "_from": "aproba@latest", - "_id": "aproba@1.0.3", + "_from": "aproba@>=1.0.3 <1.1.0", + "_id": "aproba@1.0.4", "_inCache": true, "_installable": true, "_location": "/aproba", "_nodeVersion": "4.4.0", "_npmOperationalInternal": { "host": "packages-12-west.internal.npmjs.com", - "tmp": "tmp/aproba-1.0.3.tgz_1463784729571_0.7574592484161258" + "tmp": "tmp/aproba-1.0.4.tgz_1466718885402_0.5348939662799239" }, "_npmUser": { - "email": "me@re-becca.org", - "name": "iarna" + "name": "iarna", + "email": "me@re-becca.org" }, - "_npmVersion": "3.9.2", + "_npmVersion": "3.10.2", "_phantomChildren": {}, "_requested": { - "name": "aproba", - "raw": "aproba@latest", - "rawSpec": "latest", + "raw": "aproba@~1.0.3", "scope": null, - "spec": "latest", - "type": "tag" + "escapedName": "aproba", + "name": "aproba", + "rawSpec": "~1.0.3", + "spec": ">=1.0.3 <1.1.0", + "type": "range" }, "_requiredBy": [ - "/" + "#USER", + "/", + "/npmlog/gauge" ], - "_resolved": "https://registry.npmjs.org/aproba/-/aproba-1.0.3.tgz", - "_shasum": "7fb6da3a72c70249db63fd9b5c64b31af718a94f", + "_resolved": "https://registry.npmjs.org/aproba/-/aproba-1.0.4.tgz", + "_shasum": "2713680775e7614c8ba186c065d4e2e52d1072c0", "_shrinkwrap": null, - "_spec": "aproba@latest", - "_where": "/Users/zkat/Documents/code/npm", + "_spec": "aproba@~1.0.3", + "_where": "/Users/rebecca/code/npm", "author": { - "email": "me@re-becca.org", - "name": "Rebecca Turner" + "name": "Rebecca Turner", + "email": "me@re-becca.org" }, "bugs": { "url": "https://github.com/iarna/aproba/issues" @@ -54,17 +58,20 @@ "dependencies": {}, "description": "A rediculously light-weight argument validator", "devDependencies": { - "standard": "^7.1.0", - "tap": "^5.7.1" + "standard": "^7.1.2", + "tap": "^5.7.3" }, "directories": { "test": "test" }, "dist": { - "shasum": "7fb6da3a72c70249db63fd9b5c64b31af718a94f", - "tarball": "https://registry.npmjs.org/aproba/-/aproba-1.0.3.tgz" + "shasum": "2713680775e7614c8ba186c065d4e2e52d1072c0", + "tarball": "https://registry.npmjs.org/aproba/-/aproba-1.0.4.tgz" }, - "gitHead": "20cc4fc6589bbf870c3ca7bb8b9cb203af9d96a5", + "files": [ + "index.js" + ], + "gitHead": "c6c8f82d519b9ec3816f20f23a9101083c022200", "homepage": "https://github.com/iarna/aproba", "keywords": [ "argument", @@ -74,8 +81,8 @@ "main": "index.js", "maintainers": [ { - "email": "me@re-becca.org", - "name": "iarna" + "name": "iarna", + "email": "me@re-becca.org" } ], "name": "aproba", @@ -88,5 +95,5 @@ "scripts": { "test": "standard && tap test/*.js" }, - "version": "1.0.3" + "version": "1.0.4" } diff --git a/node_modules/aproba/test/index.js b/node_modules/aproba/test/index.js deleted file mode 100644 index b96fd4216..000000000 --- a/node_modules/aproba/test/index.js +++ /dev/null @@ -1,87 +0,0 @@ -'use strict' -var test = require('tap').test -var validate = require('../index.js') - -function thrown (t, code, msg, todo) { - validate('OSSF', arguments) - try { - todo() - t.fail(msg) - } catch (e) { - t.is(e.code, code, msg + e.message) - } -} - -function notThrown (t, msg, todo) { - validate('OSF', arguments) - try { - todo() - t.pass(msg) - } catch (e) { - t.fail(msg + '\n' + e.stack) - } -} - -test('general', function (t) { - t.plan(70) - var values = { - 'A': [], - 'S': 'test', - 'N': 123, - 'F': function () {}, - 'O': {}, - 'B': false, - 'E': new Error() - } - Object.keys(values).forEach(function (type) { - Object.keys(values).forEach(function (contraType) { - if (type === contraType) { - notThrown(t, type + ' matches ' + contraType, function () { - validate(type, [values[contraType]]) - }) - } else { - thrown(t, 'EINVALIDTYPE', type + ' does not match ' + contraType, function () { - validate(type, [values[contraType]]) - }) - } - }) - if (type === 'E') { - notThrown(t, 'null is ok for E', function () { - validate(type, [null]) - }) - } else { - thrown(t, 'EMISSINGARG', 'null not ok for ' + type, function () { - validate(type, [null]) - }) - } - }) - Object.keys(values).forEach(function (contraType) { - notThrown(t, '* matches ' + contraType, function () { - validate('*', [values[contraType]]) - }) - }) - thrown(t, 'EMISSINGARG', 'not enough args', function () { - validate('SNF', ['abc', 123]) - }) - thrown(t, 'ETOOMANYARGS', 'too many args', function () { - validate('SNF', ['abc', 123, function () {}, true]) - }) - notThrown(t, 'E matches null', function () { - validate('E', [null]) - }) - notThrown(t, 'E matches undefined', function () { - validate('E', [undefined]) - }) - notThrown(t, 'E w/ error requires nothing else', function () { - validate('ESN', [new Error(), 'foo']) - }) - thrown(t, 'EMISSINGARG', 'E w/o error works as usual', function () { - validate('ESN', [null, 'foo']) - }) - try { - validate('O', [[]]) - t.fail('object != array') - } catch (ex) { - t.match(ex.message, /Expected object but got array/, 'When reporting non-objects, uses aproba types') - } -}) |