Comparing version 0.3.0 to 0.4.0
46
jjve.js
@@ -44,3 +44,3 @@ (function() { | ||
case 'required': | ||
properties = o.ns.split(o.sep); | ||
properties = o.ns; | ||
@@ -158,3 +158,3 @@ error = { | ||
case 'additional': | ||
properties = o.ns.split(o.sep); | ||
properties = o.ns; | ||
@@ -241,9 +241,6 @@ error = { | ||
var isArray = key.match(/^\d+$/); | ||
var opts = { | ||
env: o.env, | ||
schema: s || {}, | ||
ns: o.ns + (isArray ? '[' + key + ']' : (o.sep + key)), | ||
sep: o.sep | ||
ns: o.ns.concat(key) | ||
}; | ||
@@ -295,2 +292,26 @@ | ||
function formatPath(options) { | ||
var root = options.hasOwnProperty('root') ? | ||
options.root : '$'; | ||
var sep = options.hasOwnProperty('sep') ? | ||
options.sep : '.'; | ||
return function(error) { | ||
var path = root; | ||
error.path.forEach(function(key) { | ||
path += key.match(/^\d+$/) ? | ||
'[' + key + ']' : | ||
key.match(/^[A-Z_$][0-9A-Z_$]*$/i) ? | ||
(sep + key) : | ||
('[' + JSON.stringify(key) + ']'); | ||
}); | ||
error.path = path; | ||
return error; | ||
}; | ||
} | ||
function jjve(env) { | ||
@@ -302,7 +323,5 @@ return function jjve(schema, data, result, options) { | ||
if (!options.hasOwnProperty('root')) options.root = '$'; | ||
if (!options.hasOwnProperty('sep')) options.sep = '.'; | ||
if (typeof schema === 'string') { schema = env.schema[schema]; } | ||
return make({ | ||
var errors = make({ | ||
env: env, | ||
@@ -312,6 +331,11 @@ schema: schema, | ||
validation: result.validation, | ||
sep: options.sep, | ||
ns: options.root, | ||
ns: [], | ||
definitions: schema.definitions || {} | ||
}); | ||
if (errors.length && options.formatPath !== false) { | ||
return errors.map(formatPath(options)); | ||
} | ||
return errors; | ||
}; | ||
@@ -318,0 +342,0 @@ } |
{ | ||
"name": "jjve", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Render JJV errors", | ||
"main": "jjve.js", | ||
"devDependencies": { | ||
"istanbul": "^0.3.0", | ||
"jjv": "^1.0.0", | ||
@@ -8,0 +9,0 @@ "jscs": "^1.4.5", |
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
14664
7
338
6