validatem-as-array-of
v0.0.1
Published
Validatem validator for ensuring a value is an array, adding a single value into an Array if needed
Downloads
232
Readme
Validatem asArrayOf
Ensures an Array with entries that comply to provided further validation, while also transforming single values by adding them to a new Array.
const { validateValue } = require("@validatem/core");
const asArrayOf = require("validatem-as-array-of");
const isString = require("@validatem/is-string");
validateValue(["test"], asArrayOf(isString)); // [ 'test' ]
validateValue("test", asArrayOf(isString)); // [ 'test' ]
validateValue(undefined, asArrayOf(isString)); // [ ]
validateValue(42, asArrayOf(isString)); // throws ValidationError
See also the example.js in this repository.