Socket
Socket
Sign inDemoInstall

validate-value

Package Overview
Dependencies
Maintainers
4
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validate-value - npm Package Compare versions

Comparing version 4.0.0 to 4.1.0

8

dist/Value.js

@@ -28,2 +28,4 @@ 'use strict';

value: function validate(value) {
var valueName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'value';
if (value === undefined) {

@@ -43,4 +45,6 @@ throw new Error('Value is missing.');

var errors = getErrors(schema, value, result);
var message = errors[0].message;
var error = new Error(message);
var _errors$ = errors[0],
message = _errors$.message,
path = _errors$.path;
var error = new Error("".concat(message, " (at ").concat(valueName).concat(path.substring(1), ")."));
error.origins = errors;

@@ -47,0 +51,0 @@ throw error;

{
"name": "validate-value",
"version": "4.0.0",
"version": "4.1.0",
"description": "validate-value validates values against JSON schemas.",

@@ -5,0 +5,0 @@ "contributors": [

@@ -48,3 +48,3 @@ # validate-value

By default, the error message uses `Value` as identifier for the object that is validated, but sometimes you may want to change this. Therefor, provide the desired identifier as second parameter to the `validate` function:
By default, the error message uses `value` as identifier for the object that is validated, but sometimes you may want to change this. Therefor, provide the desired identifier as second parameter to the `validate` function:

@@ -58,3 +58,3 @@ ```javascript

try {
value.validate(user, 'Person');
value.validate(user, 'person');
} catch (ex) {

@@ -61,0 +61,0 @@ // ...

@@ -15,3 +15,3 @@ 'use strict';

validate (value) {
validate (value, valueName = 'value') {
if (value === undefined) {

@@ -33,5 +33,5 @@ throw new Error('Value is missing.');

const errors = getErrors(schema, value, result);
const { message } = errors[0];
const { message, path } = errors[0];
const error = new Error(message);
const error = new Error(`${message} (at ${valueName}${path.substring(1)}).`);

@@ -38,0 +38,0 @@ error.origins = errors;

@@ -52,6 +52,16 @@ 'use strict';

}).is.throwing(ex =>
ex.message === 'Missing required property: password' &&
ex.message === 'Missing required property: password (at value.password).' &&
Array.isArray(ex.origins));
});
test('throws an error with the given value name if schema does not match.', async () => {
assert.that(() => {
schema.validate({
username: 'Jane Doe'
}, 'root');
}).is.throwing(ex =>
ex.message === 'Missing required property: password (at root.password).' &&
Array.isArray(ex.origins));
});
test('throws only the first error when there are more than one.', async () => {

@@ -61,3 +71,3 @@ assert.that(() => {

}).is.throwing(ex =>
ex.message === `Missing required property: username` &&
ex.message === `Missing required property: username (at value.username).` &&
Array.isArray(ex.origins));

@@ -64,0 +74,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc