schema-inspector
Advanced tools
Comparing version 2.0.3 to 2.1.0
@@ -410,2 +410,11 @@ // Disable no-var because we need to support old IE for now. | ||
}, | ||
multipleOf: function (schema, candidate) { | ||
const divisor = Number(schema.multipleOf); | ||
if (typeof candidate !== 'number' || isNaN(divisor)) { | ||
return; | ||
} | ||
if (candidate % divisor !== 0) { | ||
this.report(candidate + ' is not divisible by ' + divisor, null, 'multipleOf'); | ||
} | ||
}, | ||
someKeys: function (schema, candidat) { | ||
@@ -412,0 +421,0 @@ var _keys = schema.someKeys; |
{ | ||
"name": "schema-inspector", | ||
"description": "Schema-Inspector is a powerful tool to sanitize and validate JS objects.", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"main": "index.js", | ||
@@ -35,3 +35,3 @@ "author": { | ||
"mocha": "^10.0.0", | ||
"semistandard": "^16.0.1", | ||
"semistandard": "^17.0.0", | ||
"should": "^13.2.3" | ||
@@ -38,0 +38,0 @@ }, |
@@ -143,2 +143,3 @@ <!-- markdownlint-disable MD041 MD033 MD024 --> | ||
* [lt, lte, gt, gte, eq, ne](#v_comparators) | ||
* [multipleOf](#v_multipleOf) | ||
* [someKeys](#v_someKeys) | ||
@@ -433,2 +434,28 @@ * [strict](#v_strict) | ||
<h3 id="v_multipleOf">multipleOf</h3> | ||
* **type**: number | ||
* **usable on**: number, array | ||
Check whether the candidate is a multiple of the provided option. If the candidate is an array of numbers, it performs this validation on each number in the array. | ||
#### Example | ||
```javascript | ||
var inspector = require('schema-inspector'); | ||
var schema = { | ||
type: 'number', | ||
multipleOf: 2 // Even | ||
}; | ||
var c1 = 100; | ||
var c2 = 73; | ||
inspector.validate(schema, c1); // Valid | ||
inspector.validate(schema, c2); // Invalid: 73 is not divisible by 2 | ||
``` | ||
--------------------------------------- | ||
<h3 id="v_someKeys">someKeys</h3> | ||
@@ -435,0 +462,0 @@ |
88503
1554
1328