ajv-error-tree
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -1,3 +0,10 @@ | ||
const { strict: Assert } = require("assert"); | ||
const { ownKeys, getOwnPropertyDescriptor } = Reflect; | ||
const { isArray } = Array; | ||
const assert = (boolean, message) => { | ||
if (!boolean) { | ||
throw new Error(message); | ||
} | ||
}; | ||
exports.structureAJVErrorArray = (errors) => { | ||
@@ -7,3 +14,3 @@ let index = errors.length; | ||
index -= 1; | ||
Assert.ok(index >= 0, "something went wrong"); | ||
assert(index >= 0, "something went wrong"); | ||
const error = { | ||
@@ -14,12 +21,7 @@ ...errors[index], | ||
}; | ||
Assert.notEqual( | ||
Reflect.getOwnPropertyDescriptor(error, "schema"), | ||
undefined, | ||
assert( | ||
getOwnPropertyDescriptor(error, "schema") !== undefined, | ||
"missing schema field, this is probably because the verbose options was not set to true -- new Ajv({verbose:true})" | ||
); | ||
Assert.notEqual( | ||
error.keyword, | ||
"allOf", | ||
"unexpected allOf schema combinator" | ||
); | ||
assert(error.keyword !== "allOf", "unexpected allOf schema combinator"); | ||
if (error.keyword === "anyOf") { | ||
@@ -45,9 +47,9 @@ error.children = error.schema.slice().reverse().map(visit).reverse(); | ||
if (depth === 0) { | ||
return Array.isArray(any) ? "... (array)" : "... (object)"; | ||
return isArray(any) ? "... (array)" : "... (object)"; | ||
} | ||
if (Array.isArray(any)) { | ||
if (isArray(any)) { | ||
return any.map((any) => strip(any, depth - 1)); | ||
} | ||
let copy = { __proto__: null }; | ||
for (let key of Reflect.ownKeys(any)) { | ||
for (let key of ownKeys(any)) { | ||
copy[key] = strip(any[key], depth - 1); | ||
@@ -90,5 +92,3 @@ } | ||
}, | ||
...(Reflect.ownKeys(error.params).length === 0 | ||
? {} | ||
: { params: error.params }), | ||
...(ownKeys(error.params).length === 0 ? {} : { params: error.params }), | ||
message: error.message, | ||
@@ -95,0 +95,0 @@ ...(error.children.length === 0 |
{ | ||
"name": "ajv-error-tree", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"scripts": { | ||
"test": "node test/test.js", | ||
"prettier": "npx prettier --write 'lib/*.js' 'test/*.js'", | ||
"format": "npx prettier --write 'lib/*.js' 'test/*.js'", | ||
"lint": "npx eslint 'lib/*.js' 'test/*.js'" | ||
@@ -8,0 +8,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5248
94