@muze-nl/assert 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +41 -121
- package/dist/assert.js +276 -44
- package/dist/assert.min.js +3 -1
- package/dist/assert.min.js.map +4 -4
- package/package.json +18 -5
- package/src/{assert.mjs~ → assert-core.mjs} +273 -32
- package/src/assert.mjs +3 -326
package/dist/assert.min.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/assert.mjs"],
|
|
4
|
-
"sourcesContent": ["/*\nTODO: add assertExplain global flag, so that if assert() fails, you can call explain() with\n the same pattern and it will return text explanation of why it failed, each assertion function must \n then check assertExplain, and return a text explanation of what fails or succeeds\n top level can then filter to show only the failures\n (so that not(x) can show the succeeds message of x)\n*/\n\n/**\n * assertEnabled (Boolean) used to toggle whether the assert()\n * method should test assertions or not.\n */\nglobalThis.assertEnabled = false\n\n/**\n * Enables assertion testing with assert()\n */\nexport function enable() {\n\tglobalThis.assertEnabled = true\n}\n\n/**\n * Disables assertion testing with assert()\n */\nexport function disable() {\n\tglobalThis.assertEnabled = false\n}\n\n/**\n * This function will check the source for the assertions in test, if\n * assertion checking is enabled globally.\n * If it is, and any assertion fails, it will throw an assertError\n * with a list of problems and other details.\n */\nexport function assert(source, test) {\n\tif (globalThis.assertEnabled) {\n\t\tlet problems = fails(source,test)\n\t\tif (problems) {\n\t\t\tconsole.error('\uD83C\uDD70\uFE0F Assertions failed because of:', problems, 'in this source:', source)\n\t\t\tthrow new Error('Assertions failed', {\n\t\t\t\tcause: { problems, source } \n\t\t\t})\n\t\t}\n\t}\n}\n\n/**\n * Tests a given value against a pattern, only if the value is not null or undefined\n */\nexport function Optional(pattern) {\n\treturn function _Optional(data, root, path) {\n\t\tif (typeof data != 'undefined' && data!=null && typeof pattern != 'undefined' ) {\n\t\t\treturn fails(data, pattern, root, path)\n\t\t}\n\t}\n}\n\n/**\n * Tests a given value against a pattern, always.\n */\nexport function Required(pattern) {\n\treturn function _Required(data, root, path) {\n\t\tif (data==null || typeof data == 'undefined') {\n\t\t\treturn error('data is required', data, pattern || 'any value', path)\n\t\t} else if (typeof pattern != 'undefined') {\n\t\t\treturn fails(data, pattern, root, path)\n\t\t} else {\n\t\t\treturn false\n\t\t}\n\t}\n}\n\n/**\n * Tests a given value against a pattern, only if the value is not null or undefined\n * If null or undefined, it does print a warning to the console.\n */\nexport function Recommended(pattern) {\n\treturn function _Recommended(data, root, path) {\n\t\tif (data==null || typeof data == 'undefined') {\n\t\t\twarn('data does not contain recommended value', data, pattern, path)\n\t\t\treturn false\n\t\t} else {\n\t\t\treturn fails(data, pattern, root, path)\n\t\t}\n\t}\n}\n\n/**\n * Tests a given value against a set of patterns, untill one succeeds\n * Returns an error if none succeed\n */\nexport function oneOf(...patterns) { \n\treturn function _oneOf(data, root, path) {\n\t\tfor(let pattern of patterns) {\n\t\t\tif (!fails(data, pattern, root, path)) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn error('data does not match oneOf patterns', data, patterns, path)\n\t}\n}\n\n/**\n * Tests a given array of values against a set of patterns\n * If any value does not match one of the patterns, it will return an error\n * If not given an array to test, it will return an error\n */\nexport function anyOf(...patterns) {\n\treturn function _anyOf(data, root, path) {\n\t\tif (!Array.isArray(data)) {\n\t\t\treturn error('data is not an array',data,'anyOf',path)\n\t\t}\n\t\tfor (let value of data) {\n\t\t\tif (oneOf(...patterns)(value)) {\n\t\t\t\treturn error('data does not match anyOf patterns',value,patterns,path)\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n}\n\nexport function allOf(...patterns) {\n\treturn function _allOf(data, root, path) {\n\t\tlet problems = []\n\t\tfor (let pattern of patterns) {\n\t\t\tproblems = problems.concat(fails(data, pattern, root, path))\n\t\t}\n\t\tproblems = problems.filter(Boolean)\n\t\tif (problems.length) {\n\t\t\treturn error('data does not match all given patterns', data, patterns, path, problems)\n\t\t}\n\t}\n}\n\n/**\n * Tests a given value to see if it is a valid (and absolute) URL, by\n * parsing it with the URL() constructor, and then testing the href\n * value to be equal to the initial value.\n */\nexport function validURL(data, root, path) {\n\ttry {\n\t\tif (data instanceof URL) {\n\t\t\tdata = data.href\n\t\t}\n\t\tlet url = new URL(data)\n\t\tif (url.href!=data) {\n\t\t\tif (!(url.href+'/'==data || url.href==data+'/')) {\n\t\t\t\t// new URL() always adds a / as path\n\t\t\t\treturn error('data is not a valid url',data,'validURL',path)\n\t\t\t}\n\t\t}\n\t} catch(e) {\n\t\treturn error('data is not a valid url',data,'validURL',path)\n\t}\n}\n\n/**\n * Tests a given value to see if it looks like a valid email address, by\n * testing it against a regular expression. So there are no guarantees that\n * it is an actual working email address, just that it looks like one.\n */\nexport function validEmail(data, root, path) {\n\tif (!/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(data)) {\n\t\treturn error('data is not a valid email',data,'validEmail',path)\n\t}\n}\n\n/**\n * Tests a given value to see if it is an object which is an instance of the given\n * constructor\n */\nexport function instanceOf(constructor) {\n\treturn function _instanceOf(data, root, path) {\n\t\tif (!(data instanceof constructor)) {\n\t\t\treturn error('data is not an instanceof pattern',data,constructor,path)\n\t\t}\n\t}\n}\n\n/**\n * Runs the given test pattern on a value, if the test succeeds, it fails\n * the not() test.\n */\nexport function not(pattern) {\n\treturn function _not(data, root, path) {\n\t\tif (!fails(data, pattern, root, path)) {\n\t\t\treturn error('data matches pattern, when required not to', data, pattern, path)\n\t\t}\n\t}\n}\n\n/**\n * returns an array of problems if the data fails to satisfy \n * the assertions in the given pattern, false otherwise\n * @param {any} data The data to match\n * @param {any} pattern The pattern to match\n * @param {any} root Root object for assertions, set to data by default\n * @return {Array|false} Array with problems if the pattern fails, false otherwise\n */\nexport function fails(data, pattern, root, path='') {\n\tif (!root) {\n\t\troot = data\n\t}\n\tlet problems = []\n\tif (pattern === Boolean) {\n\t\tif (typeof data != 'boolean' && !(data instanceof Boolean)) {\n\t\t\tproblems.push(error('data is not a boolean', data, pattern, path))\n\t\t}\t\t\n\t} else if (pattern === Number) {\n\t\tif (typeof data != 'number' && !(data instanceof Number)) {\n\t\t\tproblems.push(error('data is not a number', data, pattern, path))\n\t\t}\n\t} else if (pattern === String) {\n\t\tif (typeof data != 'string' && !(data instanceof String)) {\n\t\t\tproblems.push(error('data is not a string', data, pattern, path))\n\t\t}\n\t\tif (data == \"\") {\n\t\t\tproblems.push(error('data is an empty string, which is not allowed', data, pattern, path))\n\t\t}\n\t} else if (pattern instanceof RegExp) {\n \tif (Array.isArray(data)) {\n\t\t\tlet index = data.findIndex((element,index) => fails(element,pattern,root,path+'['+index+']'))\n if (index>-1) {\n \tproblems.push(error('data['+index+'] does not match pattern', data[index], pattern, path+'['+index+']'))\n }\n } else if (typeof data == 'undefined') {\n \tproblems.push(error('data is undefined, should match pattern', data, pattern, path))\n \t} else if (!pattern.test(data)) {\n \tproblems.push(error('data does not match pattern', data, pattern, path))\n }\n } else if (pattern instanceof Function) {\n let problem = pattern(data, root, path)\n if (problem) {\n \tif (Array.isArray(problem)) {\n \t\tproblems = problems.concat(problem)\n \t} else {\n\t \tproblems.push(problem)\n\t }\n }\n } else if (Array.isArray(pattern)) {\n\t\tif (!Array.isArray(data)) {\n\t\t\tproblems.push(error('data is not an array',data,[],path))\n\t\t}\n\t\tfor (let p of pattern) {\n\t\t\tfor (let index of data.keys()) {\n\t\t\t\tlet problem = fails(data[index], p, root, path+'['+index+']')\n\t\t\t\tif (Array.isArray(problem)) {\n\t\t\t\t\tproblems = problems.concat(problem)\n\t\t\t\t} else if (problem) {\n\t\t\t\t\tproblems.push(problem)\n\t\t\t\t}\n\t\t\t}\n \t}\n } else if (pattern && typeof pattern == 'object') {\n if (Array.isArray(data)) {\n let index = data.findIndex((element,index) => fails(element,pattern,root,path+'['+index+']'))\n if (index>-1) {\n \tproblems.push(error('data['+index+'] does not match pattern', data[index], pattern, path+'['+index+']'))\n }\n } else if (!data || typeof data != 'object') {\n \tproblems.push(error('data is not an object, pattern is', data, pattern, path))\n } else {\n \tif (data instanceof URLSearchParams) {\n \t\tdata = Object.fromEntries(data)\n \t}\n \tif (pattern instanceof Function) {\n \t\tlet result = fails(data, pattern, root, path)\n\t if (result) {\n\t \tproblems = problems.concat(result)\n\t }\n \t} else {\n\t\t for (const [patternKey, subpattern] of Object.entries(pattern)) {\n\t\t let result = fails(data[patternKey], subpattern, root, path+'.'+patternKey)\n\t\t if (result) {\n\t\t \tproblems = problems.concat(result)\n\t\t }\n\t\t }\n\t\t }\n\t }\n } else {\n \tif (pattern!=data) {\n \t\tproblems.push(error('data and pattern are not equal', data, pattern, path))\n \t}\n }\n if (problems.length) {\n \treturn problems\n }\n return false\n}\n\n/**\n * Returns an object with message, found and expected properties\n */ \nexport function error(message, found, expected, path, problems) {\n\tlet result = {\n\t\tpath,\n\t\tmessage,\n\t\tfound,\n\t\texpected\n\t}\n\tif (problems) {\n\t\tresult.problems = problems\n\t}\n\treturn result\n}\n\nexport function warn(message, data, pattern, path) {\n\tconsole.warn('\uD83C\uDD70\uFE0F Assert: '+path, message, pattern, data)\n}\n\nglobalThis.assert = {\n\twarn,\n\terror,\n\tassert,\n\tenable,\n\tdisable,\n\tRequired,\n\tRecommended,\n\tOptional,\n\toneOf,\n\tanyOf,\n\tallOf,\n\tvalidURL,\n\tvalidEmail,\n\tinstanceOf,\n\tnot,\n\tfails\n}"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../src/assert-core.mjs", "../src/assert.mjs"],
|
|
4
|
+
"sourcesContent": ["/*\nTODO: add assertExplain global flag, so that if assert() fails, you can call explain() with\n the same pattern and it will return text explanation of why it failed, each assertion function must \n then check assertExplain, and return a text explanation of what fails or succeeds\n top level can then filter to show only the failures\n (so that not(x) can show the succeeds message of x)\n*/\n\nlet assertEnabled = false\n\n/**\n * Enables assertion testing with assert()\n */\nexport function enable() {\n\tassertEnabled = true\n}\n\n/**\n * Disables assertion testing with assert()\n */\nexport function disable() {\n\tassertEnabled = false\n}\n\nfunction appendPath(path='', key) {\n\tif (typeof path == 'undefined' || path == null) {\n\t\tpath = ''\n\t}\n\tif (typeof key == 'number') {\n\t\treturn `${path}[${key}]`\n\t}\n\treturn `${path}.${key}`\n}\n\nfunction pathToArray(path='') {\n\tif (Array.isArray(path)) {\n\t\treturn path\n\t}\n\tif (!path) {\n\t\treturn []\n\t}\n\tlet result = []\n\tlet matcher = /(?:^|\\.)([^.\\[\\]]+)|\\[(\\d+)\\]/g\n\tlet match\n\twhile ((match = matcher.exec(path))) {\n\t\tif (typeof match[1] != 'undefined') {\n\t\t\tresult.push(match[1])\n\t\t} else if (typeof match[2] != 'undefined') {\n\t\t\tresult.push(Number(match[2]))\n\t\t}\n\t}\n\treturn result\n}\n\nfunction pathToString(path=[]) {\n\tif (typeof path == 'string') {\n\t\treturn path.startsWith('.') ? path.slice(1) : path\n\t}\n\treturn path.map((part, index) => {\n\t\tif (typeof part == 'number') {\n\t\t\treturn `[${part}]`\n\t\t}\n\t\treturn `${index ? '.' : ''}${part}`\n\t}).join('')\n}\n\n\nfunction describeFunction(value) {\n\tif (value === String) {\n\t\treturn 'string'\n\t}\n\tif (value === Number) {\n\t\treturn 'number'\n\t}\n\tif (value === Boolean) {\n\t\treturn 'boolean'\n\t}\n\treturn value.name || 'function'\n}\n\nfunction clip(text, maxLength=60) {\n\tif (text.length <= maxLength) {\n\t\treturn text\n\t}\n\treturn text.slice(0, maxLength - 1)+'\u2026'\n}\n\nfunction quoteString(value) {\n\treturn `'${clip(String(value).replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\").replace(/\\n/g, '\\\\n'))}'`\n}\n\nfunction jsonSummary(value) {\n\ttry {\n\t\tlet json = JSON.stringify(value)\n\t\tif (typeof json == 'string') {\n\t\t\treturn clip(json)\n\t\t}\n\t} catch(e) {\n\t\t// fall through to the generic object description below\n\t}\n\tlet name = value?.constructor?.name\n\tif (name && name != 'Object') {\n\t\treturn name\n\t}\n\treturn Object.prototype.toString.call(value)\n}\n\nfunction formatValue(value) {\n\tif (typeof value == 'string') {\n\t\treturn quoteString(value)\n\t}\n\tif (typeof value == 'undefined') {\n\t\treturn 'undefined'\n\t}\n\tif (value === null) {\n\t\treturn 'null'\n\t}\n\tif (typeof value == 'function') {\n\t\treturn describeFunction(value)\n\t}\n\tif (value instanceof RegExp) {\n\t\treturn value.toString()\n\t}\n\tif (typeof value == 'number' || typeof value == 'boolean' || typeof value == 'bigint') {\n\t\treturn String(value)\n\t}\n\tif (typeof value == 'symbol') {\n\t\treturn value.toString()\n\t}\n\treturn jsonSummary(value)\n}\n\nfunction describeExpected(value) {\n\tif (value === String || value === Number || value === Boolean) {\n\t\treturn describeFunction(value)\n\t}\n\tif (typeof value == 'function') {\n\t\treturn describeFunction(value)\n\t}\n\tif (value instanceof RegExp) {\n\t\treturn value.toString()\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn '['+value.map(describeExpected).join(', ')+']'\n\t}\n\treturn formatValue(value)\n}\n\nfunction describeOneOf(patterns) {\n\treturn patterns.map(describeExpected).join(', ')\n}\n\nfunction conciseMessage(message, actual, expected) {\n\tif (message == 'data and pattern are not equal') {\n\t\treturn `expected ${formatValue(expected)}, found ${formatValue(actual)}`\n\t}\n\tif (message == 'data does not match pattern' || /^data\\[\\d+\\] does not match pattern$/.test(message)) {\n\t\treturn `expected ${describeExpected(expected)}, found ${formatValue(actual)}`\n\t}\n\tif (message == 'data is undefined, should match pattern') {\n\t\treturn `missing; expected ${describeExpected(expected)}`\n\t}\n\tif (message == 'data is required') {\n\t\treturn 'required'\n\t}\n\tif (message == 'data is an empty string, which is not allowed') {\n\t\treturn 'empty string is not allowed'\n\t}\n\tif (message == 'data is not an object, pattern is') {\n\t\treturn 'data is not an object'\n\t}\n\tif (message == 'data is not an instanceof pattern') {\n\t\treturn `expected instance of ${describeExpected(expected)}, found ${formatValue(actual)}`\n\t}\n\tif (message == 'data does not match oneOf patterns' || message == 'data does not match anyOf patterns') {\n\t\treturn `expected one of ${describeOneOf(expected)}, found ${formatValue(actual)}`\n\t}\n\tif (message == 'data matches pattern, when required not to') {\n\t\treturn `must not match ${describeExpected(expected)}`\n\t}\n\treturn message\n}\n\nexport function formatIssue(issue, options={}) {\n\tif (!issue || typeof issue != 'object') {\n\t\treturn String(issue)\n\t}\n\tlet path = issue.pathString || pathToString(issue.path || []) || 'value'\n\tlet indent = options.indent ?? ''\n\treturn `${indent}${path}: ${issue.message}`\n}\n\nexport function formatIssues(issues, options={}) {\n\tif (!issues) {\n\t\treturn false\n\t}\n\tlet indent = options.indent ?? ' - '\n\treturn (Array.isArray(issues) ? issues : [issues]).map(issue => formatIssue(issue, { ...options, indent }))\n}\n\nfunction issueFromProblem(problem) {\n\tif (!problem || typeof problem != 'object') {\n\t\treturn {\n\t\t\tpath: [],\n\t\t\tpathString: '',\n\t\t\tmessage: String(problem),\n\t\t\texpected: undefined,\n\t\t\tactual: undefined\n\t\t}\n\t}\n\tlet path = pathToArray(problem.path)\n\tlet pathString = pathToString(path)\n\tlet actual = problem.actual ?? problem.found\n\tlet expected = describeExpected(problem.expected)\n\tlet message = conciseMessage(problem.message, actual, problem.expected)\n\treturn {\n\t\tpath,\n\t\tpathString,\n\t\tmessage,\n\t\texpected,\n\t\tactual\n\t}\n}\n\nfunction problemsToIssues(problems) {\n\tif (!problems) {\n\t\treturn []\n\t}\n\tlet result = []\n\tfor (let problem of Array.isArray(problems) ? problems : [problems]) {\n\t\tif (!problem) {\n\t\t\tcontinue\n\t\t}\n\t\tif (problem && typeof problem == 'object' && problem.problems) {\n\t\t\tlet nested = problemsToIssues(problem.problems)\n\t\t\tif (nested.length) {\n\t\t\t\tresult = result.concat(nested)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\t\tresult.push(issueFromProblem(problem))\n\t}\n\treturn result\n}\n\n/**\n * This function will check the source for the assertions in test, if\n * assertion checking is enabled.\n * If it is, and any assertion fails, it will throw an assertError\n * with a list of problems and other details.\n */\nexport function assert(source, test) {\n\tif (assertEnabled) {\n\t\tlet problems = fails(source,test)\n\t\tif (problems) {\n\t\t\tlet assertionIssues = problemsToIssues(problems)\n\t\t\tlet formattedIssues = formatIssues(assertionIssues)\n\t\t\tlet message = 'Assertions failed:\\n'+formattedIssues.join('\\n')\n\t\t\tconsole.error('\uD83C\uDD70\uFE0F '+message)\n\t\t\tthrow new Error(message, {\n\t\t\t\tcause: { problems, issues: assertionIssues, source } \n\t\t\t})\n\t\t}\n\t}\n}\n\n/**\n * Tests a given value against a pattern, only if the value is not null or undefined\n */\nexport function Optional(pattern) {\n\treturn function _Optional(data, root, path) {\n\t\tif (typeof data != 'undefined' && data!=null && typeof pattern != 'undefined' ) {\n\t\t\treturn fails(data, pattern, root, path)\n\t\t}\n\t}\n}\n\n/**\n * Tests a given value against a pattern, always.\n */\nexport function Required(pattern) {\n\treturn function _Required(data, root, path) {\n\t\tif (data==null || typeof data == 'undefined') {\n\t\t\treturn error('data is required', data, pattern || 'any value', path)\n\t\t} else if (typeof pattern != 'undefined') {\n\t\t\treturn fails(data, pattern, root, path)\n\t\t} else {\n\t\t\treturn false\n\t\t}\n\t}\n}\n\n/**\n * Tests a given value against a pattern, only if the value is not null or undefined\n * If null or undefined, it does print a warning to the console.\n */\nexport function Recommended(pattern) {\n\treturn function _Recommended(data, root, path) {\n\t\tif (data==null || typeof data == 'undefined') {\n\t\t\twarn('data does not contain recommended value', data, pattern, path)\n\t\t\treturn false\n\t\t} else {\n\t\t\treturn fails(data, pattern, root, path)\n\t\t}\n\t}\n}\n\n/**\n * Tests a given value against a set of patterns, untill one succeeds\n * Returns an error if none succeed\n */\nexport function oneOf(...patterns) { \n\treturn function _oneOf(data, root, path) {\n\t\tfor(let pattern of patterns) {\n\t\t\tif (!fails(data, pattern, root, path)) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn error('data does not match oneOf patterns', data, patterns, path)\n\t}\n}\n\n/**\n * Tests a given array of values against a set of patterns\n * If any value does not match one of the patterns, it will return an error\n * If not given an array to test, it will return an error\n */\nexport function anyOf(...patterns) {\n\treturn function _anyOf(data, root, path) {\n\t\tif (!Array.isArray(data)) {\n\t\t\treturn error('data is not an array',data,'anyOf',path)\n\t\t}\n\t\tfor (let [index, value] of data.entries()) {\n\t\t\tlet itemPath = appendPath(path, index)\n\t\t\tif (oneOf(...patterns)(value, root, itemPath)) {\n\t\t\t\treturn error('data does not match anyOf patterns',value,patterns,itemPath)\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n}\n\nexport function allOf(...patterns) {\n\treturn function _allOf(data, root, path) {\n\t\tlet problems = []\n\t\tfor (let pattern of patterns) {\n\t\t\tproblems = problems.concat(fails(data, pattern, root, path))\n\t\t}\n\t\tproblems = problems.filter(Boolean)\n\t\tif (problems.length) {\n\t\t\treturn error('data does not match all given patterns', data, patterns, path, problems)\n\t\t}\n\t}\n}\n\n/**\n * Tests a given value to see if it is a valid (and absolute) URL, by\n * parsing it with the URL() constructor, and then testing the href\n * value to be equal to the initial value.\n */\nexport function validURL(data, root, path) {\n\ttry {\n\t\tif (data instanceof URL) {\n\t\t\tdata = data.href\n\t\t}\n\t\tlet url = new URL(data)\n\t\tif (url.href!=data) {\n\t\t\tif (!(url.href+'/'==data || url.href==data+'/')) {\n\t\t\t\t// new URL() always adds a / as path\n\t\t\t\treturn error('data is not a valid url',data,'validURL',path)\n\t\t\t}\n\t\t}\n\t} catch(e) {\n\t\treturn error('data is not a valid url',data,'validURL',path)\n\t}\n}\n\n/**\n * Tests a given value to see if it looks like a valid email address, by\n * testing it against a regular expression. So there are no guarantees that\n * it is an actual working email address, just that it looks like one.\n */\nexport function validEmail(data, root, path) {\n\tif (!/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(data)) {\n\t\treturn error('data is not a valid email',data,'validEmail',path)\n\t}\n}\n\n/**\n * Tests a given value to see if it is an object which is an instance of the given\n * constructor\n */\nexport function instanceOf(constructor) {\n\treturn function _instanceOf(data, root, path) {\n\t\tif (!(data instanceof constructor)) {\n\t\t\treturn error('data is not an instanceof pattern',data,constructor,path)\n\t\t}\n\t}\n}\n\n/**\n * Runs the given test pattern on a value, if the test succeeds, it fails\n * the not() test.\n */\nexport function not(pattern) {\n\treturn function _not(data, root, path) {\n\t\tif (!fails(data, pattern, root, path)) {\n\t\t\treturn error('data matches pattern, when required not to', data, pattern, path)\n\t\t}\n\t}\n}\n\n/**\n * Returns structured, path-aware issues if the data fails to satisfy\n * the assertions in the given pattern, or false otherwise.\n * @param {any} data The data to match\n * @param {any} pattern The pattern to match\n * @param {any} root Root object for assertions, set to data by default\n * @return {Array|false} Array with structured issues if the pattern fails, false otherwise\n */\nexport function issues(data, pattern, root) {\n\tlet problems = fails(data, pattern, root)\n\tif (!problems) {\n\t\treturn false\n\t}\n\treturn problemsToIssues(problems)\n}\n\n/**\n * returns an array of problems if the data fails to satisfy \n * the assertions in the given pattern, false otherwise\n * @param {any} data The data to match\n * @param {any} pattern The pattern to match\n * @param {any} root Root object for assertions, set to data by default\n * @return {Array|false} Array with problems if the pattern fails, false otherwise\n */\nexport function fails(data, pattern, root, path='') {\n\tif (typeof root == 'undefined') {\n\t\troot = data\n\t}\n\tlet problems = []\n\tif (pattern === Boolean) {\n\t\tif (typeof data != 'boolean' && !(data instanceof Boolean)) {\n\t\t\tproblems.push(error('data is not a boolean', data, pattern, path))\n\t\t}\t\t\n\t} else if (pattern === Number) {\n\t\tif (typeof data != 'number' && !(data instanceof Number)) {\n\t\t\tproblems.push(error('data is not a number', data, pattern, path))\n\t\t}\n\t} else if (pattern === String) {\n\t\tif (typeof data != 'string' && !(data instanceof String)) {\n\t\t\tproblems.push(error('data is not a string', data, pattern, path))\n\t\t}\n\t\tif (data == \"\") {\n\t\t\tproblems.push(error('data is an empty string, which is not allowed', data, pattern, path))\n\t\t}\n\t} else if (pattern instanceof RegExp) {\n \tif (Array.isArray(data)) {\n\t\t\tlet index = data.findIndex((element,index) => fails(element,pattern,root,appendPath(path, index)))\n if (index>-1) {\n \tproblems.push(error('data['+index+'] does not match pattern', data[index], pattern, appendPath(path, index)))\n }\n } else if (typeof data == 'undefined') {\n \tproblems.push(error('data is undefined, should match pattern', data, pattern, path))\n \t} else if (!pattern.test(data)) {\n \tproblems.push(error('data does not match pattern', data, pattern, path))\n }\n } else if (pattern instanceof Function) {\n let problem = pattern(data, root, path)\n if (problem) {\n \tif (Array.isArray(problem)) {\n \t\tproblems = problems.concat(problem)\n \t} else {\n\t \tproblems.push(problem)\n\t }\n }\n } else if (Array.isArray(pattern)) {\n\t\tif (!Array.isArray(data)) {\n\t\t\tproblems.push(error('data is not an array',data,[],path))\n\t\t} else {\n\t\t\tfor (let p of pattern) {\n\t\t\t\tfor (let index of data.keys()) {\n\t\t\t\t\tlet problem = fails(data[index], p, root, appendPath(path, index))\n\t\t\t\t\tif (Array.isArray(problem)) {\n\t\t\t\t\t\tproblems = problems.concat(problem)\n\t\t\t\t\t} else if (problem) {\n\t\t\t\t\t\tproblems.push(problem)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n } else if (pattern && typeof pattern == 'object') {\n if (Array.isArray(data)) {\n let index = data.findIndex((element,index) => fails(element,pattern,root,appendPath(path, index)))\n if (index>-1) {\n \tproblems.push(error('data['+index+'] does not match pattern', data[index], pattern, appendPath(path, index)))\n }\n } else if (!data || typeof data != 'object') {\n \tproblems.push(error('data is not an object, pattern is', data, pattern, path))\n } else {\n \tif (data instanceof URLSearchParams) {\n \t\tdata = Object.fromEntries(data)\n \t}\n \tif (pattern instanceof Function) {\n \t\tlet result = fails(data, pattern, root, path)\n\t if (result) {\n\t \tproblems = problems.concat(result)\n\t }\n \t} else {\n\t\t for (const [patternKey, subpattern] of Object.entries(pattern)) {\n\t\t let result = fails(data[patternKey], subpattern, root, appendPath(path, patternKey))\n\t\t if (result) {\n\t\t \tproblems = problems.concat(result)\n\t\t }\n\t\t }\n\t\t }\n\t }\n } else {\n \tif (pattern!=data) {\n \t\tproblems.push(error('data and pattern are not equal', data, pattern, path))\n \t}\n }\n if (problems.length) {\n \treturn problems\n }\n return false\n}\n\n/**\n * Returns an object with message, found and expected properties\n */ \nexport function error(message, found, expected, path='', problems) {\n\tlet pathParts = pathToArray(path)\n\tlet result = {\n\t\tpath,\n\t\tpathString: pathToString(pathParts),\n\t\tpathParts,\n\t\tmessage,\n\t\tfound,\n\t\texpected\n\t}\n\tif (problems) {\n\t\tresult.problems = problems\n\t}\n\treturn result\n}\n\nexport function warn(message, data, pattern, path) {\n\tconsole.warn('\uD83C\uDD70\uFE0F Assert: '+path, message, pattern, data)\n}\n", "import * as assertApi from './assert-core.mjs'\n\nexport * from './assert-core.mjs'\n\nglobalThis.assert = { ...assertApi }\n"],
|
|
5
|
+
"mappings": "gGAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,EAAA,gBAAAC,EAAA,aAAAC,EAAA,UAAAC,EAAA,UAAAC,EAAA,WAAAC,EAAA,YAAAC,EAAA,WAAAC,EAAA,UAAAC,EAAA,UAAAC,EAAA,gBAAAC,EAAA,iBAAAC,EAAA,eAAAC,EAAA,WAAAC,EAAA,QAAAC,EAAA,UAAAC,EAAA,eAAAC,EAAA,aAAAC,EAAA,SAAAC,IAQA,IAAIC,EAAgB,GAKb,SAASZ,GAAS,CACxBY,EAAgB,EACjB,CAKO,SAASb,GAAU,CACzBa,EAAgB,EACjB,CAEA,SAASC,EAAWC,EAAK,GAAIC,EAAK,CAIjC,OAHI,OAAOD,EAAQ,KAAeA,GAAQ,QACzCA,EAAO,IAEJ,OAAOC,GAAO,SACV,GAAGD,CAAI,IAAIC,CAAG,IAEf,GAAGD,CAAI,IAAIC,CAAG,EACtB,CAEA,SAASC,EAAYF,EAAK,GAAI,CAC7B,GAAI,MAAM,QAAQA,CAAI,EACrB,OAAOA,EAER,GAAI,CAACA,EACJ,MAAO,CAAC,EAET,IAAIG,EAAS,CAAC,EACVC,EAAU,i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EAAG8B,EAASvC,EAAWC,EAAMQ,CAAK,CAAC,CAAC,CAEjH,SAAW,CAAC+B,GAAQ,OAAOA,GAAQ,SAClCN,EAAS,KAAK9C,EAAM,oCAAqCoD,EAAMD,EAAStC,CAAI,CAAC,UAEzEuC,aAAgB,kBACnBA,EAAO,OAAO,YAAYA,CAAI,GAE3BD,aAAmB,SAAU,CAChC,IAAInC,EAASf,EAAMmD,EAAMD,EAASE,EAAMxC,CAAI,EACrCG,IACH8B,EAAWA,EAAS,OAAO9B,CAAM,EAEtC,KACC,QAAW,CAAC2C,EAAYC,CAAU,IAAK,OAAO,QAAQT,CAAO,EAAG,CAC5D,IAAInC,EAASf,EAAMmD,EAAKO,CAAU,EAAGC,EAAYP,EAAMzC,EAAWC,EAAM8C,CAAU,CAAC,EAC/E3C,IACH8B,EAAWA,EAAS,OAAO9B,CAAM,EAEtC,MAIDmC,GAASC,GACZN,EAAS,KAAK9C,EAAM,iCAAkCoD,EAAMD,EAAStC,CAAI,CAAC,EAG5E,OAAIiC,EAAS,OACLA,EAED,EACX,CAKO,SAAS9C,EAAMoC,EAASyB,EAAOvB,EAAUzB,EAAK,GAAIiC,EAAU,CAClE,IAAIgB,EAAY/C,EAAYF,CAAI,EAC5BG,EAAS,CACZ,KAAAH,EACA,WAAYM,EAAa2C,CAAS,EAClC,UAAAA,EACA,QAAA1B,EACA,MAAAyB,EACA,SAAAvB,CACD,EACA,OAAIQ,IACH9B,EAAO,SAAW8B,GAEZ9B,CACR,CAEO,SAASN,EAAK0B,EAASgB,EAAMD,EAAStC,EAAM,CAClD,QAAQ,KAAK,4BAAgBA,EAAMuB,EAASe,EAASC,CAAI,CAC1D,CCjiBA,WAAW,OAAS,CAAE,GAAGW,CAAU",
|
|
6
|
+
"names": ["assert_core_exports", "__export", "Optional", "Recommended", "Required", "allOf", "anyOf", "assert", "disable", "enable", "error", "fails", "formatIssue", "formatIssues", "instanceOf", "issues", "not", "oneOf", "validEmail", "validURL", "warn", "assertEnabled", "appendPath", "path", "key", "pathToArray", "result", "matcher", "match", "pathToString", "part", "index", "describeFunction", "value", "clip", "text", "maxLength", "quoteString", "jsonSummary", "json", "name", "formatValue", "describeExpected", "describeOneOf", "patterns", "conciseMessage", "message", "actual", "expected", "issue", "options", "indent", "issueFromProblem", "problem", "pathString", "problemsToIssues", "problems", "nested", "source", "test", "assertionIssues", "pattern", "data", "root", "itemPath", "url", "constructor", "element", "p", "patternKey", "subpattern", "found", "pathParts", "assert_core_exports"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muze-nl/assert",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "light optional assert library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/assert.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./src/assert.mjs",
|
|
10
|
+
"default": "./src/assert.mjs"
|
|
11
|
+
},
|
|
12
|
+
"./core": {
|
|
13
|
+
"import": "./src/assert-core.mjs",
|
|
14
|
+
"default": "./src/assert-core.mjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": [
|
|
18
|
+
"./src/assert.mjs"
|
|
19
|
+
],
|
|
7
20
|
"scripts": {
|
|
8
|
-
"test": "tap test/*.mjs",
|
|
21
|
+
"test": "tap --coverage-report=text --show-full-coverage --allow-incomplete-coverage test/*.mjs",
|
|
9
22
|
"tap": "tap",
|
|
10
23
|
"build": "npx esbuild --bundle src/assert.mjs --outfile=dist/assert.min.js --minify --sourcemap",
|
|
11
24
|
"build-dev": "npx esbuild --bundle src/assert.mjs --outfile=dist/assert.js"
|
|
@@ -21,7 +34,7 @@
|
|
|
21
34
|
},
|
|
22
35
|
"homepage": "https://github.com/muze-nl/assert/#readme",
|
|
23
36
|
"devDependencies": {
|
|
24
|
-
"tap": "^
|
|
37
|
+
"tap": "^21.7.4"
|
|
25
38
|
},
|
|
26
39
|
"engines": {
|
|
27
40
|
"node": ">=20.0.0"
|
|
@@ -32,7 +45,7 @@
|
|
|
32
45
|
"/LICENSE",
|
|
33
46
|
"/README.md"
|
|
34
47
|
],
|
|
35
|
-
"source": [ "src/
|
|
48
|
+
"source": [ "src/assert.mjs" ],
|
|
36
49
|
"targets": {
|
|
37
50
|
"default": {
|
|
38
51
|
"distDir": "./dist",
|
|
@@ -40,4 +53,4 @@
|
|
|
40
53
|
},
|
|
41
54
|
"main": false
|
|
42
55
|
}
|
|
43
|
-
}
|
|
56
|
+
}
|
|
@@ -6,39 +6,259 @@ TODO: add assertExplain global flag, so that if assert() fails, you can call exp
|
|
|
6
6
|
(so that not(x) can show the succeeds message of x)
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
* assertEnabled (Boolean) used to toggle whether the assert()
|
|
11
|
-
* method should test assertions or not.
|
|
12
|
-
*/
|
|
13
|
-
globalThis.assertEnabled = false
|
|
9
|
+
let assertEnabled = false
|
|
14
10
|
|
|
15
11
|
/**
|
|
16
12
|
* Enables assertion testing with assert()
|
|
17
13
|
*/
|
|
18
14
|
export function enable() {
|
|
19
|
-
|
|
15
|
+
assertEnabled = true
|
|
20
16
|
}
|
|
21
17
|
|
|
22
18
|
/**
|
|
23
19
|
* Disables assertion testing with assert()
|
|
24
20
|
*/
|
|
25
21
|
export function disable() {
|
|
26
|
-
|
|
22
|
+
assertEnabled = false
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function appendPath(path='', key) {
|
|
26
|
+
if (typeof path == 'undefined' || path == null) {
|
|
27
|
+
path = ''
|
|
28
|
+
}
|
|
29
|
+
if (typeof key == 'number') {
|
|
30
|
+
return `${path}[${key}]`
|
|
31
|
+
}
|
|
32
|
+
return `${path}.${key}`
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function pathToArray(path='') {
|
|
36
|
+
if (Array.isArray(path)) {
|
|
37
|
+
return path
|
|
38
|
+
}
|
|
39
|
+
if (!path) {
|
|
40
|
+
return []
|
|
41
|
+
}
|
|
42
|
+
let result = []
|
|
43
|
+
let matcher = /(?:^|\.)([^.\[\]]+)|\[(\d+)\]/g
|
|
44
|
+
let match
|
|
45
|
+
while ((match = matcher.exec(path))) {
|
|
46
|
+
if (typeof match[1] != 'undefined') {
|
|
47
|
+
result.push(match[1])
|
|
48
|
+
} else if (typeof match[2] != 'undefined') {
|
|
49
|
+
result.push(Number(match[2]))
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function pathToString(path=[]) {
|
|
56
|
+
if (typeof path == 'string') {
|
|
57
|
+
return path.startsWith('.') ? path.slice(1) : path
|
|
58
|
+
}
|
|
59
|
+
return path.map((part, index) => {
|
|
60
|
+
if (typeof part == 'number') {
|
|
61
|
+
return `[${part}]`
|
|
62
|
+
}
|
|
63
|
+
return `${index ? '.' : ''}${part}`
|
|
64
|
+
}).join('')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
function describeFunction(value) {
|
|
69
|
+
if (value === String) {
|
|
70
|
+
return 'string'
|
|
71
|
+
}
|
|
72
|
+
if (value === Number) {
|
|
73
|
+
return 'number'
|
|
74
|
+
}
|
|
75
|
+
if (value === Boolean) {
|
|
76
|
+
return 'boolean'
|
|
77
|
+
}
|
|
78
|
+
return value.name || 'function'
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function clip(text, maxLength=60) {
|
|
82
|
+
if (text.length <= maxLength) {
|
|
83
|
+
return text
|
|
84
|
+
}
|
|
85
|
+
return text.slice(0, maxLength - 1)+'…'
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function quoteString(value) {
|
|
89
|
+
return `'${clip(String(value).replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\n/g, '\\n'))}'`
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function jsonSummary(value) {
|
|
93
|
+
try {
|
|
94
|
+
let json = JSON.stringify(value)
|
|
95
|
+
if (typeof json == 'string') {
|
|
96
|
+
return clip(json)
|
|
97
|
+
}
|
|
98
|
+
} catch(e) {
|
|
99
|
+
// fall through to the generic object description below
|
|
100
|
+
}
|
|
101
|
+
let name = value?.constructor?.name
|
|
102
|
+
if (name && name != 'Object') {
|
|
103
|
+
return name
|
|
104
|
+
}
|
|
105
|
+
return Object.prototype.toString.call(value)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function formatValue(value) {
|
|
109
|
+
if (typeof value == 'string') {
|
|
110
|
+
return quoteString(value)
|
|
111
|
+
}
|
|
112
|
+
if (typeof value == 'undefined') {
|
|
113
|
+
return 'undefined'
|
|
114
|
+
}
|
|
115
|
+
if (value === null) {
|
|
116
|
+
return 'null'
|
|
117
|
+
}
|
|
118
|
+
if (typeof value == 'function') {
|
|
119
|
+
return describeFunction(value)
|
|
120
|
+
}
|
|
121
|
+
if (value instanceof RegExp) {
|
|
122
|
+
return value.toString()
|
|
123
|
+
}
|
|
124
|
+
if (typeof value == 'number' || typeof value == 'boolean' || typeof value == 'bigint') {
|
|
125
|
+
return String(value)
|
|
126
|
+
}
|
|
127
|
+
if (typeof value == 'symbol') {
|
|
128
|
+
return value.toString()
|
|
129
|
+
}
|
|
130
|
+
return jsonSummary(value)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function describeExpected(value) {
|
|
134
|
+
if (value === String || value === Number || value === Boolean) {
|
|
135
|
+
return describeFunction(value)
|
|
136
|
+
}
|
|
137
|
+
if (typeof value == 'function') {
|
|
138
|
+
return describeFunction(value)
|
|
139
|
+
}
|
|
140
|
+
if (value instanceof RegExp) {
|
|
141
|
+
return value.toString()
|
|
142
|
+
}
|
|
143
|
+
if (Array.isArray(value)) {
|
|
144
|
+
return '['+value.map(describeExpected).join(', ')+']'
|
|
145
|
+
}
|
|
146
|
+
return formatValue(value)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function describeOneOf(patterns) {
|
|
150
|
+
return patterns.map(describeExpected).join(', ')
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function conciseMessage(message, actual, expected) {
|
|
154
|
+
if (message == 'data and pattern are not equal') {
|
|
155
|
+
return `expected ${formatValue(expected)}, found ${formatValue(actual)}`
|
|
156
|
+
}
|
|
157
|
+
if (message == 'data does not match pattern' || /^data\[\d+\] does not match pattern$/.test(message)) {
|
|
158
|
+
return `expected ${describeExpected(expected)}, found ${formatValue(actual)}`
|
|
159
|
+
}
|
|
160
|
+
if (message == 'data is undefined, should match pattern') {
|
|
161
|
+
return `missing; expected ${describeExpected(expected)}`
|
|
162
|
+
}
|
|
163
|
+
if (message == 'data is required') {
|
|
164
|
+
return 'required'
|
|
165
|
+
}
|
|
166
|
+
if (message == 'data is an empty string, which is not allowed') {
|
|
167
|
+
return 'empty string is not allowed'
|
|
168
|
+
}
|
|
169
|
+
if (message == 'data is not an object, pattern is') {
|
|
170
|
+
return 'data is not an object'
|
|
171
|
+
}
|
|
172
|
+
if (message == 'data is not an instanceof pattern') {
|
|
173
|
+
return `expected instance of ${describeExpected(expected)}, found ${formatValue(actual)}`
|
|
174
|
+
}
|
|
175
|
+
if (message == 'data does not match oneOf patterns' || message == 'data does not match anyOf patterns') {
|
|
176
|
+
return `expected one of ${describeOneOf(expected)}, found ${formatValue(actual)}`
|
|
177
|
+
}
|
|
178
|
+
if (message == 'data matches pattern, when required not to') {
|
|
179
|
+
return `must not match ${describeExpected(expected)}`
|
|
180
|
+
}
|
|
181
|
+
return message
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function formatIssue(issue, options={}) {
|
|
185
|
+
if (!issue || typeof issue != 'object') {
|
|
186
|
+
return String(issue)
|
|
187
|
+
}
|
|
188
|
+
let path = issue.pathString || pathToString(issue.path || []) || 'value'
|
|
189
|
+
let indent = options.indent ?? ''
|
|
190
|
+
return `${indent}${path}: ${issue.message}`
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function formatIssues(issues, options={}) {
|
|
194
|
+
if (!issues) {
|
|
195
|
+
return false
|
|
196
|
+
}
|
|
197
|
+
let indent = options.indent ?? ' - '
|
|
198
|
+
return (Array.isArray(issues) ? issues : [issues]).map(issue => formatIssue(issue, { ...options, indent }))
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function issueFromProblem(problem) {
|
|
202
|
+
if (!problem || typeof problem != 'object') {
|
|
203
|
+
return {
|
|
204
|
+
path: [],
|
|
205
|
+
pathString: '',
|
|
206
|
+
message: String(problem),
|
|
207
|
+
expected: undefined,
|
|
208
|
+
actual: undefined
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
let path = pathToArray(problem.path)
|
|
212
|
+
let pathString = pathToString(path)
|
|
213
|
+
let actual = problem.actual ?? problem.found
|
|
214
|
+
let expected = describeExpected(problem.expected)
|
|
215
|
+
let message = conciseMessage(problem.message, actual, problem.expected)
|
|
216
|
+
return {
|
|
217
|
+
path,
|
|
218
|
+
pathString,
|
|
219
|
+
message,
|
|
220
|
+
expected,
|
|
221
|
+
actual
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function problemsToIssues(problems) {
|
|
226
|
+
if (!problems) {
|
|
227
|
+
return []
|
|
228
|
+
}
|
|
229
|
+
let result = []
|
|
230
|
+
for (let problem of Array.isArray(problems) ? problems : [problems]) {
|
|
231
|
+
if (!problem) {
|
|
232
|
+
continue
|
|
233
|
+
}
|
|
234
|
+
if (problem && typeof problem == 'object' && problem.problems) {
|
|
235
|
+
let nested = problemsToIssues(problem.problems)
|
|
236
|
+
if (nested.length) {
|
|
237
|
+
result = result.concat(nested)
|
|
238
|
+
continue
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
result.push(issueFromProblem(problem))
|
|
242
|
+
}
|
|
243
|
+
return result
|
|
27
244
|
}
|
|
28
245
|
|
|
29
246
|
/**
|
|
30
247
|
* This function will check the source for the assertions in test, if
|
|
31
|
-
* assertion checking is enabled
|
|
248
|
+
* assertion checking is enabled.
|
|
32
249
|
* If it is, and any assertion fails, it will throw an assertError
|
|
33
250
|
* with a list of problems and other details.
|
|
34
251
|
*/
|
|
35
252
|
export function assert(source, test) {
|
|
36
|
-
if (
|
|
253
|
+
if (assertEnabled) {
|
|
37
254
|
let problems = fails(source,test)
|
|
38
255
|
if (problems) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
256
|
+
let assertionIssues = problemsToIssues(problems)
|
|
257
|
+
let formattedIssues = formatIssues(assertionIssues)
|
|
258
|
+
let message = 'Assertions failed:\n'+formattedIssues.join('\n')
|
|
259
|
+
console.error('🅰️ '+message)
|
|
260
|
+
throw new Error(message, {
|
|
261
|
+
cause: { problems, issues: assertionIssues, source }
|
|
42
262
|
})
|
|
43
263
|
}
|
|
44
264
|
}
|
|
@@ -110,9 +330,10 @@ export function anyOf(...patterns) {
|
|
|
110
330
|
if (!Array.isArray(data)) {
|
|
111
331
|
return error('data is not an array',data,'anyOf',path)
|
|
112
332
|
}
|
|
113
|
-
for (let value of data) {
|
|
114
|
-
|
|
115
|
-
|
|
333
|
+
for (let [index, value] of data.entries()) {
|
|
334
|
+
let itemPath = appendPath(path, index)
|
|
335
|
+
if (oneOf(...patterns)(value, root, itemPath)) {
|
|
336
|
+
return error('data does not match anyOf patterns',value,patterns,itemPath)
|
|
116
337
|
}
|
|
117
338
|
}
|
|
118
339
|
return false
|
|
@@ -189,6 +410,22 @@ export function not(pattern) {
|
|
|
189
410
|
}
|
|
190
411
|
}
|
|
191
412
|
|
|
413
|
+
/**
|
|
414
|
+
* Returns structured, path-aware issues if the data fails to satisfy
|
|
415
|
+
* the assertions in the given pattern, or false otherwise.
|
|
416
|
+
* @param {any} data The data to match
|
|
417
|
+
* @param {any} pattern The pattern to match
|
|
418
|
+
* @param {any} root Root object for assertions, set to data by default
|
|
419
|
+
* @return {Array|false} Array with structured issues if the pattern fails, false otherwise
|
|
420
|
+
*/
|
|
421
|
+
export function issues(data, pattern, root) {
|
|
422
|
+
let problems = fails(data, pattern, root)
|
|
423
|
+
if (!problems) {
|
|
424
|
+
return false
|
|
425
|
+
}
|
|
426
|
+
return problemsToIssues(problems)
|
|
427
|
+
}
|
|
428
|
+
|
|
192
429
|
/**
|
|
193
430
|
* returns an array of problems if the data fails to satisfy
|
|
194
431
|
* the assertions in the given pattern, false otherwise
|
|
@@ -198,7 +435,7 @@ export function not(pattern) {
|
|
|
198
435
|
* @return {Array|false} Array with problems if the pattern fails, false otherwise
|
|
199
436
|
*/
|
|
200
437
|
export function fails(data, pattern, root, path='') {
|
|
201
|
-
if (
|
|
438
|
+
if (typeof root == 'undefined') {
|
|
202
439
|
root = data
|
|
203
440
|
}
|
|
204
441
|
let problems = []
|
|
@@ -219,9 +456,9 @@ export function fails(data, pattern, root, path='') {
|
|
|
219
456
|
}
|
|
220
457
|
} else if (pattern instanceof RegExp) {
|
|
221
458
|
if (Array.isArray(data)) {
|
|
222
|
-
let index = data.findIndex((element,index) => fails(element,pattern,root,path
|
|
459
|
+
let index = data.findIndex((element,index) => fails(element,pattern,root,appendPath(path, index)))
|
|
223
460
|
if (index>-1) {
|
|
224
|
-
problems.push(error('data['+index+'] does not match pattern', data[index], pattern, path
|
|
461
|
+
problems.push(error('data['+index+'] does not match pattern', data[index], pattern, appendPath(path, index)))
|
|
225
462
|
}
|
|
226
463
|
} else if (typeof data == 'undefined') {
|
|
227
464
|
problems.push(error('data is undefined, should match pattern', data, pattern, path))
|
|
@@ -240,22 +477,23 @@ export function fails(data, pattern, root, path='') {
|
|
|
240
477
|
} else if (Array.isArray(pattern)) {
|
|
241
478
|
if (!Array.isArray(data)) {
|
|
242
479
|
problems.push(error('data is not an array',data,[],path))
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
480
|
+
} else {
|
|
481
|
+
for (let p of pattern) {
|
|
482
|
+
for (let index of data.keys()) {
|
|
483
|
+
let problem = fails(data[index], p, root, appendPath(path, index))
|
|
484
|
+
if (Array.isArray(problem)) {
|
|
485
|
+
problems = problems.concat(problem)
|
|
486
|
+
} else if (problem) {
|
|
487
|
+
problems.push(problem)
|
|
488
|
+
}
|
|
251
489
|
}
|
|
252
490
|
}
|
|
253
|
-
|
|
491
|
+
}
|
|
254
492
|
} else if (pattern && typeof pattern == 'object') {
|
|
255
493
|
if (Array.isArray(data)) {
|
|
256
|
-
let index = data.findIndex((element,index) => fails(element,pattern,root,path
|
|
494
|
+
let index = data.findIndex((element,index) => fails(element,pattern,root,appendPath(path, index)))
|
|
257
495
|
if (index>-1) {
|
|
258
|
-
problems.push(error('data['+index+'] does not match pattern', data[index], pattern, path
|
|
496
|
+
problems.push(error('data['+index+'] does not match pattern', data[index], pattern, appendPath(path, index)))
|
|
259
497
|
}
|
|
260
498
|
} else if (!data || typeof data != 'object') {
|
|
261
499
|
problems.push(error('data is not an object, pattern is', data, pattern, path))
|
|
@@ -270,7 +508,7 @@ export function fails(data, pattern, root, path='') {
|
|
|
270
508
|
}
|
|
271
509
|
} else {
|
|
272
510
|
for (const [patternKey, subpattern] of Object.entries(pattern)) {
|
|
273
|
-
let result = fails(data[patternKey], subpattern, root, path
|
|
511
|
+
let result = fails(data[patternKey], subpattern, root, appendPath(path, patternKey))
|
|
274
512
|
if (result) {
|
|
275
513
|
problems = problems.concat(result)
|
|
276
514
|
}
|
|
@@ -291,9 +529,12 @@ export function fails(data, pattern, root, path='') {
|
|
|
291
529
|
/**
|
|
292
530
|
* Returns an object with message, found and expected properties
|
|
293
531
|
*/
|
|
294
|
-
export function error(message, found, expected, path, problems) {
|
|
532
|
+
export function error(message, found, expected, path='', problems) {
|
|
533
|
+
let pathParts = pathToArray(path)
|
|
295
534
|
let result = {
|
|
296
535
|
path,
|
|
536
|
+
pathString: pathToString(pathParts),
|
|
537
|
+
pathParts,
|
|
297
538
|
message,
|
|
298
539
|
found,
|
|
299
540
|
expected
|
|
@@ -306,4 +547,4 @@ export function error(message, found, expected, path, problems) {
|
|
|
306
547
|
|
|
307
548
|
export function warn(message, data, pattern, path) {
|
|
308
549
|
console.warn('🅰️ Assert: '+path, message, pattern, data)
|
|
309
|
-
}
|
|
550
|
+
}
|