# ajv-error-tree

> Convert a list of [ajv](https://www.npmjs.com/package/ajv) errors into the logical tree it was always meant to be.

Latest version **0.0.5** (published 2021-08-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install ajv-error-tree
pnpm add ajv-error-tree
yarn add ajv-error-tree
bun add ajv-error-tree
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2021-08-12 |
| First published | 2021-06-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | lachrist |

## Links

- npm: https://www.npmjs.com/package/ajv-error-tree
- Repository: https://github.com/lachrist/ajv-error-tree
- Homepage: https://github.com/lachrist/ajv-error-tree#readme
- Issues: https://github.com/lachrist/ajv-error-tree/issues
- npm.io page: https://npm.io/package/ajv-error-tree

## Recent versions

- 0.0.5 (latest) — 2021-08-12
- 0.0.4 — 2021-08-09
- 0.0.3 — 2021-06-14
- 0.0.2 — 2021-06-13
- 0.0.1 — 2021-06-13
- 0.0.0 — 2021-06-13

## README

# ajv-error-tree

Convert a list of [ajv](https://www.npmjs.com/package/ajv) errors into the logical tree it was always meant to be.

Requirement: `ajv@8.x.x`.

Example:

```js
const Ajv = require("ajv");
const YAML = require("yaml");
const { asTree } = require("treeify");
const {
  structureAJVErrorArray,
  summarizeAJVErrorTree,
} = require("ajv-error-tree");
const ajv = new Ajv({ verbose: true });
const validate = ajv.compile({
  type: "array",
  items: {
    anyOf: [
      {type: "number"},
      {type: "boolean"}
    ]
  }
});
console.assert(!validate([123, true, "foo"]));
const tree1 = structureAJVErrorArray(validate.errors);
const tree2 = summarizeAJVErrorTree(tree1);
console.log(asTree(tree2, true));
// ├─ .: /items/anyOf >> /2 must match a schema in anyOf
// └─ +
//    ├─ 0: /items/anyOf/0/type >> /2 must be number
//    └─ 1: /items/anyOf/1/type >> /2 must be boolean
```

See [sample](test/sample.js) for another example.

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