Array
Path:
/src/type/array.coffee
compiled to/lib/type/array.js
A list of something.
Sanitize options:
delimiter
- allow value text with specified list separator (it can also be an regular expression)
Check options:
notEmpty
- set to true if an empty array is not validminLength
- minimum number of entriesmaxLength
- maximum number of entriestoArray
- convert scalar values into array
Validating children:
entries
- specification for all entries or as array for each element
Formatting options:
-
shuffle
- set to true to shuffle elements on validation -
format
- one of ‘simple’, ‘pretty’, ‘json’data = [1, 2, 3, 'a', {b: 1}, ['c', 9]] # simple -> "1, 2, 3, a, [object Object], c,9" # pretty -> "1, 2, 3, 'a', { b: 1 }, [ 'c', 9 ]" # json -> '[1,2,3,"a",{"b":1},["c",9]]'
Schema Specification
Array is the array schema definitions.
An object with the following keys allowed: delimiter
, toArray
, unique
, notEmpty
, minLength
, maxLength
, list
, entries
, shuffle
, format
, title
, description
, key
, type
, optional
, default
. The following entries have a specific format:
delimiter
-
Delimiter is the delimiter to split given string into list.
It has to be one of the following types (optional):
-
Characters are the characters to be used as explicit delimiter.
A text entry in which all control characters will be removed.
-
RegExp is the expression to split into list.
An object which has to be an instance of class
RegExp
.
-
toArray
-
To Array is a flag to automatically pack other data into an array.
A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.
unique
-
Unique is a flag to remove duplicate entries in list.
A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.
notEmpty
-
Not Empty is a flag to not allow an empty list.
A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.
minLength
-
Minimum is the minimum number of elements in list.
An integer value which is optional. The value should be greater than 0.
maxLength
-
Maximum is the maximum number of elements in list.
An integer value which is optional. The value should be greater than <<
>>. list
-
Specific Formats are the schema for each element.
A list which is optional. Each entry has to be of type object:
Element Format is the schema definition for a specific element.
An object with the following keys have to be present:
type
. entries
-
Element Format is the general schema definition for the entries.
An object which is optional. The following keys have to be present:
type
. shuffle
-
Shuffle is the list will be shuffled to get a random order.
A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.
format
-
Format is the type of output format to use.
A text entry which is optional. All control characters will be removed. Only the values: ‘simple’, ‘pretty’, ‘json’ are allowed.
title
-
Title is the title used to describe the element.
A text entry which is optional. All control characters will be removed.
description
-
Description is the free description of the element.
A text entry which is optional. All control characters will be removed.
key
-
Binding to Keyname is the mapping to which key names in an object this element belongs.
A valid regular expression which is optional. It has to be one of the following types:
- An object which has to be an instance of class
RegExp
. - A text entry in which all control characters will be removed. The text should match: /^/.?/[gim]$/.
- An object which has to be an instance of class
type
-
Type is the type of element.
A text entry in which all control characters will be removed.
optional
-
Optional is a flag defining if this element is optional.
A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.
default
-
Default Value is the default value to use if nothing given.
A list which is optional.