"use strict"; const { validateValue } = require("@validatem/core"); const isString = require("@validatem/is-string"); const wrapError = require("./"); /*** Simple rules ***/ let rule = wrapError("This is a custom error message complaining that the value must be a string!", "wrap-error.custom", [ isString ]); console.log(validateValue("hello world", [ rule ])); // hello world try { console.log(validateValue(42, [ rule ])); } catch (error) { console.log("Error occurred:", error.stack); /* Error occurred: AggregrateValidationError: One or more validation errors occurred: - At (root): This is a custom error message complaining that the value must be a string! */ } /*** Combinators with properties, and preserving the original errors as well ***/ let objectRule = wrapError("Must be a valid thingem", "wrap-error.thingem", { a: [ isString ], b: [ isString ] }, { preserveOriginalErrors: true }); let objectA = { a: "hello", b: "world" }; console.log(validateValue(objectA, [ objectRule ])); // { a: 'hello', b: 'world' } let objectB = { a: "hello", b: 42 }; console.log(validateValue(objectB, [ objectRule ])); /* AggregrateValidationError: One or more validation errors occurred: - At (root): Must be a valid thingem └─ b: Must be a string */