Indicative compiler to compile parsed schema into highly optimized functions
npm install indicative-compiler
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.
> You must use indicative directly. This is a low level module meant to be used by indicative itself.
``sh
npm i 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
[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"