ajv-error-messages
Advanced tools
Comparing version 2.0.0 to 2.1.0
10
index.js
function normaliseErrorMessages(errors) { | ||
var fields = errors.reduce(function (acc, e) { | ||
if (e.instancePath.length && e.instancePath[0] === ".") { | ||
acc[e.instancePath.slice(1)] = [ | ||
e.message.toUpperCase()[0] + e.message.slice(1), | ||
]; | ||
if (e.instancePath.length && e.instancePath[0] === "/") { | ||
let path = e.instancePath.slice(1); | ||
if (Number.isInteger(parseInt(path, 10))) { | ||
path = `/${path}`; | ||
} | ||
acc[path] = [e.message.toUpperCase()[0] + e.message.slice(1)]; | ||
} else { | ||
@@ -8,0 +10,0 @@ acc[e.instancePath] = [e.message.toUpperCase()[0] + e.message.slice(1)]; |
{ | ||
"name": "ajv-error-messages", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Normalise AJV error messages", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,2 +7,6 @@ # ajv-error-messages | ||
# AJV Version | ||
v2 of `ajv-error-messages` has been upgraded to work with v8 of `ajv` | ||
## Usage | ||
@@ -52,5 +56,5 @@ | ||
fields: { | ||
'/foo': ['Must be string'] | ||
'foo': ['Must be string'] | ||
} | ||
} | ||
``` |
@@ -37,6 +37,6 @@ var test = require("tape"); | ||
fields: { | ||
"/foo": ["Must be string"], | ||
"/arrayThing": ["Must NOT have more than 2 items"], | ||
"/arrayThing/0": ["Must be string"], | ||
"/arrayThing/1": ["Must be integer"], | ||
foo: ["Must be string"], | ||
arrayThing: ["Must NOT have more than 2 items"], | ||
"arrayThing/0": ["Must be string"], | ||
"arrayThing/1": ["Must be integer"], | ||
}, | ||
@@ -43,0 +43,0 @@ }; |
Sorry, the diff of this file is not supported yet
5433
84
59