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.
39 lines
828 B
JavaScript
39 lines
828 B
JavaScript
"use strict";
|
|
|
|
const anyProperty = require("./");
|
|
const { validateValue } = require("@validatem/core");
|
|
const isString = require("@validatem/is-string");
|
|
|
|
let validator = anyProperty({
|
|
key: [ isString ],
|
|
value: [ isString ]
|
|
});
|
|
|
|
let objectA = {
|
|
foo: "bar",
|
|
baz: "qux"
|
|
};
|
|
|
|
console.log(validateValue(objectA, validator)); // { foo: 'bar', baz: 'qux' }
|
|
|
|
let objectB = {
|
|
foo: "bar",
|
|
baz: 42
|
|
};
|
|
|
|
console.log(validateValue(objectB, validator)); /*
|
|
AggregrateValidationError: One or more validation errors occurred:
|
|
- At baz -> (value): Must be a string
|
|
*/
|
|
|
|
let SomeSymbol = Symbol("SomeSymbol");
|
|
let objectC = {
|
|
foo: "bar",
|
|
[SomeSymbol]: "qux"
|
|
};
|
|
|
|
console.log(validateValue(objectC, validator)); /*
|
|
AggregrateValidationError: One or more validation errors occurred:
|
|
- At Symbol(SomeSymbol) -> (key): Must be a string
|
|
*/
|