Function
Static Public Summary | ||
public |
Convenience function that returns a function that validates strict equality. |
|
public |
Generates a function that checks each value matches the validators passed, |
|
public |
Generates a function that checks that each element of a List matches at least |
|
public |
Creates a validator function based on passed validator 2-tuples. |
|
public |
Convenience function that returns a function that validates strict membership |
Static Public
public Exactly(value: *): function source
import {Exactly} from 'immutable-schema/src/index.js'
Convenience function that returns a function that validates strict equality.
Params:
Name | Type | Attribute | Description |
value | * | value to test equality |
Example:
var isExactly = Exactly('3');
isExactly('hi'); // false
isExactly(3); // false
isExactly('3'); // true
public FixedListSchema(): function source
import {FixedListSchema} from 'immutable-schema/src/index.js'
Generates a function that checks each value matches the validators passed, respective per index.
Params:
Name | Type | Attribute | Description |
...validators | function | functions, in order, to check each value in the passed list |
Example:
var schema = FixedListSchema(Exactly('roar'), isNumber);
schema(List.of(3)); // false
schema(List.of('roar')); // false
schema(List.of('fake roar')); // false
schema(List.of('roar', 15)); // true
public ListSchema(): function source
import {ListSchema} from 'immutable-schema/src/index.js'
Generates a function that checks that each element of a List matches at least one of the passed validators.
Params:
Name | Type | Attribute | Description |
...validators | function | functions to check each value in the passed list |
Example:
var schema = ListSchema(Exactly('roar'), isNumber);
schema(List.of(3)); // true
schema(List.of('roar')); // true
schema(List.of(3, 'fake roar')); // false
public MapSchema(): function source
import {MapSchema} from 'immutable-schema/src/index.js'
Creates a validator function based on passed validator 2-tuples.
Key-value entries in the map must satisfy at least one of the validator tuples.
TODO: Optional and required key/values
Params:
Name | Type | Attribute | Description |
...validators | function | functions in pairs to match with each key-value pair |
Example:
var isValid = MapSchema(isNumber, Exactly('hi'), isString, isNumber);
isValid(Map().set(5, 'hi')); // true
isValid(Map().set('hi', 'hi')); // false
isValid(Map().set(5, 'hi').set('foo', 3)); // true
public OneOf(): function source
import {OneOf} from 'immutable-schema/src/index.js'
Convenience function that returns a function that validates strict membership in passed arguments.
Params:
Name | Type | Attribute | Description |
...values | * | collection of values to test membership upon |
Example:
var membership = OneOf('hi', '3', 19);
membership('hi'); // true
membership(3); // false
membership('not in there'); // false
membership(19); // true