<div align="center">
  <img src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1557762307/poppinss_iftxlt.jpg" width="600px">
</div>

# Indicative Compiler
[![circleci-image]][circleci-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url]
> 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.

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
## Table of contents

- [Usage](#usage)
- [API Docs](#api-docs)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Usage
Install the package from npm registry as follows:

> You must use [indicative](https://github.com/poppinss/indicative) directly. This is a low level module meant to be used by indicative itself.

```sh
npm i indicative-compiler

# yarn
yarn add indicative-compiler
```

and then use it as follows:

```ts
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

* [API](docs/README.md)

[circleci-image]: https://img.shields.io/circleci/project/github/poppinss/indicative-compiler/master.svg?style=for-the-badge&logo=circleci
[circleci-url]: https://circleci.com/gh/poppinss/indicative-compiler "circleci"

[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
[typescript-url]:  "typescript"

[npm-image]: https://img.shields.io/npm/v/indicative-compiler.svg?style=for-the-badge&logo=npm
[npm-url]: https://npmjs.org/package/indicative-compiler "npm"

[license-image]: https://img.shields.io/npm/l/indicative-compiler?color=blueviolet&style=for-the-badge
[license-url]: LICENSE.md "license"
