summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/aproba/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/aproba/index.js')
-rw-r--r--deps/npm/node_modules/aproba/index.js66
1 files changed, 33 insertions, 33 deletions
diff --git a/deps/npm/node_modules/aproba/index.js b/deps/npm/node_modules/aproba/index.js
index 6f3f797c09..fd947481ba 100644
--- a/deps/npm/node_modules/aproba/index.js
+++ b/deps/npm/node_modules/aproba/index.js
@@ -1,38 +1,39 @@
'use strict'
+module.exports = validate
function isArguments (thingy) {
return thingy != null && typeof thingy === 'object' && thingy.hasOwnProperty('callee')
}
-var types = {
- '*': {label: 'any', check: function () { return true }},
- A: {label: 'array', check: function (thingy) { return Array.isArray(thingy) || isArguments(thingy) }},
- S: {label: 'string', check: function (thingy) { return typeof thingy === 'string' }},
- N: {label: 'number', check: function (thingy) { return typeof thingy === 'number' }},
- F: {label: 'function', check: function (thingy) { return typeof thingy === 'function' }},
- O: {label: 'object', check: function (thingy) { return typeof thingy === 'object' && thingy != null && !types.A.check(thingy) && !types.E.check(thingy) }},
- B: {label: 'boolean', check: function (thingy) { return typeof thingy === 'boolean' }},
- E: {label: 'error', check: function (thingy) { return thingy instanceof Error }},
- Z: {label: 'null', check: function (thingy) { return thingy == null }}
+const types = {
+ '*': {label: 'any', check: () => true},
+ A: {label: 'array', check: _ => Array.isArray(_) || isArguments(_)},
+ S: {label: 'string', check: _ => typeof _ === 'string'},
+ N: {label: 'number', check: _ => typeof _ === 'number'},
+ F: {label: 'function', check: _ => typeof _ === 'function'},
+ O: {label: 'object', check: _ => typeof _ === 'object' && _ != null && !types.A.check(_) && !types.E.check(_)},
+ B: {label: 'boolean', check: _ => typeof _ === 'boolean'},
+ E: {label: 'error', check: _ => _ instanceof Error},
+ Z: {label: 'null', check: _ => _ == null}
}
function addSchema (schema, arity) {
- var group = arity[schema.length] = arity[schema.length] || []
+ const group = arity[schema.length] = arity[schema.length] || []
if (group.indexOf(schema) === -1) group.push(schema)
}
-var validate = module.exports = function (rawSchemas, args) {
+function validate (rawSchemas, args) {
if (arguments.length !== 2) throw wrongNumberOfArgs(['SA'], arguments.length)
if (!rawSchemas) throw missingRequiredArg(0, 'rawSchemas')
if (!args) throw missingRequiredArg(1, 'args')
if (!types.S.check(rawSchemas)) throw invalidType(0, ['string'], rawSchemas)
if (!types.A.check(args)) throw invalidType(1, ['array'], args)
- var schemas = rawSchemas.split('|')
- var arity = {}
+ const schemas = rawSchemas.split('|')
+ const arity = {}
- schemas.forEach(function (schema) {
- for (var ii = 0; ii < schema.length; ++ii) {
- var type = schema[ii]
+ schemas.forEach(schema => {
+ for (let ii = 0; ii < schema.length; ++ii) {
+ const type = schema[ii]
if (!types[type]) throw unknownType(ii, type)
}
if (/E.*E/.test(schema)) throw moreThanOneError(schema)
@@ -43,20 +44,18 @@ var validate = module.exports = function (rawSchemas, args) {
if (schema.length === 1) addSchema('', arity)
}
})
- var matching = arity[args.length]
+ let matching = arity[args.length]
if (!matching) {
throw wrongNumberOfArgs(Object.keys(arity), args.length)
}
- for (var ii = 0; ii < args.length; ++ii) {
- var newMatching = matching.filter(function (schema) {
- var type = schema[ii]
- var typeCheck = types[type].check
+ for (let ii = 0; ii < args.length; ++ii) {
+ let newMatching = matching.filter(schema => {
+ const type = schema[ii]
+ const typeCheck = types[type].check
return typeCheck(args[ii])
})
if (!newMatching.length) {
- var labels = matching.map(function (schema) {
- return types[schema[ii]].label
- }).filter(function (schema) { return schema != null })
+ const labels = matching.map(_ => types[_[ii]].label).filter(_ => _ != null)
throw invalidType(ii, labels, args[ii])
}
matching = newMatching
@@ -72,8 +71,8 @@ function unknownType (num, type) {
}
function invalidType (num, expectedTypes, value) {
- var valueType
- Object.keys(types).forEach(function (typeCode) {
+ let valueType
+ Object.keys(types).forEach(typeCode => {
if (types[typeCode].check(value)) valueType = types[typeCode].label
})
return newException('EINVALIDTYPE', 'Argument #' + (num + 1) + ': Expected ' +
@@ -85,8 +84,8 @@ function englishList (list) {
}
function wrongNumberOfArgs (expected, got) {
- var english = englishList(expected)
- var args = expected.every(function (ex) { return ex.length === 1 })
+ const english = englishList(expected)
+ const args = expected.every(ex => ex.length === 1)
? 'argument'
: 'arguments'
return newException('EWRONGARGCOUNT', 'Expected ' + english + ' ' + args + ' but got ' + got)
@@ -98,8 +97,9 @@ function moreThanOneError (schema) {
}
function newException (code, msg) {
- var e = new Error(msg)
- e.code = code
- if (Error.captureStackTrace) Error.captureStackTrace(e, validate)
- return e
+ const err = new Error(msg)
+ err.code = code
+ /* istanbul ignore else */
+ if (Error.captureStackTrace) Error.captureStackTrace(err, validate)
+ return err
}