7.2.4 • Published 4 years ago

indicative-compiler v7.2.4

Weekly downloads
2,871
License
MIT
Repository
github
Last release
4 years ago

Indicative Compiler

circleci-image npm-image license-image

Indicative compiler to compile validations schema into a highly optimized executable function.

Indicative is a highly performant validation library for Node.js. It achieves this by compiling the schema into a tree and then an a top level executable function.

Table of contents

Usage

Install the package from npm registry as follows:

You must use indicative directly. This is a low level module meant to be used by indicative itself.

npm i indicative-compiler

# yarn
yarn add indicative-compiler

and then use it as follows:

import { ValidatorCompiler, ValidatorExecutor } from 'indicative-compiler'
import { VanillaFormatter } from 'indicative-formatters'
import * as validations from 'indicative-rules'

const schema = {
  username: 'required',
  email: 'required|email'
}

const messages = {}

// Do it once for each schema
const compiledFunctions = new ValidatorCompiler(schema, messages).compile()

await new ValidatorExecutor(compiledFunctions).exec(data, VanillaFormatter, {}, false, false)

The ValidatorExecutor.exec function takes 5 parameters.

  1. data: The runtime data to validate against the compiled schema.
  2. formatter: Formatter constructor to collect and format error messages.
  3. config: The config to be passed to all the validation functions.
  4. bail: When true, it will stop after first error.
  5. removeAdditional: When true, the exec will return only validated properties.

API Docs

Following are the autogenerated files via Typedoc

7.2.4

4 years ago

7.2.3

4 years ago

7.2.2

4 years ago

7.2.1

4 years ago

7.2.0

4 years ago

7.1.0

4 years ago

7.0.5

5 years ago

7.0.4

5 years ago

7.0.3

5 years ago

7.0.2

5 years ago

7.0.1

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

7.0.0

5 years ago

6.0.0

5 years ago