vtypes-immutable
"immutable" validator for validate.js
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 = ;const vImmutable = ; // you can then proceed to register the required validators.validatevalidatorsimmutable = vImmutable;
Usage
const Immutable = ; ;// => undefined ;// => {attr: ["Attr is not an immutable value"]}
// note: both "type" and "library" must be preset.const constraints = attr: immutable: library: Immutable type: 'List' ;// => {attr: ["Attr is not an immutable List"]}
For more examples, check out the test files in this package's source folder.
Available Options
name | type | default | description |
---|---|---|---|
library | func | undefined |
The immutable library |
message | string | is not an immutable %{type} |
Error message |
type | string | undefined |
A type that is accepted by immutable library |
License
vtypes-immutable
is MIT licensed