You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
995 B
JavaScript
45 lines
995 B
JavaScript
5 years ago
|
"use strict";
|
||
|
|
||
|
const { validateValue } = require("./");
|
||
|
const isString = require("@validatem/is-string");
|
||
|
const isBoolean = require("@validatem/is-boolean");
|
||
|
const isNumber = require("@validatem/is-number");
|
||
|
const required = require("@validatem/required");
|
||
|
const arrayOf = require("@validatem/array-of");
|
||
|
const anyProperty = require("@validatem/any-property");
|
||
|
|
||
|
let data = {
|
||
|
one: "foo",
|
||
|
two: "bar",
|
||
|
array: [
|
||
|
"A",
|
||
|
false,
|
||
|
"C"
|
||
|
],
|
||
|
mapping: {
|
||
|
a: true,
|
||
|
b: false,
|
||
|
c: false,
|
||
|
d: NaN
|
||
|
}
|
||
|
};
|
||
|
|
||
|
validateValue(data, {
|
||
|
one: [ required, isString ],
|
||
|
two: [ required, isNumber ],
|
||
|
three: [ required, isBoolean ],
|
||
|
array: [ required, arrayOf([ required, isString ]) ],
|
||
|
mapping: [ required, anyProperty({
|
||
|
key: [ required ],
|
||
|
value: [ required, isBoolean ]
|
||
|
}) ]
|
||
|
});
|
||
|
|
||
|
/*
|
||
|
AggregrateValidationError: One or more validation errors occurred:
|
||
|
- At two: Must be a number
|
||
|
- At three: Required value is missing
|
||
|
- At array -> 1: Must be a string
|
||
|
- At mapping -> d -> (value): Must be a boolean
|
||
|
*/
|