Home Identifier Source Repository

Function

Static Public Summary
public

Exactly(value: *): function

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:

NameTypeAttributeDescription
value *

value to test equality

Return:

function

evaluates strict equality of passed value

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:

NameTypeAttributeDescription
...validators function

functions, in order, to check each value in the passed list

Return:

function

which returns true if each element in list matches in order

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:

NameTypeAttributeDescription
...validators function

functions to check each value in the passed list

Return:

function

which returns true if each element in list matches at least one validator

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:

NameTypeAttributeDescription
...validators function

functions in pairs to match with each key-value pair

Return:

function

function returns true if passed a valid Map

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:

NameTypeAttributeDescription
...values *

collection of values to test membership upon

Return:

function

evaluates membership of passed value

Example:

var membership = OneOf('hi', '3', 19);

membership('hi');  // true
membership(3);  // false
membership('not in there');  // false
membership(19);  // true