- Source:
Methods
(static) allow(value) → {Array.<any>|null}
Checks whether value is related to one of expected values
Parameters:
Name | Type | Description |
---|---|---|
value |
any |
any possible value |
Returns:
returns tuple ['any.allow', [...allowedValues]]
- Type
- Array.<any> | null
- Source:
Example
import { validators } from 'egoist-js'
const { any } = validators
const isHelloOrWorld = any.allow(['hello', 'world'])
console.log(isHelloOrWorld(undefined)) // null
console.log(isHelloOrWorld(null)) // null
console.log(isHelloOrWorld('hello')) // null
console.log(isHelloOrWorld('world')) // null
console.log(isHelloOrWorld('cosmic')) // ['any.allow', ['hello', 'world']]
(static) required(value) → {Array.<string>|null}
Checks whether value is null/undefined
Parameters:
Name | Type | Description |
---|---|---|
value |
any |
any possible value |
Returns:
returns one item array with key ['any.required']
- Type
- Array.<string> | null
- Source: