check-types-mini
Advanced tools
Comparing version 3.4.4 to 4.0.0
@@ -8,2 +8,31 @@ # Change Log | ||
## [4.0.0] - 2018-07-03 | ||
I felt a need for this feature since the very beginning but only now the API's of my librarires started to become complex-enough to warrant nested options' objects. | ||
- ✨ Now, we accept and enforce _nested options objects_. For example, you can have defaults as: | ||
```js | ||
{ | ||
oodles: { | ||
noodles: true; | ||
} | ||
} | ||
``` | ||
and if user customised your options object to the following, `check-types-mini` will throw: | ||
```js | ||
{ | ||
oodles: { | ||
noodles: "zzz"; // | ||
} | ||
} | ||
// => oodles.noodles is a string, not Boolean | ||
``` | ||
- ✨ Also, rebased the code quite substantially, with some new deps and some old deps removed. | ||
- ✨ `opts.ignorePaths` because now `opts.ignoreKeys` is not enough - what if key names are called the same in different nested opts object key's value child object key's values? | ||
- ✨ Implemented _throw pinning_. It's fancy term meaning all internal errors are named with an ID and all unit tests are not just checking, _does it throw_ but _does it throw the particular error_, because it can _throw_ but _throw at wrong place_ that would be a defect, yet unit test would pass. As a side effect, this doesn't lock the throw error messages in the unit tests. Since we pin against the ID, we can tweak the error messages' text as much as we want as long as ID is kept the same. | ||
## [3.4.0] - 2018-06-10 | ||
@@ -15,3 +44,2 @@ | ||
- ✨ Dropped BitHound (RIP) and Travis | ||
- ✨ Removed `package-lock` | ||
@@ -144,3 +172,3 @@ ## [3.3.0] - 2018-05-11 | ||
[1.5.0]: https://bitbucket.org/codsen/check-types-mini/branches/compare/v1.5.0%0Dv1.4.1#diff | ||
[1.6.0]: https://bitbucket.org/codsen/check-types-mini/branches/compare/v1.6.0%0Dv3.4.3#diff | ||
[1.6.0]: https://bitbucket.org/codsen/check-types-mini/branches/compare/v1.6.0%0Dv3.4.4#diff | ||
[2.0.0]: https://bitbucket.org/codsen/check-types-mini/branches/compare/v2.0.0%0Dv1.5.0#diff | ||
@@ -159,1 +187,2 @@ [2.1.0]: https://bitbucket.org/codsen/check-types-mini/branches/compare/v2.1.0%0Dv2.0.3#diff | ||
[3.4.0]: https://bitbucket.org/codsen/check-types-mini/branches/compare/v3.4.0%0Dv3.3.1#diff | ||
[4.0.0]: https://bitbucket.org/codsen/check-types-mini/branches/compare/v4.0.0%0Dv3.4.4#diff |
@@ -7,32 +7,32 @@ 'use strict'; | ||
var pullAll = _interopDefault(require('lodash.pullall')); | ||
var traverse = _interopDefault(require('ast-monkey-traverse')); | ||
var intersection = _interopDefault(require('lodash.intersection')); | ||
var arrayiffyIfString = _interopDefault(require('arrayiffy-if-string')); | ||
var objectPath = _interopDefault(require('object-path')); | ||
var ordinal = _interopDefault(require('ordinal')); | ||
function checkTypesMini(obj, originalRef, originalOptions) { | ||
function checkTypesMini(obj, ref, originalOptions) { | ||
var shouldWeCheckTheOpts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true; | ||
function existy(something) { | ||
return something != null; | ||
} | ||
function isBool(something) { | ||
return typ(something) === "boolean"; | ||
} | ||
function isStr(something) { | ||
return typ(something) === "string"; | ||
} | ||
function isObj(something) { | ||
return typ(something) === "Object"; | ||
} | ||
function goUpByOneLevel(path) { | ||
if (path.includes(".")) { | ||
var split = path.split("."); | ||
split.pop(); | ||
return split.join("."); | ||
} | ||
return path; | ||
} | ||
var NAMESFORANYTYPE = ["any", "anything", "every", "everything", "all", "whatever", "whatevs"]; | ||
var isArr = Array.isArray; | ||
if (arguments.length === 0) { | ||
throw new Error("check-types-mini: [THROW_ID_01] Missing all arguments!"); | ||
if (!existy(obj)) { | ||
throw new Error("check-types-mini: [THROW_ID_01] First argument is missing!"); | ||
} | ||
if (arguments.length === 1) { | ||
throw new Error("check-types-mini: [THROW_ID_02] Missing second argument!"); | ||
} | ||
var ref = isObj(originalRef) ? originalRef : {}; | ||
var defaults = { | ||
ignoreKeys: [], | ||
ignorePaths: [], | ||
acceptArrays: false, | ||
@@ -51,100 +51,100 @@ acceptArraysIgnore: [], | ||
} | ||
if (!isStr(opts.msg)) { | ||
throw new Error("check-types-mini: [THROW_ID_03] opts.msg must be string! Currently it's: " + typ(opts.msg) + ", equal to " + JSON.stringify(opts.msg, null, 4)); | ||
if (!existy(opts.ignoreKeys) || !opts.ignoreKeys) { | ||
opts.ignoreKeys = []; | ||
} else { | ||
opts.ignoreKeys = arrayiffyIfString(opts.ignoreKeys); | ||
} | ||
opts.msg = opts.msg.trim(); | ||
if (opts.msg[opts.msg.length - 1] === ":") { | ||
opts.msg = opts.msg.slice(0, opts.msg.length - 1); | ||
if (!existy(opts.ignorePaths) || !opts.ignorePaths) { | ||
opts.ignorePaths = []; | ||
} else { | ||
opts.ignorePaths = arrayiffyIfString(opts.ignorePaths); | ||
} | ||
if (!isStr(opts.optsVarName)) { | ||
throw new Error("check-types-mini: [THROW_ID_04] opts.optsVarName must be string! Currently it's: " + typ(opts.optsVarName) + ", equal to " + JSON.stringify(opts.optsVarName, null, 4)); | ||
if (!existy(opts.acceptArraysIgnore) || !opts.acceptArraysIgnore) { | ||
opts.acceptArraysIgnore = []; | ||
} else { | ||
opts.acceptArraysIgnore = arrayiffyIfString(opts.acceptArraysIgnore); | ||
} | ||
opts.ignoreKeys = arrayiffyIfString(opts.ignoreKeys); | ||
opts.acceptArraysIgnore = arrayiffyIfString(opts.acceptArraysIgnore); | ||
// make every schema object key's value to be an array: | ||
if (!isArr(opts.ignoreKeys)) { | ||
throw new TypeError("check-types-mini: [THROW_ID_05] opts.ignoreKeys should be an array, currently it's: " + typ(opts.ignoreKeys)); | ||
opts.msg = typeof opts.msg === "string" ? opts.msg.trim() : opts.msg; | ||
if (opts.msg[opts.msg.length - 1] === ":") { | ||
opts.msg = opts.msg.slice(0, opts.msg.length - 1).trim(); | ||
} | ||
if (!isBool(opts.acceptArrays)) { | ||
throw new TypeError("check-types-mini: [THROW_ID_06] opts.acceptArrays should be a Boolean, currently it's: " + typ(opts.acceptArrays)); | ||
if (opts.schema) { | ||
Object.keys(opts.schema).forEach(function (oneKey) { | ||
if (!isArr(opts.schema[oneKey])) { | ||
opts.schema[oneKey] = [opts.schema[oneKey]]; | ||
} | ||
opts.schema[oneKey] = opts.schema[oneKey].map(String).map(function (el) { | ||
return el.toLowerCase(); | ||
}).map(function (el) { | ||
return el.trim(); | ||
}); | ||
}); | ||
} | ||
if (!isArr(opts.acceptArraysIgnore)) { | ||
throw new TypeError("check-types-mini: [THROW_ID_07] opts.acceptArraysIgnore should be an array, currently it's: " + typ(opts.acceptArraysIgnore)); | ||
if (!existy(ref)) { | ||
ref = {}; | ||
} | ||
if (!isBool(opts.enforceStrictKeyset)) { | ||
throw new TypeError("check-types-mini: [THROW_ID_08] opts.enforceStrictKeyset should be a Boolean, currently it's: " + typ(opts.enforceStrictKeyset)); | ||
if (shouldWeCheckTheOpts) { | ||
checkTypesMini(opts, defaults, { enforceStrictKeyset: false }, false); | ||
} | ||
Object.keys(opts.schema).forEach(function (oneKey) { | ||
if (!isArr(opts.schema[oneKey])) { | ||
opts.schema[oneKey] = [opts.schema[oneKey]]; | ||
} | ||
// then turn all keys into strings and trim and lowercase them: | ||
opts.schema[oneKey] = opts.schema[oneKey].map(String).map(function (el) { | ||
return el.toLowerCase(); | ||
}).map(function (el) { | ||
return el.trim(); | ||
}); | ||
}); | ||
if (opts.enforceStrictKeyset) { | ||
if (existy(opts.schema) && Object.keys(opts.schema).length > 0) { | ||
if (pullAll(Object.keys(obj), Object.keys(ref).concat(Object.keys(opts.schema))).length !== 0) { | ||
throw new TypeError(opts.msg + ": " + opts.optsVarName + ".enforceStrictKeyset is on and the following keys are not covered by schema and/or reference objects: " + JSON.stringify(pullAll(Object.keys(obj), Object.keys(ref).concat(Object.keys(opts.schema))), null, 4)); | ||
var keys = pullAll(Object.keys(obj), Object.keys(ref).concat(Object.keys(opts.schema))); | ||
throw new TypeError(opts.msg + ": " + opts.optsVarName + ".enforceStrictKeyset is on and the following key" + (keys.length > 1 ? "s" : "") + " " + (keys.length > 1 ? "are" : "is") + " not covered by schema and/or reference objects: " + keys.join(", ")); | ||
} | ||
} else if (existy(ref) && Object.keys(ref).length > 0) { | ||
if (pullAll(Object.keys(obj), Object.keys(ref)).length !== 0) { | ||
throw new TypeError(opts.msg + ": The input object has keys that are not covered by reference object: " + JSON.stringify(pullAll(Object.keys(obj), Object.keys(ref)), null, 4)); | ||
var _keys = pullAll(Object.keys(obj), Object.keys(ref)); | ||
throw new TypeError(opts.msg + ": The input object has key" + (_keys.length > 1 ? "s" : "") + " which " + (_keys.length > 1 ? "are" : "is") + " not covered by the reference object: " + _keys.join(", ")); | ||
} else if (pullAll(Object.keys(ref), Object.keys(obj)).length !== 0) { | ||
throw new TypeError(opts.msg + ": The reference object has keys that are not present in the input object: " + JSON.stringify(pullAll(Object.keys(ref), Object.keys(obj)), null, 4)); | ||
var _keys2 = pullAll(Object.keys(ref), Object.keys(obj)); | ||
throw new TypeError(opts.msg + ": The reference object has key" + (_keys2.length > 1 ? "s" : "") + " which " + (_keys2.length > 1 ? "are" : "is") + " not present in the input object: " + _keys2.join(", ")); | ||
} | ||
} else { | ||
// it's an error because both schema and reference don't exist | ||
throw new TypeError(opts.msg + ": Both " + opts.optsVarName + ".schema and reference objects are missing! We don't have anything to match the keys as you requested via opts.enforceStrictKeyset!"); | ||
} | ||
} | ||
Object.keys(obj).forEach(function (key) { | ||
if (existy(opts.schema) && Object.prototype.hasOwnProperty.call(opts.schema, key)) { | ||
// stage 1. check schema, if present | ||
opts.schema[key] = arrayiffyIfString(opts.schema[key]).map(String).map(function (el) { | ||
return el.toLowerCase(); | ||
}); | ||
// first check does our schema contain any blanket names, "any", "whatever" etc. | ||
if (!intersection(opts.schema[key], NAMESFORANYTYPE).length) { | ||
// because, if not, it means we need to do some work, check types: | ||
if (obj[key] !== true && obj[key] !== false && !opts.schema[key].includes(typ(obj[key]).toLowerCase()) || (obj[key] === true || obj[key] === false) && !opts.schema[key].includes(String(obj[key])) && !opts.schema[key].includes("boolean")) { | ||
// new in v.2.2 | ||
// Check if key's value is array. Then, if it is, check if opts.acceptArrays is on. | ||
// If it is, then iterate through the array, checking does each value conform to the | ||
// types listed in that key's schema entry. | ||
if (isArr(obj[key]) && opts.acceptArrays) { | ||
// check each key: | ||
for (var i = 0, len = obj[key].length; i < len; i++) { | ||
if (!opts.schema[key].includes(typ(obj[key][i]).toLowerCase())) { | ||
throw new TypeError(opts.msg + ": " + opts.optsVarName + "." + key + " is of type " + typ(obj[key][i]).toLowerCase() + ", but only the following are allowed in " + opts.optsVarName + ".schema: " + opts.schema[key]); | ||
traverse(obj, function (key, val, innerObj) { | ||
var current = val !== undefined ? val : key; | ||
if (opts.enforceStrictKeyset && !(!isObj(current) && !isArr(current) && isArr(innerObj.parent)) && (!existy(opts.schema) || !isObj(opts.schema) || isObj(opts.schema) && (!Object.keys(opts.schema).length || !isArr(innerObj.parent) && !Object.prototype.hasOwnProperty.call(opts.schema, innerObj.path) || isArr(innerObj.parent) && !objectPath.has(opts.schema, goUpByOneLevel(innerObj.path)))) && (!existy(ref) || !isObj(ref) || isObj(ref) && (!Object.keys(ref).length || !opts.acceptArrays && !objectPath.has(ref, innerObj.path) || opts.acceptArrays && (!isArr(innerObj.parent) && !objectPath.has(ref, innerObj.path) || isArr(innerObj.parent) && !objectPath.has(ref, goUpByOneLevel(innerObj.path)))))) { | ||
throw new TypeError(opts.msg + ": " + opts.optsVarName + "." + innerObj.path + " is neither covered by reference object (second input argument), nor " + opts.optsVarName + ".schema! To stop this error, turn off " + opts.optsVarName + ".enforceStrictKeyset or provide some type reference (2nd argument or " + opts.optsVarName + ".schema)."); | ||
} else if (isObj(opts.schema) && Object.keys(opts.schema).length && Object.prototype.hasOwnProperty.call(opts.schema, innerObj.path) | ||
) { | ||
var currentKeysSchema = arrayiffyIfString(opts.schema[innerObj.path]).map(String).map(function (el) { | ||
return el.toLowerCase(); | ||
}); | ||
objectPath.set(opts.schema, innerObj.path, currentKeysSchema); | ||
if (!intersection(currentKeysSchema, NAMESFORANYTYPE).length) { | ||
if (current !== true && current !== false && !currentKeysSchema.includes(typ(current).toLowerCase()) || (current === true || current === false) && !currentKeysSchema.includes(String(current)) && !currentKeysSchema.includes("boolean")) { | ||
if (isArr(current) && opts.acceptArrays) { | ||
for (var i = 0, len = current.length; i < len; i++) { | ||
if (!currentKeysSchema.includes(typ(current[i]).toLowerCase())) { | ||
throw new TypeError(opts.msg + ": " + opts.optsVarName + "." + innerObj.path + "." + i + ", the " + ordinal(i + 1) + " element (equal to " + JSON.stringify(current[i], null, 0) + ") is of a type " + typ(current[i]).toLowerCase() + ", but only the following are allowed by the " + opts.optsVarName + ".schema: " + currentKeysSchema.join(", ")); | ||
} | ||
} | ||
} else { | ||
throw new TypeError(opts.msg + ": " + opts.optsVarName + "." + innerObj.path + " was customised to " + (typ(current) !== "string" ? '"' : "") + JSON.stringify(current, null, 0) + (typ(current) !== "string" ? '"' : "") + " (" + typ(current).toLowerCase() + ") which is not among the allowed types in schema (" + currentKeysSchema.join(", ") + ")"); | ||
} | ||
} else { | ||
// only then, throw | ||
throw new TypeError(opts.msg + ": " + opts.optsVarName + "." + key + " was customised to " + JSON.stringify(obj[key], null, 4) + " which is not among the allowed types in schema (" + opts.schema[key] + ") but " + typ(obj[key])); | ||
} | ||
} | ||
} | ||
} else if (existy(ref) && Object.prototype.hasOwnProperty.call(ref, key) && typ(obj[key]) !== typ(ref[key]) && !opts.ignoreKeys.includes(key)) { | ||
if (opts.acceptArrays && isArr(obj[key]) && !opts.acceptArraysIgnore.includes(key)) { | ||
var allMatch = obj[key].every(function (el) { | ||
return typ(el) === typ(ref[key]); | ||
} else if (existy(ref) && Object.keys(ref).length && objectPath.has(ref, innerObj.path) && typ(current) !== typ(objectPath.get(ref, innerObj.path)) && (!opts.ignoreKeys || !opts.ignoreKeys.includes(key)) && (!opts.ignorePaths || !opts.ignorePaths.includes(innerObj.path))) { | ||
var compareTo = objectPath.get(ref, innerObj.path); | ||
if (opts.acceptArrays && isArr(current) && !opts.acceptArraysIgnore.includes(key)) { | ||
var allMatch = current.every(function (el) { | ||
return typ(el).toLowerCase() === typ(ref[key]).toLowerCase(); | ||
}); | ||
if (!allMatch) { | ||
throw new TypeError(opts.msg + ": " + opts.optsVarName + "." + key + " was customised to be array, but not all of its elements are " + typ(ref[key]) + "-type"); | ||
throw new TypeError(opts.msg + ": " + opts.optsVarName + "." + innerObj.path + " was customised to be array, but not all of its elements are " + typ(ref[key]).toLowerCase() + "-type"); | ||
} | ||
} else { | ||
throw new TypeError(opts.msg + ": " + opts.optsVarName + "." + key + " was customised to " + JSON.stringify(obj[key], null, 4) + " which is not " + typ(ref[key]) + " but " + typ(obj[key])); | ||
throw new TypeError(opts.msg + ": " + opts.optsVarName + "." + innerObj.path + " was customised to " + (typ(current).toLowerCase() === "string" ? "" : '"') + JSON.stringify(current, null, 0) + (typ(current).toLowerCase() === "string" ? "" : '"') + " which is not " + typ(compareTo).toLowerCase() + " but " + typ(current).toLowerCase()); | ||
} | ||
} | ||
return current; | ||
}); | ||
} | ||
function externalApi(obj, ref, originalOptions) { | ||
return checkTypesMini(obj, ref, originalOptions); | ||
} | ||
module.exports = checkTypesMini; | ||
module.exports = externalApi; |
import typ from 'type-detect'; | ||
import pullAll from 'lodash.pullall'; | ||
import traverse from 'ast-monkey-traverse'; | ||
import intersection from 'lodash.intersection'; | ||
import arrayiffyIfString from 'arrayiffy-if-string'; | ||
import objectPath from 'object-path'; | ||
import ordinal from 'ordinal'; | ||
function checkTypesMini(obj, originalRef, originalOptions) { | ||
function checkTypesMini( | ||
obj, | ||
ref, | ||
originalOptions, | ||
shouldWeCheckTheOpts = true | ||
) { | ||
function existy(something) { | ||
return something != null; | ||
} | ||
function isBool(something) { | ||
return typ(something) === "boolean"; | ||
} | ||
function isStr(something) { | ||
return typ(something) === "string"; | ||
} | ||
function isObj(something) { | ||
return typ(something) === "Object"; | ||
} | ||
function goUpByOneLevel(path) { | ||
if (path.includes(".")) { | ||
const split = path.split("."); | ||
split.pop(); | ||
return split.join("."); | ||
} | ||
return path; | ||
} | ||
const NAMESFORANYTYPE = [ | ||
@@ -29,14 +39,10 @@ "any", | ||
const isArr = Array.isArray; | ||
if (arguments.length === 0) { | ||
throw new Error("check-types-mini: [THROW_ID_01] Missing all arguments!"); | ||
if (!existy(obj)) { | ||
throw new Error( | ||
"check-types-mini: [THROW_ID_01] First argument is missing!" | ||
); | ||
} | ||
if (arguments.length === 1) { | ||
throw new Error("check-types-mini: [THROW_ID_02] Missing second argument!"); | ||
} | ||
const ref = isObj(originalRef) ? originalRef : {}; | ||
const defaults = { | ||
ignoreKeys: [], | ||
ignorePaths: [], | ||
acceptArrays: false, | ||
@@ -55,64 +61,38 @@ acceptArraysIgnore: [], | ||
} | ||
if (!isStr(opts.msg)) { | ||
throw new Error( | ||
`check-types-mini: [THROW_ID_03] opts.msg must be string! Currently it's: ${typ( | ||
opts.msg | ||
)}, equal to ${JSON.stringify(opts.msg, null, 4)}` | ||
); | ||
if (!existy(opts.ignoreKeys) || !opts.ignoreKeys) { | ||
opts.ignoreKeys = []; | ||
} else { | ||
opts.ignoreKeys = arrayiffyIfString(opts.ignoreKeys); | ||
} | ||
opts.msg = opts.msg.trim(); | ||
if (opts.msg[opts.msg.length - 1] === ":") { | ||
opts.msg = opts.msg.slice(0, opts.msg.length - 1); | ||
if (!existy(opts.ignorePaths) || !opts.ignorePaths) { | ||
opts.ignorePaths = []; | ||
} else { | ||
opts.ignorePaths = arrayiffyIfString(opts.ignorePaths); | ||
} | ||
if (!isStr(opts.optsVarName)) { | ||
throw new Error( | ||
`check-types-mini: [THROW_ID_04] opts.optsVarName must be string! Currently it's: ${typ( | ||
opts.optsVarName | ||
)}, equal to ${JSON.stringify(opts.optsVarName, null, 4)}` | ||
); | ||
if (!existy(opts.acceptArraysIgnore) || !opts.acceptArraysIgnore) { | ||
opts.acceptArraysIgnore = []; | ||
} else { | ||
opts.acceptArraysIgnore = arrayiffyIfString(opts.acceptArraysIgnore); | ||
} | ||
opts.ignoreKeys = arrayiffyIfString(opts.ignoreKeys); | ||
opts.acceptArraysIgnore = arrayiffyIfString(opts.acceptArraysIgnore); | ||
// make every schema object key's value to be an array: | ||
if (!isArr(opts.ignoreKeys)) { | ||
throw new TypeError( | ||
`check-types-mini: [THROW_ID_05] opts.ignoreKeys should be an array, currently it's: ${typ( | ||
opts.ignoreKeys | ||
)}` | ||
); | ||
opts.msg = typeof opts.msg === "string" ? opts.msg.trim() : opts.msg; | ||
if (opts.msg[opts.msg.length - 1] === ":") { | ||
opts.msg = opts.msg.slice(0, opts.msg.length - 1).trim(); | ||
} | ||
if (!isBool(opts.acceptArrays)) { | ||
throw new TypeError( | ||
`check-types-mini: [THROW_ID_06] opts.acceptArrays should be a Boolean, currently it's: ${typ( | ||
opts.acceptArrays | ||
)}` | ||
); | ||
if (opts.schema) { | ||
Object.keys(opts.schema).forEach(oneKey => { | ||
if (!isArr(opts.schema[oneKey])) { | ||
opts.schema[oneKey] = [opts.schema[oneKey]]; | ||
} | ||
opts.schema[oneKey] = opts.schema[oneKey] | ||
.map(String) | ||
.map(el => el.toLowerCase()) | ||
.map(el => el.trim()); | ||
}); | ||
} | ||
if (!isArr(opts.acceptArraysIgnore)) { | ||
throw new TypeError( | ||
`check-types-mini: [THROW_ID_07] opts.acceptArraysIgnore should be an array, currently it's: ${typ( | ||
opts.acceptArraysIgnore | ||
)}` | ||
); | ||
if (!existy(ref)) { | ||
ref = {}; | ||
} | ||
if (!isBool(opts.enforceStrictKeyset)) { | ||
throw new TypeError( | ||
`check-types-mini: [THROW_ID_08] opts.enforceStrictKeyset should be a Boolean, currently it's: ${typ( | ||
opts.enforceStrictKeyset | ||
)}` | ||
); | ||
if (shouldWeCheckTheOpts) { | ||
checkTypesMini(opts, defaults, { enforceStrictKeyset: false }, false); | ||
} | ||
Object.keys(opts.schema).forEach(oneKey => { | ||
if (!isArr(opts.schema[oneKey])) { | ||
opts.schema[oneKey] = [opts.schema[oneKey]]; | ||
} | ||
// then turn all keys into strings and trim and lowercase them: | ||
opts.schema[oneKey] = opts.schema[oneKey] | ||
.map(String) | ||
.map(el => el.toLowerCase()) | ||
.map(el => el.trim()); | ||
}); | ||
if (opts.enforceStrictKeyset) { | ||
@@ -126,13 +106,14 @@ if (existy(opts.schema) && Object.keys(opts.schema).length > 0) { | ||
) { | ||
const keys = pullAll( | ||
Object.keys(obj), | ||
Object.keys(ref).concat(Object.keys(opts.schema)) | ||
); | ||
throw new TypeError( | ||
`${opts.msg}: ${ | ||
opts.optsVarName | ||
}.enforceStrictKeyset is on and the following keys are not covered by schema and/or reference objects: ${JSON.stringify( | ||
pullAll( | ||
Object.keys(obj), | ||
Object.keys(ref).concat(Object.keys(opts.schema)) | ||
), | ||
null, | ||
4 | ||
)}` | ||
}.enforceStrictKeyset is on and the following key${ | ||
keys.length > 1 ? "s" : "" | ||
} ${ | ||
keys.length > 1 ? "are" : "is" | ||
} not covered by schema and/or reference objects: ${keys.join(", ")}` | ||
); | ||
@@ -142,24 +123,21 @@ } | ||
if (pullAll(Object.keys(obj), Object.keys(ref)).length !== 0) { | ||
const keys = pullAll(Object.keys(obj), Object.keys(ref)); | ||
throw new TypeError( | ||
`${ | ||
opts.msg | ||
}: The input object has keys that are not covered by reference object: ${JSON.stringify( | ||
pullAll(Object.keys(obj), Object.keys(ref)), | ||
null, | ||
4 | ||
)}` | ||
`${opts.msg}: The input object has key${ | ||
keys.length > 1 ? "s" : "" | ||
} which ${ | ||
keys.length > 1 ? "are" : "is" | ||
} not covered by the reference object: ${keys.join(", ")}` | ||
); | ||
} else if (pullAll(Object.keys(ref), Object.keys(obj)).length !== 0) { | ||
const keys = pullAll(Object.keys(ref), Object.keys(obj)); | ||
throw new TypeError( | ||
`${ | ||
opts.msg | ||
}: The reference object has keys that are not present in the input object: ${JSON.stringify( | ||
pullAll(Object.keys(ref), Object.keys(obj)), | ||
null, | ||
4 | ||
)}` | ||
`${opts.msg}: The reference object has key${ | ||
keys.length > 1 ? "s" : "" | ||
} which ${ | ||
keys.length > 1 ? "are" : "is" | ||
} not present in the input object: ${keys.join(", ")}` | ||
); | ||
} | ||
} else { | ||
// it's an error because both schema and reference don't exist | ||
throw new TypeError( | ||
@@ -172,37 +150,78 @@ `${opts.msg}: Both ${ | ||
} | ||
Object.keys(obj).forEach(key => { | ||
traverse(obj, (key, val, innerObj) => { | ||
const current = val !== undefined ? val : key; | ||
if ( | ||
existy(opts.schema) && | ||
Object.prototype.hasOwnProperty.call(opts.schema, key) | ||
opts.enforceStrictKeyset && | ||
!(!isObj(current) && !isArr(current) && isArr(innerObj.parent)) && | ||
(!existy(opts.schema) || | ||
!isObj(opts.schema) || | ||
(isObj(opts.schema) && | ||
(!Object.keys(opts.schema).length || | ||
((!isArr(innerObj.parent) && | ||
!Object.prototype.hasOwnProperty.call( | ||
opts.schema, | ||
innerObj.path | ||
)) || | ||
(isArr(innerObj.parent) && | ||
!objectPath.has( | ||
opts.schema, | ||
goUpByOneLevel(innerObj.path) | ||
)))))) && | ||
(!existy(ref) || | ||
!isObj(ref) || | ||
(isObj(ref) && | ||
(!Object.keys(ref).length || | ||
((!opts.acceptArrays && !objectPath.has(ref, innerObj.path)) || | ||
(opts.acceptArrays && | ||
((!isArr(innerObj.parent) && | ||
!objectPath.has(ref, innerObj.path)) || | ||
(isArr(innerObj.parent) && | ||
!objectPath.has(ref, goUpByOneLevel(innerObj.path))))))))) | ||
) { | ||
// stage 1. check schema, if present | ||
opts.schema[key] = arrayiffyIfString(opts.schema[key]) | ||
throw new TypeError( | ||
`${opts.msg}: ${opts.optsVarName}.${ | ||
innerObj.path | ||
} is neither covered by reference object (second input argument), nor ${ | ||
opts.optsVarName | ||
}.schema! To stop this error, turn off ${ | ||
opts.optsVarName | ||
}.enforceStrictKeyset or provide some type reference (2nd argument or ${ | ||
opts.optsVarName | ||
}.schema).` | ||
); | ||
} else if ( | ||
isObj(opts.schema) && | ||
Object.keys(opts.schema).length && | ||
Object.prototype.hasOwnProperty.call(opts.schema, innerObj.path) | ||
) { | ||
const currentKeysSchema = arrayiffyIfString(opts.schema[innerObj.path]) | ||
.map(String) | ||
.map(el => el.toLowerCase()); | ||
// first check does our schema contain any blanket names, "any", "whatever" etc. | ||
if (!intersection(opts.schema[key], NAMESFORANYTYPE).length) { | ||
// because, if not, it means we need to do some work, check types: | ||
objectPath.set(opts.schema, innerObj.path, currentKeysSchema); | ||
if (!intersection(currentKeysSchema, NAMESFORANYTYPE).length) { | ||
if ( | ||
(obj[key] !== true && | ||
obj[key] !== false && | ||
!opts.schema[key].includes(typ(obj[key]).toLowerCase())) || | ||
((obj[key] === true || obj[key] === false) && | ||
!opts.schema[key].includes(String(obj[key])) && | ||
!opts.schema[key].includes("boolean")) | ||
(current !== true && | ||
current !== false && | ||
!currentKeysSchema.includes(typ(current).toLowerCase())) || | ||
((current === true || current === false) && | ||
!currentKeysSchema.includes(String(current)) && | ||
!currentKeysSchema.includes("boolean")) | ||
) { | ||
// new in v.2.2 | ||
// Check if key's value is array. Then, if it is, check if opts.acceptArrays is on. | ||
// If it is, then iterate through the array, checking does each value conform to the | ||
// types listed in that key's schema entry. | ||
if (isArr(obj[key]) && opts.acceptArrays) { | ||
// check each key: | ||
for (let i = 0, len = obj[key].length; i < len; i++) { | ||
if (!opts.schema[key].includes(typ(obj[key][i]).toLowerCase())) { | ||
if (isArr(current) && opts.acceptArrays) { | ||
for (let i = 0, len = current.length; i < len; i++) { | ||
if (!currentKeysSchema.includes(typ(current[i]).toLowerCase())) { | ||
throw new TypeError( | ||
`${opts.msg}: ${opts.optsVarName}.${key} is of type ${typ( | ||
obj[key][i] | ||
).toLowerCase()}, but only the following are allowed in ${ | ||
`${opts.msg}: ${opts.optsVarName}.${ | ||
innerObj.path | ||
}.${i}, the ${ordinal( | ||
i + 1 | ||
)} element (equal to ${JSON.stringify( | ||
current[i], | ||
null, | ||
0 | ||
)}) is of a type ${typ( | ||
current[i] | ||
).toLowerCase()}, but only the following are allowed by the ${ | ||
opts.optsVarName | ||
}.schema: ${opts.schema[key]}` | ||
}.schema: ${currentKeysSchema.join(", ")}` | ||
); | ||
@@ -212,13 +231,14 @@ } | ||
} else { | ||
// only then, throw | ||
throw new TypeError( | ||
`${opts.msg}: ${ | ||
opts.optsVarName | ||
}.${key} was customised to ${JSON.stringify( | ||
obj[key], | ||
null, | ||
4 | ||
)} which is not among the allowed types in schema (${ | ||
opts.schema[key] | ||
}) but ${typ(obj[key])}` | ||
`${opts.msg}: ${opts.optsVarName}.${ | ||
innerObj.path | ||
} was customised to ${ | ||
typ(current) !== "string" ? '"' : "" | ||
}${JSON.stringify(current, null, 0)}${ | ||
typ(current) !== "string" ? '"' : "" | ||
} (${typ( | ||
current | ||
).toLowerCase()}) which is not among the allowed types in schema (${currentKeysSchema.join( | ||
", " | ||
)})` | ||
); | ||
@@ -230,19 +250,24 @@ } | ||
existy(ref) && | ||
Object.prototype.hasOwnProperty.call(ref, key) && | ||
typ(obj[key]) !== typ(ref[key]) && | ||
!opts.ignoreKeys.includes(key) | ||
Object.keys(ref).length && | ||
objectPath.has(ref, innerObj.path) && | ||
typ(current) !== typ(objectPath.get(ref, innerObj.path)) && | ||
(!opts.ignoreKeys || !opts.ignoreKeys.includes(key)) && | ||
(!opts.ignorePaths || !opts.ignorePaths.includes(innerObj.path)) | ||
) { | ||
const compareTo = objectPath.get(ref, innerObj.path); | ||
if ( | ||
opts.acceptArrays && | ||
isArr(obj[key]) && | ||
isArr(current) && | ||
!opts.acceptArraysIgnore.includes(key) | ||
) { | ||
const allMatch = obj[key].every(el => typ(el) === typ(ref[key])); | ||
const allMatch = current.every( | ||
el => typ(el).toLowerCase() === typ(ref[key]).toLowerCase() | ||
); | ||
if (!allMatch) { | ||
throw new TypeError( | ||
`${opts.msg}: ${ | ||
opts.optsVarName | ||
}.${key} was customised to be array, but not all of its elements are ${typ( | ||
`${opts.msg}: ${opts.optsVarName}.${ | ||
innerObj.path | ||
} was customised to be array, but not all of its elements are ${typ( | ||
ref[key] | ||
)}-type` | ||
).toLowerCase()}-type` | ||
); | ||
@@ -252,15 +277,21 @@ } | ||
throw new TypeError( | ||
`${opts.msg}: ${ | ||
opts.optsVarName | ||
}.${key} was customised to ${JSON.stringify( | ||
obj[key], | ||
null, | ||
4 | ||
)} which is not ${typ(ref[key])} but ${typ(obj[key])}` | ||
`${opts.msg}: ${opts.optsVarName}.${ | ||
innerObj.path | ||
} was customised to ${ | ||
typ(current).toLowerCase() === "string" ? "" : '"' | ||
}${JSON.stringify(current, null, 0)}${ | ||
typ(current).toLowerCase() === "string" ? "" : '"' | ||
} which is not ${typ(compareTo).toLowerCase()} but ${typ( | ||
current | ||
).toLowerCase()}` | ||
); | ||
} | ||
} | ||
return current; | ||
}); | ||
} | ||
function externalApi(obj, ref, originalOptions) { | ||
return checkTypesMini(obj, ref, originalOptions); | ||
} | ||
export default checkTypesMini; | ||
export default externalApi; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.checkTypesMini=t()}(this,function(){"use strict";var _="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var e,v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},p=(function(e,t){var o,i,r,a,c,s,u,f,n,y,p,l,h,g,m,d,b,w;e.exports=(o="function"==typeof Promise,i="object"===("undefined"==typeof self?"undefined":v(self))?self:_,r="undefined"!=typeof Symbol,a="undefined"!=typeof Map,c="undefined"!=typeof Set,s="undefined"!=typeof WeakMap,u="undefined"!=typeof WeakSet,f="undefined"!=typeof DataView,n=r&&void 0!==Symbol.iterator,y=r&&void 0!==Symbol.toStringTag,p=c&&"function"==typeof Set.prototype.entries,l=a&&"function"==typeof Map.prototype.entries,h=p&&Object.getPrototypeOf((new Set).entries()),g=l&&Object.getPrototypeOf((new Map).entries()),m=n&&"function"==typeof Array.prototype[Symbol.iterator],d=m&&Object.getPrototypeOf([][Symbol.iterator]()),b=n&&"function"==typeof String.prototype[Symbol.iterator],w=b&&Object.getPrototypeOf(""[Symbol.iterator]()),function(e){var t=void 0===e?"undefined":v(e);if("object"!==t)return t;if(null===e)return"null";if(e===i)return"global";if(Array.isArray(e)&&(!1===y||!(Symbol.toStringTag in e)))return"Array";if("object"===("undefined"==typeof window?"undefined":v(window))&&null!==window){if("object"===v(window.location)&&e===window.location)return"Location";if("object"===v(window.document)&&e===window.document)return"Document";if("object"===v(window.navigator)){if("object"===v(window.navigator.mimeTypes)&&e===window.navigator.mimeTypes)return"MimeTypeArray";if("object"===v(window.navigator.plugins)&&e===window.navigator.plugins)return"PluginArray"}if(("function"==typeof window.HTMLElement||"object"===v(window.HTMLElement))&&e instanceof window.HTMLElement){if("BLOCKQUOTE"===e.tagName)return"HTMLQuoteElement";if("TD"===e.tagName)return"HTMLTableDataCellElement";if("TH"===e.tagName)return"HTMLTableHeaderCellElement"}}var r=y&&e[Symbol.toStringTag];if("string"==typeof r)return r;var n=Object.getPrototypeOf(e);return n===RegExp.prototype?"RegExp":n===Date.prototype?"Date":o&&n===Promise.prototype?"Promise":c&&n===Set.prototype?"Set":a&&n===Map.prototype?"Map":u&&n===WeakSet.prototype?"WeakSet":s&&n===WeakMap.prototype?"WeakMap":f&&n===DataView.prototype?"DataView":a&&n===g?"Map Iterator":c&&n===h?"Set Iterator":m&&n===d?"Array Iterator":b&&n===w?"String Iterator":null===n?"Object":Object.prototype.toString.call(e).slice(8,-1)})}(e={exports:{}},e.exports),e.exports);function l(e,t,r){if(t!=t)return function(e,t,r,n){for(var o=e.length,i=r+(n?1:-1);n?i--:++i<o;)if(t(e[i],i,e))return i;return-1}(e,i,r);for(var n=r-1,o=e.length;++n<o;)if(e[n]===t)return n;return-1}function h(e,t,r,n){for(var o=r-1,i=e.length;++o<i;)if(n(e[o],t))return o;return-1}function i(e){return e!=e}var g=Array.prototype.splice;function r(e,t,r,n){var o,i=n?h:l,a=-1,c=t.length,s=e;for(e===t&&(t=function(e,t){var r=-1,n=e.length;t||(t=Array(n));for(;++r<n;)t[r]=e[r];return t}(t)),r&&(s=function(e,t){for(var r=-1,n=e?e.length:0,o=Array(n);++r<n;)o[r]=t(e[r],r,e);return o}(e,(o=r,function(e){return o(e)})));++a<c;)for(var u=0,f=t[a],y=r?r(f):f;-1<(u=i(s,y,u,n));)s!==e&&g.call(s,u,1),g.call(e,u,1);return e}var m=function(e,t){return e&&e.length&&t&&t.length?r(e,t):e},a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n="__lodash_hash_undefined__",c=9007199254740991,o="[object Function]",s="[object GeneratorFunction]",u=/^\[object .+?Constructor\]$/,t="object"==a(_)&&_&&_.Object===Object&&_,f="object"==("undefined"==typeof self?"undefined":a(self))&&self&&self.Object===Object&&self,y=t||f||Function("return this")();function d(e,t){return!!(e?e.length:0)&&-1<function(e,t,r){if(t!=t)return function(e,t,r,n){var o=e.length,i=r+(n?1:-1);for(;n?i--:++i<o;)if(t(e[i],i,e))return i;return-1}(e,O,r);var n=r-1,o=e.length;for(;++n<o;)if(e[n]===t)return n;return-1}(e,t,0)}function b(e,t,r){for(var n=-1,o=e?e.length:0;++n<o;)if(r(t,e[n]))return!0;return!1}function w(e,t){for(var r=-1,n=e?e.length:0,o=Array(n);++r<n;)o[r]=t(e[r],r,e);return o}function O(e){return e!=e}function j(t){return function(e){return t(e)}}function S(e,t){return e.has(t)}var T,k,A,E=Array.prototype,M=Function.prototype,N=Object.prototype,I=y["__core-js_shared__"],D=(T=/[^.]+$/.exec(I&&I.keys&&I.keys.IE_PROTO||""))?"Symbol(src)_1."+T:"",H=M.toString,K=N.hasOwnProperty,V=N.toString,W=RegExp("^"+H.call(K).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),P=E.splice,L=Math.max,R=Math.min,x=z(y,"Map"),C=z(Object,"create");function J(e){var t=-1,r=e?e.length:0;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function $(e){var t=-1,r=e?e.length:0;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function B(e){var t=-1,r=e?e.length:0;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function F(e){var t=-1,r=e?e.length:0;for(this.__data__=new B;++t<r;)this.add(e[t])}function q(e,t){for(var r,n,o=e.length;o--;)if((r=e[o][0])===(n=t)||r!=r&&n!=n)return o;return-1}function Q(e){return!(!Y(e)||(t=e,D&&D in t))&&(X(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?W:u).test(function(e){if(null!=e){try{return H.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e));var t}function G(e){return(o=t=e)&&"object"==(void 0===o?"undefined":a(o))&&(null!=(r=t)&&("number"==typeof(n=r.length)&&-1<n&&n%1==0&&n<=c)&&!X(r))?e:[];var t,r,n,o}function U(e,t){var r,n,o=e.__data__;return("string"==(n=void 0===(r=t)?"undefined":a(r))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof t?"string":"hash"]:o.map}function z(e,t){var r,n,o=(n=t,null==(r=e)?void 0:r[n]);return Q(o)?o:void 0}function X(e){var t=Y(e)?V.call(e):"";return t==o||t==s}function Y(e){var t=void 0===e?"undefined":a(e);return!!e&&("object"==t||"function"==t)}J.prototype.clear=function(){this.__data__=C?C(null):{}},J.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},J.prototype.get=function(e){var t=this.__data__;if(C){var r=t[e];return r===n?void 0:r}return K.call(t,e)?t[e]:void 0},J.prototype.has=function(e){var t=this.__data__;return C?void 0!==t[e]:K.call(t,e)},J.prototype.set=function(e,t){return this.__data__[e]=C&&void 0===t?n:t,this},$.prototype.clear=function(){this.__data__=[]},$.prototype.delete=function(e){var t=this.__data__,r=q(t,e);return!(r<0||(r==t.length-1?t.pop():P.call(t,r,1),0))},$.prototype.get=function(e){var t=this.__data__,r=q(t,e);return r<0?void 0:t[r][1]},$.prototype.has=function(e){return-1<q(this.__data__,e)},$.prototype.set=function(e,t){var r=this.__data__,n=q(r,e);return n<0?r.push([e,t]):r[n][1]=t,this},B.prototype.clear=function(){this.__data__={hash:new J,map:new(x||$),string:new J}},B.prototype.delete=function(e){return U(this,e).delete(e)},B.prototype.get=function(e){return U(this,e).get(e)},B.prototype.has=function(e){return U(this,e).has(e)},B.prototype.set=function(e,t){return U(this,e).set(e,t),this},F.prototype.add=F.prototype.push=function(e){return this.__data__.set(e,n),this},F.prototype.has=function(e){return this.__data__.has(e)};var Z=(k=function(e){var t=w(e,G);return t.length&&t[0]===e[0]?function(e,t,r){for(var n=r?b:d,o=e[0].length,i=e.length,a=i,c=Array(i),s=1/0,u=[];a--;){var f=e[a];a&&t&&(f=w(f,j(t))),s=R(f.length,s),c[a]=!r&&(t||120<=o&&120<=f.length)?new F(a&&f):void 0}f=e[0];var y=-1,p=c[0];e:for(;++y<o&&u.length<s;){var l=f[y],h=t?t(l):l;if(l=r||0!==l?l:0,!(p?S(p,h):n(u,h,r))){for(a=i;--a;){var g=c[a];if(!(g?S(g,h):n(e[a],h,r)))continue e}p&&p.push(h),u.push(l)}}return u}(t):[]},A=L(void 0===A?k.length-1:A,0),function(){for(var e=arguments,t=-1,r=L(e.length-A,0),n=Array(r);++t<r;)n[t]=e[A+t];t=-1;for(var o=Array(A+1);++t<A;)o[t]=e[t];return o[A]=n,function(e,t,r){switch(r.length){case 0:return e.call(t);case 1:return e.call(t,r[0]);case 2:return e.call(t,r[0],r[1]);case 3:return e.call(t,r[0],r[1],r[2])}return e.apply(t,r)}(k,this,o)});function ee(e){return"string"==typeof e?0<e.length?[e]:[]:e}return function(n,e,t){function o(e){return null!=e}function r(e){return"boolean"===p(e)}function i(e){return"string"===p(e)}function a(e){return"Object"===p(e)}var c=["any","anything","every","everything","all","whatever","whatevs"],s=Array.isArray;if(0===arguments.length)throw new Error("check-types-mini: [THROW_ID_01] Missing all arguments!");if(1===arguments.length)throw new Error("check-types-mini: [THROW_ID_02] Missing second argument!");var u=a(e)?e:{},f={ignoreKeys:[],acceptArrays:!1,acceptArraysIgnore:[],enforceStrictKeyset:!0,schema:{},msg:"check-types-mini",optsVarName:"opts"},y=void 0;if(!i((y=o(t)&&a(t)?Object.assign({},f,t):Object.assign({},f)).msg))throw new Error("check-types-mini: [THROW_ID_03] opts.msg must be string! Currently it's: "+p(y.msg)+", equal to "+JSON.stringify(y.msg,null,4));if(y.msg=y.msg.trim(),":"===y.msg[y.msg.length-1]&&(y.msg=y.msg.slice(0,y.msg.length-1)),!i(y.optsVarName))throw new Error("check-types-mini: [THROW_ID_04] opts.optsVarName must be string! Currently it's: "+p(y.optsVarName)+", equal to "+JSON.stringify(y.optsVarName,null,4));if(y.ignoreKeys=ee(y.ignoreKeys),y.acceptArraysIgnore=ee(y.acceptArraysIgnore),!s(y.ignoreKeys))throw new TypeError("check-types-mini: [THROW_ID_05] opts.ignoreKeys should be an array, currently it's: "+p(y.ignoreKeys));if(!r(y.acceptArrays))throw new TypeError("check-types-mini: [THROW_ID_06] opts.acceptArrays should be a Boolean, currently it's: "+p(y.acceptArrays));if(!s(y.acceptArraysIgnore))throw new TypeError("check-types-mini: [THROW_ID_07] opts.acceptArraysIgnore should be an array, currently it's: "+p(y.acceptArraysIgnore));if(!r(y.enforceStrictKeyset))throw new TypeError("check-types-mini: [THROW_ID_08] opts.enforceStrictKeyset should be a Boolean, currently it's: "+p(y.enforceStrictKeyset));if(Object.keys(y.schema).forEach(function(e){s(y.schema[e])||(y.schema[e]=[y.schema[e]]),y.schema[e]=y.schema[e].map(String).map(function(e){return e.toLowerCase()}).map(function(e){return e.trim()})}),y.enforceStrictKeyset)if(o(y.schema)&&0<Object.keys(y.schema).length){if(0!==m(Object.keys(n),Object.keys(u).concat(Object.keys(y.schema))).length)throw new TypeError(y.msg+": "+y.optsVarName+".enforceStrictKeyset is on and the following keys are not covered by schema and/or reference objects: "+JSON.stringify(m(Object.keys(n),Object.keys(u).concat(Object.keys(y.schema))),null,4))}else{if(!(o(u)&&0<Object.keys(u).length))throw new TypeError(y.msg+": Both "+y.optsVarName+".schema and reference objects are missing! We don't have anything to match the keys as you requested via opts.enforceStrictKeyset!");if(0!==m(Object.keys(n),Object.keys(u)).length)throw new TypeError(y.msg+": The input object has keys that are not covered by reference object: "+JSON.stringify(m(Object.keys(n),Object.keys(u)),null,4));if(0!==m(Object.keys(u),Object.keys(n)).length)throw new TypeError(y.msg+": The reference object has keys that are not present in the input object: "+JSON.stringify(m(Object.keys(u),Object.keys(n)),null,4))}Object.keys(n).forEach(function(t){if(o(y.schema)&&Object.prototype.hasOwnProperty.call(y.schema,t)){if(y.schema[t]=ee(y.schema[t]).map(String).map(function(e){return e.toLowerCase()}),!(Z(y.schema[t],c).length||(!0===n[t]||!1===n[t]||y.schema[t].includes(p(n[t]).toLowerCase()))&&(!0!==n[t]&&!1!==n[t]||y.schema[t].includes(String(n[t]))||y.schema[t].includes("boolean")))){if(!s(n[t])||!y.acceptArrays)throw new TypeError(y.msg+": "+y.optsVarName+"."+t+" was customised to "+JSON.stringify(n[t],null,4)+" which is not among the allowed types in schema ("+y.schema[t]+") but "+p(n[t]));for(var e=0,r=n[t].length;e<r;e++)if(!y.schema[t].includes(p(n[t][e]).toLowerCase()))throw new TypeError(y.msg+": "+y.optsVarName+"."+t+" is of type "+p(n[t][e]).toLowerCase()+", but only the following are allowed in "+y.optsVarName+".schema: "+y.schema[t])}}else if(o(u)&&Object.prototype.hasOwnProperty.call(u,t)&&p(n[t])!==p(u[t])&&!y.ignoreKeys.includes(t)){if(!y.acceptArrays||!s(n[t])||y.acceptArraysIgnore.includes(t))throw new TypeError(y.msg+": "+y.optsVarName+"."+t+" was customised to "+JSON.stringify(n[t],null,4)+" which is not "+p(u[t])+" but "+p(n[t]));if(!n[t].every(function(e){return p(e)===p(u[t])}))throw new TypeError(y.msg+": "+y.optsVarName+"."+t+" was customised to be array, but not all of its elements are "+p(u[t])+"-type")}})}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.checkTypesMini=e()}(this,function(){"use strict";var St="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(t,e){return t(e={exports:{}},e.exports),e.exports}var _="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},d=t(function(t,e){var o,i,r,a,c,u,s,f,n,p,l,y,h,d,g,b,v,m;t.exports=(o="function"==typeof Promise,i="object"===("undefined"==typeof self?"undefined":_(self))?self:St,r="undefined"!=typeof Symbol,a="undefined"!=typeof Map,c="undefined"!=typeof Set,u="undefined"!=typeof WeakMap,s="undefined"!=typeof WeakSet,f="undefined"!=typeof DataView,n=r&&void 0!==Symbol.iterator,p=r&&void 0!==Symbol.toStringTag,l=c&&"function"==typeof Set.prototype.entries,y=a&&"function"==typeof Map.prototype.entries,h=l&&Object.getPrototypeOf((new Set).entries()),d=y&&Object.getPrototypeOf((new Map).entries()),g=n&&"function"==typeof Array.prototype[Symbol.iterator],b=g&&Object.getPrototypeOf([][Symbol.iterator]()),v=n&&"function"==typeof String.prototype[Symbol.iterator],m=v&&Object.getPrototypeOf(""[Symbol.iterator]()),function(t){var e=void 0===t?"undefined":_(t);if("object"!==e)return e;if(null===t)return"null";if(t===i)return"global";if(Array.isArray(t)&&(!1===p||!(Symbol.toStringTag in t)))return"Array";if("object"===("undefined"==typeof window?"undefined":_(window))&&null!==window){if("object"===_(window.location)&&t===window.location)return"Location";if("object"===_(window.document)&&t===window.document)return"Document";if("object"===_(window.navigator)){if("object"===_(window.navigator.mimeTypes)&&t===window.navigator.mimeTypes)return"MimeTypeArray";if("object"===_(window.navigator.plugins)&&t===window.navigator.plugins)return"PluginArray"}if(("function"==typeof window.HTMLElement||"object"===_(window.HTMLElement))&&t instanceof window.HTMLElement){if("BLOCKQUOTE"===t.tagName)return"HTMLQuoteElement";if("TD"===t.tagName)return"HTMLTableDataCellElement";if("TH"===t.tagName)return"HTMLTableHeaderCellElement"}}var r=p&&t[Symbol.toStringTag];if("string"==typeof r)return r;var n=Object.getPrototypeOf(t);return n===RegExp.prototype?"RegExp":n===Date.prototype?"Date":o&&n===Promise.prototype?"Promise":c&&n===Set.prototype?"Set":a&&n===Map.prototype?"Map":s&&n===WeakSet.prototype?"WeakSet":u&&n===WeakMap.prototype?"WeakMap":f&&n===DataView.prototype?"DataView":a&&n===d?"Map Iterator":c&&n===h?"Set Iterator":g&&n===b?"Array Iterator":v&&n===m?"String Iterator":null===n?"Object":Object.prototype.toString.call(t).slice(8,-1)})});function l(t,e,r){if(e!=e)return function(t,e,r,n){for(var o=t.length,i=r+(n?1:-1);n?i--:++i<o;)if(e(t[i],i,t))return i;return-1}(t,i,r);for(var n=r-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1}function y(t,e,r,n){for(var o=r-1,i=t.length;++o<i;)if(n(t[o],e))return o;return-1}function i(t){return t!=t}var h=Array.prototype.splice;function r(t,e,r,n){var o,i=n?y:l,a=-1,c=e.length,u=t;for(t===e&&(e=function(t,e){var r=-1,n=t.length;e||(e=Array(n));for(;++r<n;)e[r]=t[r];return e}(e)),r&&(u=function(t,e){for(var r=-1,n=t?t.length:0,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o}(t,(o=r,function(t){return o(t)})));++a<c;)for(var s=0,f=e[a],p=r?r(f):f;-1<(s=i(u,p,s,n));)u!==t&&h.call(u,s,1),h.call(t,s,1);return t}var c=function(t,e){return t&&t.length&&e&&e.length?r(t,e):t},At="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},g=t(function(t,e){var n="__lodash_hash_undefined__",r=9007199254740991,w="[object Arguments]",O="[object Function]",S="[object GeneratorFunction]",o="[object Map]",A="[object Object]",i="[object Promise]",a="[object Set]",c="[object WeakMap]",u="[object DataView]",s=/^\[object .+?Constructor\]$/,f=/^(?:0|[1-9]\d*)$/,p="object"==At(St)&&St&&St.Object===Object&&St,l="object"==("undefined"==typeof self?"undefined":At(self))&&self&&self.Object===Object&&self,y=p||l||Function("return this")(),h=e&&!e.nodeType&&e,d=h&&t&&!t.nodeType&&t,g=d&&d.exports===h;function k(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}function b(e,r){return function(t){return e(r(t))}}var v,m=Array.prototype,_=Function.prototype,j=Object.prototype,P=y["__core-js_shared__"],T=(v=/[^.]+$/.exec(P&&P.keys&&P.keys.IE_PROTO||""))?"Symbol(src)_1."+v:"",E=_.toString,N=j.hasOwnProperty,M=j.toString,x=RegExp("^"+E.call(N).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),L=g?y.Buffer:void 0,I=y.Symbol,C=(y.Uint8Array,b(Object.getPrototypeOf,Object)),K=Object.create,V=j.propertyIsEnumerable,$=m.splice,D=Object.getOwnPropertySymbols,F=L?L.isBuffer:void 0,W=b(Object.keys,Object),H=pt(y,"DataView"),R=pt(y,"Map"),B=pt(y,"Promise"),J=pt(y,"Set"),q=pt(y,"WeakMap"),G=pt(Object,"create"),Q=gt(H),U=gt(R),z=gt(B),X=gt(J),Y=gt(q),Z=I?I.prototype:void 0;Z&&Z.valueOf;function tt(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function et(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function rt(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function nt(t){this.__data__=new et(t)}function ot(t,e){var r,n,o,i=vt(t)||(o=n=r=t)&&"object"==(void 0===o?"undefined":At(o))&&mt(n)&&N.call(r,"callee")&&(!V.call(r,"callee")||M.call(r)==w)?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],a=i.length,c=!!a;for(var u in t)!e&&!N.call(t,u)||c&&("length"==u||ht(u,a))||i.push(u);return i}function it(t,e,r){var n=t[e];N.call(t,e)&&bt(n,r)&&(void 0!==r||e in t)||(t[e]=r)}function at(t,e){for(var r=t.length;r--;)if(bt(t[r][0],e))return r;return-1}function ct(r,n,o,i,t,e,a){var c;if(i&&(c=e?i(r,t,e,a):i(r)),void 0!==c)return c;if(!wt(r))return r;var u,s,f,p,l,y,h=vt(r);if(h){if(c=function(t){var e=t.length,r=t.constructor(e);e&&"string"==typeof t[0]&&N.call(t,"index")&&(r.index=t.index,r.input=t.input);return r}(r),!n)return function(t,e){var r=-1,n=t.length;e||(e=Array(n));for(;++r<n;)e[r]=t[r];return e}(r,c)}else{var d=yt(r),g=d==O||d==S;if(_t(r))return function(t,e){if(e)return t.slice();var r=new t.constructor(t.length);return t.copy(r),r}(r,n);if(d!=A&&d!=w&&(!g||e))return e?r:{};if(k(r))return e?r:{};if(c="function"!=typeof(l=g?{}:r).constructor||dt(l)?{}:wt(y=C(l))?K(y):{},!n)return p=u=r,s=(f=c)&&st(p,Ot(p),f),st(u,lt(u),s)}a||(a=new nt);var b,v,m,_=a.get(r);if(_)return _;if(a.set(r,c),!h)var j=o?(v=lt,m=Ot(b=r),vt(b)?m:function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}(m,v(b))):Ot(r);return function(t,e){for(var r=-1,n=t?t.length:0;++r<n&&!1!==e(t[r],r,t););}(j||r,function(t,e){j&&(t=r[e=t]),it(c,e,ct(t,n,o,i,e,r,a))}),c}function ut(t){return!(!wt(t)||(e=t,T&&T in e))&&(jt(t)||k(t)?x:s).test(gt(t));var e}function st(t,e,r,n){r||(r={});for(var o=-1,i=e.length;++o<i;){var a=e[o],c=n?n(r[a],t[a],a,r,t):void 0;it(r,a,void 0===c?t[a]:c)}return r}function ft(t,e){var r,n,o=t.__data__;return("string"==(n=void 0===(r=e)?"undefined":At(r))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function pt(t,e){var r,n,o=(n=e,null==(r=t)?void 0:r[n]);return ut(o)?o:void 0}tt.prototype.clear=function(){this.__data__=G?G(null):{}},tt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},tt.prototype.get=function(t){var e=this.__data__;if(G){var r=e[t];return r===n?void 0:r}return N.call(e,t)?e[t]:void 0},tt.prototype.has=function(t){var e=this.__data__;return G?void 0!==e[t]:N.call(e,t)},tt.prototype.set=function(t,e){return this.__data__[t]=G&&void 0===e?n:e,this},et.prototype.clear=function(){this.__data__=[]},et.prototype.delete=function(t){var e=this.__data__,r=at(e,t);return!(r<0||(r==e.length-1?e.pop():$.call(e,r,1),0))},et.prototype.get=function(t){var e=this.__data__,r=at(e,t);return r<0?void 0:e[r][1]},et.prototype.has=function(t){return-1<at(this.__data__,t)},et.prototype.set=function(t,e){var r=this.__data__,n=at(r,t);return n<0?r.push([t,e]):r[n][1]=e,this},rt.prototype.clear=function(){this.__data__={hash:new tt,map:new(R||et),string:new tt}},rt.prototype.delete=function(t){return ft(this,t).delete(t)},rt.prototype.get=function(t){return ft(this,t).get(t)},rt.prototype.has=function(t){return ft(this,t).has(t)},rt.prototype.set=function(t,e){return ft(this,t).set(t,e),this},nt.prototype.clear=function(){this.__data__=new et},nt.prototype.delete=function(t){return this.__data__.delete(t)},nt.prototype.get=function(t){return this.__data__.get(t)},nt.prototype.has=function(t){return this.__data__.has(t)},nt.prototype.set=function(t,e){var r=this.__data__;if(r instanceof et){var n=r.__data__;if(!R||n.length<199)return n.push([t,e]),this;r=this.__data__=new rt(n)}return r.set(t,e),this};var lt=D?b(D,Object):function(){return[]},yt=function(t){return M.call(t)};function ht(t,e){return!!(e=null==e?r:e)&&("number"==typeof t||f.test(t))&&-1<t&&t%1==0&&t<e}function dt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||j)}function gt(t){if(null!=t){try{return E.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function bt(t,e){return t===e||t!=t&&e!=e}(H&&yt(new H(new ArrayBuffer(1)))!=u||R&&yt(new R)!=o||B&&yt(B.resolve())!=i||J&&yt(new J)!=a||q&&yt(new q)!=c)&&(yt=function(t){var e=M.call(t),r=e==A?t.constructor:void 0,n=r?gt(r):void 0;if(n)switch(n){case Q:return u;case U:return o;case z:return i;case X:return a;case Y:return c}return e});var vt=Array.isArray;function mt(t){return null!=t&&("number"==typeof(e=t.length)&&-1<e&&e%1==0&&e<=r)&&!jt(t);var e}var _t=F||function(){return!1};function jt(t){var e=wt(t)?M.call(t):"";return e==O||e==S}function wt(t){var e=void 0===t?"undefined":At(t);return!!t&&("object"==e||"function"==e)}function Ot(t){return mt(t)?ot(t):function(t){if(!dt(t))return W(t);var e=[];for(var r in Object(t))N.call(t,r)&&"constructor"!=r&&e.push(r);return e}(t)}t.exports=function(t){return ct(t,!0,!0)}}),o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};var e,n,a=Function.prototype,u=Object.prototype,s=a.toString,f=u.hasOwnProperty,p=s.call(Object),b=u.toString,v=(e=Object.getPrototypeOf,n=Object,function(t){return e(n(t))});var m=function(t){if(!(e=t)||"object"!=(void 0===e?"undefined":o(e))||"[object Object]"!=b.call(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t))return!1;var e,r=v(t);if(null===r)return!0;var n=f.call(r,"constructor")&&r.constructor;return"function"==typeof n&&n instanceof n&&s.call(n)==p},j=Array.isArray;function w(t){return"string"==typeof t&&0<t.length&&"."===t[0]?t.slice(1):t}var O="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},S="__lodash_hash_undefined__",A=9007199254740991,k="[object Function]",P="[object GeneratorFunction]",T=/^\[object .+?Constructor\]$/,E="object"==O(St)&&St&&St.Object===Object&&St,N="object"==("undefined"==typeof self?"undefined":O(self))&&self&&self.Object===Object&&self,M=E||N||Function("return this")();function x(t,e){return!!(t?t.length:0)&&-1<function(t,e,r){if(e!=e)return function(t,e,r,n){var o=t.length,i=r+(n?1:-1);for(;n?i--:++i<o;)if(e(t[i],i,t))return i;return-1}(t,C,r);var n=r-1,o=t.length;for(;++n<o;)if(t[n]===e)return n;return-1}(t,e,0)}function L(t,e,r){for(var n=-1,o=t?t.length:0;++n<o;)if(r(e,t[n]))return!0;return!1}function I(t,e){for(var r=-1,n=t?t.length:0,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o}function C(t){return t!=t}function K(e){return function(t){return e(t)}}function V(t,e){return t.has(e)}var $,D,F,W=Array.prototype,H=Function.prototype,R=Object.prototype,B=M["__core-js_shared__"],J=($=/[^.]+$/.exec(B&&B.keys&&B.keys.IE_PROTO||""))?"Symbol(src)_1."+$:"",q=H.toString,G=R.hasOwnProperty,Q=R.toString,U=RegExp("^"+q.call(G).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),z=W.splice,X=Math.max,Y=Math.min,Z=st(M,"Map"),tt=st(Object,"create");function et(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function rt(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function nt(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function ot(t){var e=-1,r=t?t.length:0;for(this.__data__=new nt;++e<r;)this.add(t[e])}function it(t,e){for(var r,n,o=t.length;o--;)if((r=t[o][0])===(n=e)||r!=r&&n!=n)return o;return-1}function at(t){return!(!pt(t)||(e=t,J&&J in e))&&(ft(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?U:T).test(function(t){if(null!=t){try{return q.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t));var e}function ct(t){return(o=e=t)&&"object"==(void 0===o?"undefined":O(o))&&(null!=(r=e)&&("number"==typeof(n=r.length)&&-1<n&&n%1==0&&n<=A)&&!ft(r))?t:[];var e,r,n,o}function ut(t,e){var r,n,o=t.__data__;return("string"==(n=void 0===(r=e)?"undefined":O(r))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function st(t,e){var r,n,o=(n=e,null==(r=t)?void 0:r[n]);return at(o)?o:void 0}function ft(t){var e=pt(t)?Q.call(t):"";return e==k||e==P}function pt(t){var e=void 0===t?"undefined":O(t);return!!t&&("object"==e||"function"==e)}et.prototype.clear=function(){this.__data__=tt?tt(null):{}},et.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},et.prototype.get=function(t){var e=this.__data__;if(tt){var r=e[t];return r===S?void 0:r}return G.call(e,t)?e[t]:void 0},et.prototype.has=function(t){var e=this.__data__;return tt?void 0!==e[t]:G.call(e,t)},et.prototype.set=function(t,e){return this.__data__[t]=tt&&void 0===e?S:e,this},rt.prototype.clear=function(){this.__data__=[]},rt.prototype.delete=function(t){var e=this.__data__,r=it(e,t);return!(r<0||(r==e.length-1?e.pop():z.call(e,r,1),0))},rt.prototype.get=function(t){var e=this.__data__,r=it(e,t);return r<0?void 0:e[r][1]},rt.prototype.has=function(t){return-1<it(this.__data__,t)},rt.prototype.set=function(t,e){var r=this.__data__,n=it(r,t);return n<0?r.push([t,e]):r[n][1]=e,this},nt.prototype.clear=function(){this.__data__={hash:new et,map:new(Z||rt),string:new et}},nt.prototype.delete=function(t){return ut(this,t).delete(t)},nt.prototype.get=function(t){return ut(this,t).get(t)},nt.prototype.has=function(t){return ut(this,t).has(t)},nt.prototype.set=function(t,e){return ut(this,t).set(t,e),this},ot.prototype.add=ot.prototype.push=function(t){return this.__data__.set(t,S),this},ot.prototype.has=function(t){return this.__data__.has(t)};var lt=(D=function(t){var e=I(t,ct);return e.length&&e[0]===t[0]?function(t,e,r){for(var n=r?L:x,o=t[0].length,i=t.length,a=i,c=Array(i),u=1/0,s=[];a--;){var f=t[a];a&&e&&(f=I(f,K(e))),u=Y(f.length,u),c[a]=!r&&(e||120<=o&&120<=f.length)?new ot(a&&f):void 0}f=t[0];var p=-1,l=c[0];t:for(;++p<o&&s.length<u;){var y=f[p],h=e?e(y):y;if(y=r||0!==y?y:0,!(l?V(l,h):n(s,h,r))){for(a=i;--a;){var d=c[a];if(!(d?V(d,h):n(t[a],h,r)))continue t}l&&l.push(h),s.push(y)}}return s}(e):[]},F=X(void 0===F?D.length-1:F,0),function(){for(var t=arguments,e=-1,r=X(t.length-F,0),n=Array(r);++e<r;)n[e]=t[F+e];e=-1;for(var o=Array(F+1);++e<F;)o[e]=t[e];return o[F]=n,function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}(D,this,o)});function yt(t){return"string"==typeof t?0<t.length?[t]:[]:t}var ht="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},dt=t(function(t){t.exports=function(){var e=Object.prototype.toString;function i(t,e){return null!=t&&Object.prototype.hasOwnProperty.call(t,e)}function f(t){if(!t)return!0;if(l(t)&&0===t.length)return!0;if("string"!=typeof t){for(var e in t)if(i(t,e))return!1;return!0}return!1}function p(t){return e.call(t)}var l=Array.isArray||function(t){return"[object Array]"===e.call(t)};function y(t){var e=parseInt(t);return e.toString()===t?e:t}function t(o){o=o||{};var a=function r(n){return Object.keys(r).reduce(function(t,e){return"create"===e||"function"==typeof r[e]&&(t[e]=r[e].bind(r,n)),t},{})};function c(t,e){return o.includeInheritedProps||"number"==typeof e&&Array.isArray(t)||i(t,e)}function u(t,e){if(c(t,e))return t[e]}function s(t,e,r,n){if("number"==typeof e&&(e=[e]),!e||0===e.length)return t;if("string"==typeof e)return s(t,e.split(".").map(y),r,n);var o=e[0],i=u(t,o);return 1===e.length?(void 0!==i&&n||(t[o]=r),i):(void 0===i&&("number"==typeof e[1]?t[o]=[]:t[o]={}),s(t[o],e.slice(1),r,n))}return a.has=function(t,e){if("number"==typeof e?e=[e]:"string"==typeof e&&(e=e.split(".")),!e||0===e.length)return!!t;for(var r=0;r<e.length;r++){var n=y(e[r]);if(!("number"==typeof n&&l(t)&&n<t.length||(o.includeInheritedProps?n in Object(t):i(t,n))))return!1;t=t[n]}return!0},a.ensureExists=function(t,e,r){return s(t,e,r,!0)},a.set=function(t,e,r,n){return s(t,e,r,n)},a.insert=function(t,e,r,n){var o=a.get(t,e);n=~~n,l(o)||a.set(t,e,o=[]),o.splice(n,0,r)},a.empty=function(t,e){var r,n;if(!f(e)&&null!=t&&(r=a.get(t,e))){if("string"==typeof r)return a.set(t,e,"");if("boolean"==typeof(i=r)||"[object Boolean]"===p(i))return a.set(t,e,!1);if("number"==typeof r)return a.set(t,e,0);if(l(r))r.length=0;else{if("object"!==(void 0===(o=r)?"undefined":ht(o))||"[object Object]"!==p(o))return a.set(t,e,null);for(n in r)c(r,n)&&delete r[n]}var o,i}},a.push=function(t,e){var r=a.get(t,e);l(r)||a.set(t,e,r=[]),r.push.apply(r,Array.prototype.slice.call(arguments,2))},a.coalesce=function(t,e,r){for(var n,o=0,i=e.length;o<i;o++)if(void 0!==(n=a.get(t,e[o])))return n;return r},a.get=function(t,e,r){if("number"==typeof e&&(e=[e]),!e||0===e.length)return t;if(null==t)return r;if("string"==typeof e)return a.get(t,e.split("."),r);var n=y(e[0]),o=u(t,n);return void 0===o?r:1===e.length?o:a.get(t[n],e.slice(1),r)},a.del=function(t,e){if("number"==typeof e&&(e=[e]),null==t)return t;if(f(e))return t;if("string"==typeof e)return a.del(t,e.split("."));var r=y(e[0]);return c(t,r)?1!==e.length?a.del(t[r],e.slice(1)):(l(t)?t.splice(r,1):delete t[r],t):t},a}var r=t();return r.create=t,r.withInheritedProps=t({includeInheritedProps:!0}),r}()}),gt=function(t){var e=t%100;if(10<=e&&e<=20)return"th";var r=t%10;return 1===r?"st":2===r?"nd":3===r?"rd":"th"},bt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};function vt(t){if("number"!=typeof t)throw new TypeError("Expected Number, got "+(void 0===t?"undefined":bt(t))+" "+t);return t+gt(t)}vt.indicator=gt;var mt=vt;function _t(t,u,e){var r=!(3<arguments.length&&void 0!==arguments[3])||arguments[3];function s(t){return null!=t}function f(t){return"Object"===d(t)}function p(t){if(t.includes(".")){var e=t.split(".");return e.pop(),e.join(".")}return t}var l=["any","anything","every","everything","all","whatever","whatevs"],y=Array.isArray;if(!s(t))throw new Error("check-types-mini: [THROW_ID_01] First argument is missing!");var n={ignoreKeys:[],ignorePaths:[],acceptArrays:!1,acceptArraysIgnore:[],enforceStrictKeyset:!0,schema:{},msg:"check-types-mini",optsVarName:"opts"},h=void 0;if(s((h=s(e)&&f(e)?Object.assign({},n,e):Object.assign({},n)).ignoreKeys)&&h.ignoreKeys?h.ignoreKeys=yt(h.ignoreKeys):h.ignoreKeys=[],s(h.ignorePaths)&&h.ignorePaths?h.ignorePaths=yt(h.ignorePaths):h.ignorePaths=[],s(h.acceptArraysIgnore)&&h.acceptArraysIgnore?h.acceptArraysIgnore=yt(h.acceptArraysIgnore):h.acceptArraysIgnore=[],h.msg="string"==typeof h.msg?h.msg.trim():h.msg,":"===h.msg[h.msg.length-1]&&(h.msg=h.msg.slice(0,h.msg.length-1).trim()),h.schema&&Object.keys(h.schema).forEach(function(t){y(h.schema[t])||(h.schema[t]=[h.schema[t]]),h.schema[t]=h.schema[t].map(String).map(function(t){return t.toLowerCase()}).map(function(t){return t.trim()})}),s(u)||(u={}),r&&_t(h,n,{enforceStrictKeyset:!1},!1),h.enforceStrictKeyset)if(s(h.schema)&&0<Object.keys(h.schema).length){if(0!==c(Object.keys(t),Object.keys(u).concat(Object.keys(h.schema))).length){var o=c(Object.keys(t),Object.keys(u).concat(Object.keys(h.schema)));throw new TypeError(h.msg+": "+h.optsVarName+".enforceStrictKeyset is on and the following key"+(1<o.length?"s":"")+" "+(1<o.length?"are":"is")+" not covered by schema and/or reference objects: "+o.join(", "))}}else{if(!(s(u)&&0<Object.keys(u).length))throw new TypeError(h.msg+": Both "+h.optsVarName+".schema and reference objects are missing! We don't have anything to match the keys as you requested via opts.enforceStrictKeyset!");if(0!==c(Object.keys(t),Object.keys(u)).length){var i=c(Object.keys(t),Object.keys(u));throw new TypeError(h.msg+": The input object has key"+(1<i.length?"s":"")+" which "+(1<i.length?"are":"is")+" not covered by the reference object: "+i.join(", "))}if(0!==c(Object.keys(u),Object.keys(t)).length){var a=c(Object.keys(u),Object.keys(t));throw new TypeError(h.msg+": The reference object has key"+(1<a.length?"s":"")+" which "+(1<a.length?"are":"is")+" not present in the input object: "+a.join(", "))}}(function t(e,r,n){var o=g(e),i=void 0,a=void 0,c=void 0,u=void 0,s=void 0;if((n=Object.assign({depth:-1,path:""},n)).depth+=1,j(o))for(i=0,a=o.length;i<a;i++){var f=n.path+"."+i;void 0!==o[i]?(n.parent=g(o),c=t(r(o[i],void 0,Object.assign({},n,{path:w(f)})),r,Object.assign({},n,{path:w(f)})),Number.isNaN(c)&&i<o.length?(o.splice(i,1),i-=1):o[i]=c):o.splice(i,1)}else if(m(o))for(i=0,a=(u=Object.keys(o)).length;i<a;i++){s=u[i];var p=n.path+"."+s;0===n.depth&&null!=s&&(n.topmostKey=s),n.parent=g(o),c=t(r(s,o[s],Object.assign({},n,{path:w(p)})),r,Object.assign({},n,{path:w(p)})),Number.isNaN(c)?delete o[s]:o[s]=c}return o})(t,function(e,t,r){var n=void 0!==t?t:e;if(!(!h.enforceStrictKeyset||!f(n)&&!y(n)&&y(r.parent)||s(h.schema)&&f(h.schema)&&(!f(h.schema)||Object.keys(h.schema).length&&(y(r.parent)||Object.prototype.hasOwnProperty.call(h.schema,r.path))&&(!y(r.parent)||dt.has(h.schema,p(r.path))))||s(u)&&f(u)&&(!f(u)||Object.keys(u).length&&(h.acceptArrays||dt.has(u,r.path))&&(!h.acceptArrays||(y(r.parent)||dt.has(u,r.path))&&(!y(r.parent)||dt.has(u,p(r.path)))))))throw new TypeError(h.msg+": "+h.optsVarName+"."+r.path+" is neither covered by reference object (second input argument), nor "+h.optsVarName+".schema! To stop this error, turn off "+h.optsVarName+".enforceStrictKeyset or provide some type reference (2nd argument or "+h.optsVarName+".schema).");if(f(h.schema)&&Object.keys(h.schema).length&&Object.prototype.hasOwnProperty.call(h.schema,r.path)){var o=yt(h.schema[r.path]).map(String).map(function(t){return t.toLowerCase()});if(dt.set(h.schema,r.path,o),!(lt(o,l).length||(!0===n||!1===n||o.includes(d(n).toLowerCase()))&&(!0!==n&&!1!==n||o.includes(String(n))||o.includes("boolean")))){if(!y(n)||!h.acceptArrays)throw new TypeError(h.msg+": "+h.optsVarName+"."+r.path+" was customised to "+("string"!==d(n)?'"':"")+JSON.stringify(n,null,0)+("string"!==d(n)?'"':"")+" ("+d(n).toLowerCase()+") which is not among the allowed types in schema ("+o.join(", ")+")");for(var i=0,a=n.length;i<a;i++)if(!o.includes(d(n[i]).toLowerCase()))throw new TypeError(h.msg+": "+h.optsVarName+"."+r.path+"."+i+", the "+mt(i+1)+" element (equal to "+JSON.stringify(n[i],null,0)+") is of a type "+d(n[i]).toLowerCase()+", but only the following are allowed by the "+h.optsVarName+".schema: "+o.join(", "))}}else if(s(u)&&Object.keys(u).length&&dt.has(u,r.path)&&d(n)!==d(dt.get(u,r.path))&&(!h.ignoreKeys||!h.ignoreKeys.includes(e))&&(!h.ignorePaths||!h.ignorePaths.includes(r.path))){var c=dt.get(u,r.path);if(!h.acceptArrays||!y(n)||h.acceptArraysIgnore.includes(e))throw new TypeError(h.msg+": "+h.optsVarName+"."+r.path+" was customised to "+("string"===d(n).toLowerCase()?"":'"')+JSON.stringify(n,null,0)+("string"===d(n).toLowerCase()?"":'"')+" which is not "+d(c).toLowerCase()+" but "+d(n).toLowerCase());if(!n.every(function(t){return d(t).toLowerCase()===d(u[e]).toLowerCase()}))throw new TypeError(h.msg+": "+h.optsVarName+"."+r.path+" was customised to be array, but not all of its elements are "+d(u[e]).toLowerCase()+"-type")}return n},{})}return function(t,e,r){return _t(t,e,r)}}); |
{ | ||
"name": "check-types-mini", | ||
"version": "3.4.4", | ||
"version": "4.0.0", | ||
"description": "Check the types of your options object's values after user has customised them", | ||
@@ -159,4 +159,7 @@ "license": "MIT", | ||
"arrayiffy-if-string": "*", | ||
"ast-monkey-traverse": "^1.3.3", | ||
"lodash.intersection": "*", | ||
"lodash.pullall": "*", | ||
"object-path": "^0.11.4", | ||
"ordinal": "^1.0.2", | ||
"type-detect": "^4.0.8" | ||
@@ -182,3 +185,4 @@ }, | ||
"rollup": "latest", | ||
"rollup-plugin-babel": "^3.0.5", | ||
"rollup-plugin-babel": "^3.0.7", | ||
"rollup-plugin-cleanup": "^3.0.0-beta.1", | ||
"rollup-plugin-commonjs": "^9.1.3", | ||
@@ -185,0 +189,0 @@ "rollup-plugin-node-resolve": "^3.3.0", |
@@ -41,5 +41,5 @@ # check-types-mini | ||
| ------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------ | ----- | | ||
| Main export - **CommonJS version**, transpiled to ES5, contains `require` and `module.exports` | `main` | `dist/check-types-mini.cjs.js` | 7 KB | | ||
| **ES module** build that Webpack/Rollup understands. Untranspiled ES6 code with `import`/`export`. | `module` | `dist/check-types-mini.esm.js` | 8 KB | | ||
| **UMD build** for browsers, transpiled, minified, containing `iife`'s and has all dependencies baked-in | `browser` | `dist/check-types-mini.umd.js` | 13 KB | | ||
| Main export - **CommonJS version**, transpiled to ES5, contains `require` and `module.exports` | `main` | `dist/check-types-mini.cjs.js` | 8 KB | | ||
| **ES module** build that Webpack/Rollup understands. Untranspiled ES6 code with `import`/`export`. | `module` | `dist/check-types-mini.esm.js` | 9 KB | | ||
| **UMD build** for browsers, transpiled, minified, containing `iife`'s and has all dependencies baked-in | `browser` | `dist/check-types-mini.umd.js` | 24 KB | | ||
@@ -88,14 +88,30 @@ **[⬆ back to top](#markdown-header-check-types-mini)** | ||
| `options` object's key | Type | Obligatory? | Default | Description | | ||
| ---------------------- | -------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `options` object's key | Type | Obligatory? | Default | Description | | ||
| ---------------------- | -------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| { | | | | | ||
| `ignoreKeys` | Array or String | no | `[]` (empty array) | Instructs to skip all and any checks on keys, specified in this array. Put them as strings. | | ||
| `acceptArrays` | Boolean | no | `false` | If it's set to `true`, value can be array of elements, same type as reference. | | ||
| `acceptArraysIgnore` | Array of strings or String | no | `[]` (empty array) | If you want to ignore `acceptArrays` on certain keys, pass them in an array here. | | ||
| `enforceStrictKeyset` | Boolean | no | `true` | If it's set to `true`, your object must not have any unique keys that reference object (and/or `schema`) does not have. | | ||
| `schema` | Plain object | no | `{}` | You can set arrays of types for each key, overriding the reference object. This allows you more precision and enforcing multiple types. | | ||
| `ignoreKeys` | Array or String | no | `[]` (empty array) | Instructs to skip all and any checks on keys, specified in this array. Put them as strings. | | ||
| `ignorePaths` | Array or String | no | `[]` (empty array) | Instructs to skip all and any checks on keys which have given [object-path](https://github.com/mariocasciaro/object-path) notation-style path(s) within the `obj`. Similar thing to `opts.ignoreKeys` above, but unique (because simply key names can appear in multiple places whereas paths are unique). | | ||
| `acceptArrays` | Boolean | no | `false` | If it's set to `true`, value can be array of elements, same type as reference. | | ||
| `acceptArraysIgnore` | Array of strings or String | no | `[]` (empty array) | If you want to ignore `acceptArrays` on certain keys, pass them in an array here. | | ||
| `enforceStrictKeyset` | Boolean | no | `true` | If it's set to `true`, your object must not have any unique keys that reference object (and/or `schema`) does not have. | | ||
| `schema` | Plain object | no | `{}` | You can set arrays of types for each key, overriding the reference object. This allows you more precision and enforcing multiple types. | | ||
| `msg` | String | no | `` | A message to show. I like to include the name of the calling library, parent function and numeric throw ID. | | ||
| `optsVarName` | String | no | `opts` | How is your options variable called? It does not matter much, but it's nicer to keep references consistent with your API documentation. | | ||
| `optsVarName` | String | no | `opts` | How is your options variable called? It does not matter much, but it's nicer to keep references consistent with your API documentation. | | ||
| } | | | | | ||
Here are all defaults in one place: | ||
```js | ||
{ | ||
ignoreKeys: [], | ||
ignorePaths: [], | ||
acceptArrays: false, | ||
acceptArraysIgnore: [], | ||
enforceStrictKeyset: true, | ||
schema: {}, | ||
msg: "check-types-mini", | ||
optsVarName: "opts" | ||
} | ||
``` | ||
**[⬆ back to top](#markdown-header-check-types-mini)** | ||
@@ -102,0 +118,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
74439
532
309
7
23
1
+ Addedast-monkey-traverse@^1.3.3
+ Addedobject-path@^0.11.4
+ Addedordinal@^1.0.2
+ Added@babel/runtime@7.26.9(transitive)
+ Addedast-monkey-traverse@1.13.1(transitive)
+ Addedast-monkey-util@1.4.0(transitive)
+ Addedlodash.clonedeep@4.5.0(transitive)
+ Addedobject-path@0.11.8(transitive)
+ Addedordinal@1.0.3(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)