Comparing version 0.6.0 to 0.6.1
@@ -6,2 +6,39 @@ 'use strict'; | ||
const padder = (res, row) => { | ||
row.map((e, i) => { | ||
if (typeof res[i] !== 'number') { | ||
res[i] = 0; | ||
} | ||
res[i] = Math.max(res[i], e.toString().length); | ||
}); | ||
return res; | ||
}; | ||
const hfmt = [ | ||
{head: '\u001b[4m', tail: '\u001b[0m '}, | ||
{head: '\u001b[4m', tail: '\u001b[0m '}, | ||
{head: '\u001b[4m', tail: '\u001b[0m '} | ||
]; | ||
const bfmt = [ | ||
{head: '\u001b[33;1m', tail: '\u001b[0m '}, | ||
{head: '\u001b[34;1m', tail: '\u001b[0m '}, | ||
{head: '\u001b[37;1m', tail: '\u001b[0m '} | ||
]; | ||
const formatter = (fmt, widths) => | ||
(res, col, i) => | ||
res + fmt[i].head + col.toString().padEnd(widths[i]) + fmt[i].tail; | ||
const logger = errors => { | ||
const errora = errors.map(err => [err.dataPath, err.schemaPath, err.message]); | ||
const widths = errora.reduce(padder, []); | ||
return [ | ||
'DUH document does not match schema:', | ||
['data path', 'schema path', 'message'].reduce(formatter(hfmt, widths), ''), | ||
errora.map(row => row.reduce(formatter(bfmt, widths), '')).join('\n') | ||
].join('\n'); | ||
}; | ||
module.exports = duh => new Promise((resolve, reject) => { | ||
@@ -15,4 +52,5 @@ const ajv = new Ajv; | ||
} else { | ||
reject(validate.errors); | ||
// reject(validate.errors); | ||
reject(logger(validate.errors)); | ||
} | ||
}); |
{ | ||
"name": "duh-core", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "DUH core", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
17144
151