@flatfile/plugin-constraints
v7.0.0
Published
A plugin for extending blueprint with external constraints
Downloads
3,403
Maintainers
Keywords
Readme
@flatfile/plugin-constraints
This plugin introduces the ability to register external constraints for blueprint.
Usage
listener.use(
externalConstraint('length', (value, key, { config, record }) => {
if (value.length > config.max) {
record.addError(key, `Text must be under ${config.max} characters`)
// alternatively throw the error
}
})
)
// blueprint fields
[
{
key: 'name',
type: 'string',
constraints: [
{ type: 'external', validator: 'length', config: { max: 100 } }
]
},
{
key: 'age',
type: 'number',
}
]