SYNOPSIS
Models backed by validimir
.
Define, validate and sanitize without any DSLs or schema languages.
BUILD
USAGE
const Models = let v = Models let data = beep: boop: 'k' foo: bar: bazz: quxx: 100 let result = if resultlength === 0 consoleelse console
Function
Models.create(Object
obj [, Object
model, ...])
create(object)
accepts an object with
object paths
for keys and
validation functions
for values, returns a validator
function. It can
also be extended with other models by passing them in as additional arguments.
let v = Models
Function
Models.validators([Boolean
optional]])
Returns a chainable set of validator functions via
validimir
. Validators cover
a good number of use cases, here are a few examples...
// an item is in an arrayModels'foo' // a custom pattern matchModels // a rangeModels'a'
Object
validate(Object
object[, Boolean
sanitize])
The validator
function only cares about property paths that are specified
in the model, that way you can be liberal with data and strict about specific
details. You can also pass a bool as the second parameter which will remove
any properties that have not been specified in the model.
let data = beep: boop: 'bla' bla: 100 let result = if resultlength === 0 consoleelse console
When there are errors, they will be detailed, for example...
let v = Models let data = beep: boop: 'k' bla: 100 console