JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3752
  • Score
    100M100P100Q163897F
  • License MIT

Compiles parser tree into array of top level functions

Package Exports

  • indicative-compiler

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (indicative-compiler) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

UsageWhy?FeaturesExamplesDocumentation


Compiler

The compiler package takes the parser input and creates a highly performant function that can be cached to run validations with runtime data. Below are some benchmarks ran on the output function of compiler with dummy rules.

  • Macbook Pro (2.2 GHz Intel Core i7): 2,281,616 ops/sec

Usage

Install the package from npm

npm i indicative-compiler

# yarn user
yarn add indicative-compiler

and then use it as follows

const { validationCompiler } = require('indicative-compiler')

const rulesSchema = {
  username: 'required'
}

const validations = {
  required: {
    async: false,
    validate () {
      return true
    }
  }
}

const messagesSchema = {
  'username.required': 'Username is required'
}

const validate = validationCompiler(rulesSchema, validations, messagesSchema)

The above code will output a pre-compiled function, that can be used to run validations using runtime data.

const { vanilla } = require('indicative-formatters')
const config = {}

/**
 * Bail true means stop on first validation error
 */
const bail = true

validate(data, vanilla, config, bail)
  .then(console.log)
  .catch(console.error)