another-json-schema
Advanced tools
Comparing version 3.8.1 to 3.8.2
@@ -0,1 +1,5 @@ | ||
## 3.8.2/2018-01-17 | ||
- add `.length` helper | ||
## 3.8.1/2018-01-10 | ||
@@ -2,0 +6,0 @@ |
@@ -12,2 +12,13 @@ const validator = require('validator') | ||
/* | ||
* String | ||
*/ | ||
exports.length = function (actual, expected, key, parent) { | ||
if (Array.isArray(expected)) { | ||
const len = actual.length | ||
return len >= expected[0] && len <= expected[1] | ||
} | ||
return actual.length === expected | ||
} | ||
// return true|false | ||
@@ -14,0 +25,0 @@ /* |
{ | ||
"name": "another-json-schema", | ||
"version": "3.8.1", | ||
"version": "3.8.2", | ||
"description": "Another JSON Schema, simple & flexible & intuitive.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -151,2 +151,28 @@ const AJS = require('..') | ||
it('.length', function () { | ||
const stringSchema = AJS('stringSchema', { type: 'string', length: 1 }) | ||
assert.deepEqual(stringSchema.validate('a'), { valid: true, error: null, result: 'a' }) | ||
assert.deepEqual(stringSchema.validate('hehe'), { valid: false, | ||
error: | ||
{ | ||
validator: 'length', | ||
path: '$', | ||
actual: 'hehe', | ||
expected: { type: 'string', length: 1 }, | ||
schema: 'stringSchema' }, | ||
result: 'hehe' }) | ||
const stringSchema2 = AJS('stringSchema2', { type: 'string', length: [1, 2] }) | ||
assert.deepEqual(stringSchema2.validate('a'), { valid: true, error: null, result: 'a' }) | ||
assert.deepEqual(stringSchema2.validate('hehe'), { valid: false, | ||
error: | ||
{ | ||
validator: 'length', | ||
path: '$', | ||
actual: 'hehe', | ||
expected: { type: 'string', length: [1, 2] }, | ||
schema: 'stringSchema2' }, | ||
result: 'hehe' }) | ||
}) | ||
it('.gt', function () { | ||
@@ -153,0 +179,0 @@ const schema = AJS('numberSchema', { type: 'number', gt: 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
57827
1464