JSPM

  • Created
  • Published
  • Downloads 61987
  • Score
    100M100P100Q150778F
  • License MIT

dynamic json-schema validator

Package Exports

  • djv

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (djv) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Build Status Join the chat at https://gitter.im/korzio/djv

djv

Dynamic Json Schema Validator

This package contains json-schema utility for validating objects across schemas. This is a part of djv packages aimed to work with json-schema.

Installation

npm install djv

Usage

var env = new djv();
var jsonSchema = {
    "common": {
        "properties": {
            "type": {
                "enum": ["common"]
            }
        },
        "required": [
            "type"
        ]
    }
};

// Use `addSchema` to add json schema
env.addSchema('test', jsonSchema);
env.validate('test#/common', { type: 'common' });
// => undefined

env.validate('test#/common', { type: 'custom' });
// => 'required: data'

API

validate(name, object)

check if object corresponds to schema

Examples:

env.validate('test#/common', { type: 'common' });
// => undefined

env.validate('test#/common', { type: 'custom' });
// => 'required: data'

Params:

  • String name
  • Object object

Return:

  • String error - undefined if it is valid

addSchema(name, schema)

add schema to djv environment

Examples:

env.addSchema('test', jsonSchema);

Params:

  • String name
  • Object schema

Return:

  • resolved

removeSchema(name)

removes a schema or the whole structure from djv environment

Examples:

env.removeSchema('test');

Params:

  • String name

resolve(name)

resolves name by existing environment

Examples:

env.resolve('test');
// => { name: 'test', schema: {} }, fn: ... }

Params:

  • String name

Return:

  • resolved

export(name)

exports the whole structure object from environment or by resolved name

Examples:

env.export();
// => { test: { name: 'test', schema: {}, ... } }

Params:

  • String name

Return:

  • serializedInternalState

import(config)

imports all found structure objects to internal environment structure

Examples:

env.import(config);

Params:

  • Object config - internal structure or only resolved schema object

Tests

npm test

Resources