ajv-pack-loader

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

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
ajv-pack-loader
2.2.07 years ago8 years agoMinified + gzip package size for ajv-pack-loader in KB

Readme

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

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