1.0.0 • Published 7 years ago

vtypes-immutable v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

vtypes-immutable

"immutable" validator for validate.js

npm package vtypes

About

The immutable validator attempts to ensure that the field is a valid immutable value. The API for checking immutability is referenced off immutable.js.

If no parser is provided, then best effort guess if a value is immutable based on availability of conversion functions like toJS, toJSON, toArray, toObject;

Installation

$ npm install vtypes-immutable
const validate = require('validate.js');
const vImmutable = require('vtypes-immutable');

// you can then proceed to register the required validators.
validate.validators.immutable = vImmutable;

Usage

const Immutable = require('immutable');

validate({}, {attr: {immutable: true}});
// => undefined

validate({attr: 'foo'}, {attr: {immutable: true}});
// => {attr: ["Attr is not an immutable value"]}
// note: both "type" and "library" must be preset.
const constraints = {
  attr: {
    immutable: {
      library: Immutable,
      type: 'List'
    }
  }
}

validate({attr: 'foo'}, constraints);
// => {attr: ["Attr is not an immutable List"]}

For more examples, check out the test files in this package's source folder.

Available Options

nametypedefaultdescription
libraryfuncundefinedThe immutable library
messagestringis not an immutable %{type}Error message
typestringundefinedA type that is accepted by immutable library

License

vtypes-immutable is MIT licensed