Browse plugins

plugin-constraints

A plugin for extending blueprint with external constraints

Install
npm i @flatfile/plugin-constraints
Source:
View source
Package:
@flatfile/plugin-constraints 1k installs

@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',
  }
]