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.

34 lines
748 B
JavaScript

"use strict";
const { validateValue } = require("@validatem/core");
const isString = require("@validatem/is-string");
const when = require("./");
let rule = when((object) => object.type === "string", {
value: [ isString ]
});
let objectA = {
type: "string",
value: "hello world"
};
console.log(validateValue(objectA, rule)); // { type: 'string', value: 'hello world' }
let objectB = {
type: "number", /* Note that there are no rules for this case! */
value: 42
};
console.log(validateValue(objectB, rule)); // { type: 'number', value: 42 }
let objectC = {
type: "string",
value: 42
};
console.log(validateValue(objectC, rule)); /*
AggregrateValidationError: One or more validation errors occurred:
- At value: Must be a string
*/