# indicative-parser

> Schema parser for Indicative

Latest version **8.0.0** (published 2020-01-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install indicative-parser
pnpm add indicative-parser
yarn add indicative-parser
bun add indicative-parser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 8.0.0 |
| Published | 2020-01-04 |
| First published | 2019-03-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 17.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | virk,poppinss |
| Maintainers | virk |
| Keywords | indicative, validator, parser |

## Links

- npm: https://www.npmjs.com/package/indicative-parser
- Repository: https://github.com/poppinss/indicative-parser
- Homepage: https://github.com/poppinss/indicative-parser#readme
- Issues: https://github.com/poppinss/indicative-parser/issues
- npm.io page: https://npm.io/package/indicative-parser

## Dependencies (1)

- [haye](https://npm.io/package/haye.md) ^2.0.2

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 8.0.0 (latest) — 2020-01-04
- 1.0.0 (alpha) — 2019-06-05
- 7.1.4 — 2019-12-25
- 7.1.3 — 2019-12-25
- 7.1.2 — 2019-12-09
- 7.1.1 — 2019-12-08
- 7.1.0 — 2019-12-08
- 7.0.3 — 2019-12-02
- 7.0.2 — 2019-09-02
- 7.0.1 — 2019-07-08
- 1.0.1 — 2019-07-07
- 7.0.0 — 2019-04-01
- 6.0.0 — 2019-03-29

## README

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

# Indicative Parser
> Converts indicative rules and messages schema to a tree

[![circleci-image]][circleci-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url]

Indicative parser pre-compiles the Indicative schema to a recursive tree of nodes. Each node is given one of the following types.

- `object`: Node with one or more nested children.
- `array`: Node with one or more index or wildcard based nested children.
- `literal`: The leaf nodes.

Do note, that the `literal` **type is not equal to literal values in Javascript**. For parser, the literal nodes are nodes with no leaf.

<!-- 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

- [Why Indicative needs a parser?](#why-indicative-needs-a-parser)
- [Usage](#usage)

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

## Why Indicative needs a parser?
If you look at the Indicative schema, it is very concise and developer friendly. However, the same schema needs to be parsed to execute the validation rules.

```js
{
  username: 'required',
  'account.type': 'required|in:email,social'
}
```

One way is to loop over the schema object keys, split them by `.` and then inline execute the validations for each field. This process is very straight forward, but will have performance issues.

Instead, we parse the schema into a tree. The tree is later converted to an array of top level functions that are highly optimized for performance.

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

```sh
npm i indicative-parser

# yarn
yarn add indicative-parser
```

and then use it as follows:

```js
import { rulesParser } from 'indicative-parser'

rulesParser({
  username: 'required',
  'account.type': 'required|in:email,social'
})
```

Above code outputs the following tree.

```json
{
  "username": {
    "type": "literal",
    "rules": [
      {
        "name": "required",
        "args": []
      }
    ]
  },
  "account": {
    "rules": [],
    "type": "object",
    "children": {
      "type": {
        "type": "literal",
        "rules": [
          {
            "name": "required",
            "args": []
          },
          {
            "name": "in",
            "args": [
              "email",
              "social"
            ]
          }
        ]
      }
    }
  }
}
```

[circleci-image]: https://img.shields.io/circleci/project/github/poppinss/indicative-parser/master.svg?style=for-the-badge&logo=circleci
[circleci-url]: https://circleci.com/gh/poppinss/indicative-parser "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-parser.svg?style=for-the-badge&logo=npm
[npm-url]: https://npmjs.org/package/indicative-parser "npm"

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

---
_Source: https://npm.io/package/indicative-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
