@exact-realty/ajv-pack-loader

3.0.1 • Public • Published

ajv-pack-loader

Build Status

This is a webpack loader for 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:

npm install ajv ajv-formats

Now you could install the loader:

npm install ajv-pack-loader

Usage example

Add a loader into your webpack config:

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

Import your schema in the project code:

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

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

Validate your data:

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.

console.log(validate.errors);

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @exact-realty/ajv-pack-loader

Weekly Downloads

0

Version

3.0.1

License

MIT

Unpacked Size

6.35 kB

Total Files

11

Last publish

Collaborators

  • er-ci-bot
  • corrideat