🧑🎓 Optional
If you want to allow null
and undefined
as allowed values, you can use optional()
function to transform Predicate
into a Predicate
that allows those values:
const { asVerificable, optional, isString, ensure } = require("verifica");
function sayName(name) {
const vname = asVerificable(name);
const isOptionalString = optional(isString);
ensure(vname, isOptionalString);
if (name == null) {
console.log("Hello, anonymous!");
} else {
console.log(`Hello, ${name}!`);
}
}
Last updated
Was this helpful?