- Source:
Methods
(static) every(value) → {Array.<string>|null}
Checks whether each item of collection follows a predicate rule
Parameters:
Name | Type | Description |
---|---|---|
value |
any |
accepts an array of any type values |
Returns:
returns one item array with key ['array.every']
- Type
- Array.<string> | null
- Source:
Example
import { validators } from 'egoist-js'
const { array } = validators
const onlyNumbers = array.every(value => typeof(value === 'number'))
console.log(onlyNumbers(undefined)) // null
console.log(onlyNumbers(null)) // null
console.log(onlyNumbers([1, 2, 3, 4, 5])) // null
console.log(onlyNumbers(['1', '2', '3'])) // ['array.every']
console.log(onlyNumbers([1, 2, null, 4, 5])) // ['array.every']
(static) inRange(value) → {Array.<any>|null}
Checks whether an array contains desired number of items
Parameters:
Name | Type | Description |
---|---|---|
value |
any |
accepts an array of any type values |
Returns:
returns tuple ['array.range', [min_length, max_length]]
- Type
- Array.<any> | null
- Source:
Example
import { validators } from 'egoist-js'
const { array } = validators
const between5and10 = array.inRange([3, 5])
console.log(between5and10(undefined)) // null
console.log(between5and10(null)) // null
console.log(between5and10([1, 2, 3, 4, 5])) // null
console.log(between5and10([1, 2, 3, 4])) // null
console.log(between5and10([1, 2, 3])) // null
console.log(between5and10([1, 2, 3, 4, 5, 6])) // ['array.range', [3, 5]]
console.log(between5and10([1, 2])) // ['array.range', [3, 5]]
(static) isArray(value) → {Array.<string>|null}
Parameters:
Name | Type | Description |
---|---|---|
value |
any |
any possible value |
Returns:
returns one item array with key ['array.type']
- Type
- Array.<string> | null
- Source:
Example
import { validators } from 'egoist-js'
const { array } = validators
console.log(array.isArray(undefined)) // null
console.log(array.isArray(null)) // null
console.log(array.isArray([1, 2])) // null
console.log(array.isArray([])) // null
console.log(array.isArray(1)) // ['array.type']
(static) length(value) → {Array.<any>|null}
Checks whether an array has exact length
Parameters:
Name | Type | Description |
---|---|---|
value |
any |
accepts an array of any type values |
Returns:
returns tuple ['array.exact.length', length]
- Type
- Array.<any> | null
- Source:
Example
import { validators } from 'egoist-js'
const { array } = validators
const exlength3 = array.length(3)
console.log(exlength3(undefined)) // null
console.log(exlength3(null)) // null
console.log(exlength3([1, 2, 3])) // null
console.log(exlength3([1, 2, 3, 4, 5])) // ['array.exact.length', 3]
console.log(exlength3([1, 2])) // ['array.exact.length', 3]
(static) maxLength(value) → {Array.<any>|null}
Checks whether an array has at most defined number of items
Parameters:
Name | Type | Description |
---|---|---|
value |
any |
accepts an array of any type values |
Returns:
returns tuple ['array.max.length', max_length]
- Type
- Array.<any> | null
- Source:
Example
import { validators } from 'egoist-js'
const { array } = validators
const maxLength3 = array.maxLength(3)
console.log(maxLength3(undefined)) // null
console.log(maxLength3(null)) // null
console.log(maxLength3([1, 2, 3])) // null
console.log(maxLength3([1, 2, 3, 4, 5])) // ['array.max.length', 3]
console.log(maxLength3([1, 2, 3, 4])) // ['array.max.length', 3]
(static) minLength(value) → {Array.<any>|null}
Checks whether an array has at least defined number of items
Parameters:
Name | Type | Description |
---|---|---|
value |
any |
accepts an array of any type values |
Returns:
returns tuple ['array.min.length', min_length]
- Type
- Array.<any> | null
- Source:
Example
import { validators } from 'egoist-js'
const { array } = validators
const minLength3 = array.minLength(3)
console.log(minLength3(undefined)) // null
console.log(minLength3(null)) // null
console.log(minLength3([1, 2, 3, 4, 5])) // null
console.log(minLength3([1, 2, 3, 4])) // null
console.log(minLength3([1, 2, 3])) // null
console.log(minLength3([1, 2])) // ['array.min.length', 3]
(static) some(value) → {Array.<string>|null}
Checks whether at least one item of collection follows a predicate rule
Parameters:
Name | Type | Description |
---|---|---|
value |
any |
accepts an array of any type values |
Returns:
returns one item array with key ['array.some']
- Type
- Array.<string> | null
- Source:
Example
import { validators } from 'egoist-js'
const { array } = validators
const hasEvenValue = array.some(value => value % 2 === 0)
console.log(hasEvenValue(undefined)) // null
console.log(hasEvenValue(null)) // null
console.log(hasEvenValue([1, 2, 3])) // null
console.log(hasEvenValue([1, 3])) // ['array.some']