occamsrazor-validator
Advanced tools
Comparing version 8.0.1 to 9.0.0
@@ -18,6 +18,5 @@ var ValidationResult = require('./validation-result'); | ||
if (args.length < validators.length) { | ||
decoratedCallback && decoratedCallback({ path: '', name: 'minArguments:' + args.length, result: false, value: args }); | ||
decoratedCallback && decoratedCallback({ path: '', name: 'minArguments:' + args.length, value: args }); | ||
return null; | ||
} | ||
decoratedCallback && decoratedCallback({ path: '', name: 'minArguments:' + args.length, result: true, value: args }); | ||
for (i = 0, l = validators.length; i < l; i++) { | ||
@@ -24,0 +23,0 @@ validator = validators[i]; |
{ | ||
"name": "occamsrazor-validator", | ||
"version": "8.0.1", | ||
"version": "9.0.0", | ||
"description": "A duck-typing library", | ||
@@ -34,4 +34,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"occamsrazor-match": "^2.2.1" | ||
"occamsrazor-match": "^4.0.0" | ||
} | ||
} |
@@ -93,6 +93,7 @@ occamsrazor-validator | ||
// match with width and height equal to 10 | ||
var has_width_and_height_10 = validator().match({width: 10, height: 10}); | ||
var has_width_and_height_10 = validator().match({ width: 10, height: 10 }); | ||
// match with a center attribute with x and y subattributes | ||
var has_center = validator().match({center: {x: undefined, y: undefined}}); | ||
var isNumber = require('occamsrazor-match/extra/isNumber'); // you can find many helpers in this library | ||
var has_center = validator().match({ center: { x: isNumber, y: isNumber } }); | ||
@@ -150,7 +151,6 @@ // match if obj.recipe.ingredients is a string and match with /nuts/ | ||
var has_width_and_height_10 = validator().match({width: 10, height: 10}); | ||
has_width_and_height_10({width: 10, height: 10}, function debug (o) { | ||
has_width_and_height_10({width: 10, height: 10}, function onError (o) { | ||
// "o" contains: | ||
// name: 'the validator name', | ||
// path: if the validation is applied to an object, the path of the current validation | ||
// result: true or false, | ||
// value: the value used for the validation, | ||
@@ -166,3 +166,2 @@ }); | ||
// path: if the validation is applied to an object, the path of the current validation | ||
// result: true or false, | ||
// value: the value used for the validation, | ||
@@ -240,7 +239,8 @@ }); | ||
```js | ||
var hasCenterX = validator().match({center: {x: undefined}}); | ||
// will match {center: {x: "10"}} | ||
var hasCenterX = validator() | ||
.match({ center: { x: /[0-9]+/ } }); | ||
// will match { center: {x: "10"} } | ||
var hasCenterX10 = validator().match({center: {x: "10"}}); | ||
// will match {center: {x: "10"}} but not {center: {x: "11"}} | ||
// will match {center: { x: "10" } } but not {center: { x: "11" } } | ||
@@ -247,0 +247,0 @@ var hasCenter5or10 = validator().match({center: {x : function (c){ |
@@ -24,30 +24,4 @@ var assert = require('chai').assert; | ||
assert.deepEqual(out, [ | ||
{ path: '', | ||
name: 'minArguments:3', | ||
result: true, | ||
value: [ 1, 5, [ 3 ] ], | ||
validatorName: 'isAnything (score: 0), isNumber:5 (score: 1), and(isArray object:{length:isNumber:2}) (score: 2)' }, | ||
{ path: '', | ||
name: 'isNumber:5', | ||
result: true, | ||
value: 5, | ||
validatorName: 'isNumber:5 (score: 1)' }, | ||
{ path: '', | ||
name: 'isArray', | ||
result: true, | ||
value: [ 3 ], | ||
validatorName: 'and(isArray object:{length:isNumber:2}) (score: 2)' }, | ||
{ path: '', | ||
name: 'isObject', | ||
result: true, | ||
value: [ 3 ], | ||
validatorName: 'and(isArray object:{length:isNumber:2}) (score: 2)' }, | ||
{ path: 'length', | ||
name: 'hasAttribute', | ||
result: true, | ||
value: [ 3 ], | ||
validatorName: 'and(isArray object:{length:isNumber:2}) (score: 2)' }, | ||
{ path: 'length', | ||
name: 'isNumber:2', | ||
result: false, | ||
value: 1, | ||
@@ -54,0 +28,0 @@ validatorName: 'and(isArray object:{length:isNumber:2}) (score: 2)' }, |
@@ -29,3 +29,2 @@ var assert = require('chai').assert; | ||
path: '', | ||
result: false, | ||
value: 'hi', | ||
@@ -32,0 +31,0 @@ } |
var assert = require('chai').assert; | ||
var validator = require('..'); | ||
var isDefined = require('occamsrazor-match/extra/isDefined'); | ||
@@ -53,3 +54,3 @@ describe('validator match', function () { | ||
center: { | ||
x: '10', y: undefined | ||
x: '10', y: isDefined | ||
} | ||
@@ -56,0 +57,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
26976
471
+ Addedoccamsrazor-match@4.1.1(transitive)
- Removedoccamsrazor-match@2.2.1(transitive)
Updatedoccamsrazor-match@^4.0.0