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.

35 lines
768 B
JavaScript

"use strict";
const hasShape = require("./");
const { validateValue } = require("@validatem/core"); /* FIXME: Add this as a devDep */
const isString = require("@validatem/is-string");
let validator = hasShape({
foo: [ 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'
*/