# ajv-pack-loader

> ajv-pack-loader ---------------

Latest version **2.2.0** (published 2017-07-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install ajv-pack-loader
pnpm add ajv-pack-loader
yarn add ajv-pack-loader
bun add ajv-pack-loader
```

## 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 | 2.2.0 |
| Published | 2017-07-13 |
| First published | 2016-11-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | corpix |

## Links

- npm: https://www.npmjs.com/package/ajv-pack-loader
- npm.io page: https://npm.io/package/ajv-pack-loader

## Dependencies (3)

- [ajv](https://npm.io/package/ajv.md) ^5.2.2
- [ajv-pack](https://npm.io/package/ajv-pack.md) ^0.3.0
- [loader-utils](https://npm.io/package/loader-utils.md) ^1.1.0

## Recent versions

- 2.2.0 (latest) — 2017-07-13
- 2.1.0 — 2017-07-13
- 2.0.0 — 2017-04-10
- 1.0.1 — 2016-11-23
- 1.0.0 — 2016-11-23

## README

ajv-pack-loader
---------------

[![Build Status](https://travis-ci.org/corpix/ajv-pack-loader.svg?branch=master)](https://travis-ci.org/corpix/ajv-pack-loader)

This is a webpack loader for [ajv-pack](https://github.com/epoberezkin/ajv-pack) that converts a JSON schema into JavaScript validation function.

# Installation

We depend on two npm packages as `peerDependencies`, so you should install them first:

``` shell
npm install ajv ajv-pack
```

Now you could install the loader:

``` shell
npm install ajv-pack-loader
```

# Usage example

Add a loader into your webpack config:

``` javascript
{
    loaders: [
        {
            test: /\.?schema.json$/,
            loader: 'ajv-pack-loader'
        }
    ]
}
```

Import your schema in the project code:

``` javascript
import validate from 'app/external/microformats/schema.json';
```

> Signature of a validate function is `validate(data, dataPath, parentData, parentDataProperty, rootData)`

Validate your data:

``` javascript
validate(
    {
        user: {
            name: 'John',
            surname: 'Doe'
        }
    }
); // true || false
```

Access validation errors:

> This is a bit strange, but `.errors` attribute will become available after `validate(...)` invocation.

``` javascript
console.log(validate.errors);
```

# License

[MIT](/LICENSE)

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