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.

36 lines
757 B
JavaScript

"use strict";
const hasShape = require("./");
const { validateValue } = require("@validatem/core");
const isString = require("@validatem/is-string");
let validator = hasShape({
foo: [ isString ],
unused: [ isString ]
});
let objectA = {
foo: "bar"
};
console.log(validateValue(objectA, validator)); // { foo: 'bar' }
let objectB = {
foo: 42
};
console.log(validateValue(objectB, validator)); /*
AggregrateValidationError: One or more validation errors occurred:
- At foo: Must be a string
*/
let objectC = {
foo: "hello world",
otherProperty: "baz"
};
console.log(validateValue(objectC, validator)); /*
AggregrateValidationError: One or more validation errors occurred:
- At (root): Encountered an unexpected property 'otherProperty'
*/