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.

29 lines
845 B
JavaScript

"use strict";
const allowExtraProperties = require("./");
const { validateValue } = require("@validatem/core");
const hasShape = require("@validatem/has-shape");
const isString = require("@validatem/is-string");
let object = {
foo: "bar",
baz: "qux"
};
let resultA = validateValue(object, allowExtraProperties({ foo: isString })); // { foo: 'bar', baz: 'qux' }
console.log(resultA);
// Also works with explicit hasShape!
let resultB = validateValue(object, allowExtraProperties(hasShape({ foo: isString }))); // { foo: 'bar', baz: 'qux' }
console.log(resultB);
// Without allowExtraProperties, we'd get an error
let resultC = validateValue(object, { foo: isString }); /*
AggregrateValidationError: One or more validation errors occurred:
- At (root): Encountered an unexpected property 'baz'
*/
console.log(resultC); // Never reached