- Source:
Methods
(static) allowedKeys(value) → {Array.<any>|null}
Checks whether value has only allowed properties
Parameters:
Name | Type | Description |
---|---|---|
value |
any |
accepts an object |
Returns:
returns ['shape.allowed.keys']
- Type
- Array.<any> | null
- Source:
Example
import { validators } from 'egoist-js'
const { shape } = validators
const isAllowedKeys = shape.allowedKeys(['prop1', 'prop2'])
console.log(isAllowedKeys(undefined)) // null
console.log(isAllowedKeys(null)) // null
console.log(isAllowedKeys({ prop1: 1, prop2: 1 })) // null
console.log(isAllowedKeys({ prop1: 1 })) // null
console.log(isAllowedKeys({ prop2: 1 })) // null
console.log(isAllowedKeys({})) // null
console.log(isAllowedKeys({ prop3: 1 })) // ['shape.allowed.keys', ['prop1', 'prop2']]
console.log(isAllowedKeys({ prop1: 1, prop3: 1})) // ['shape.allowed.keys', ['prop1', 'prop2']]
(static) expectKeys(value) → {Array.<any>|null}
Checks whether value has forbidden properties
Parameters:
Name | Type | Description |
---|---|---|
value |
any |
accepts an object |
Returns:
returns ['shape.expected.keys']
- Type
- Array.<any> | null
- Source:
Example
import { validators } from 'egoist-js'
const { shape } = validators
const isExpectedKeys = shape.expectKeys(['prop1', 'prop2'])
console.log(isExpectedKeys(undefined)) // null
console.log(isExpectedKeys(null)) // null
console.log(isExpectedKeys({ prop1: 1, prop2: 1 })) // null
console.log(isExpectedKeys({ prop1: 1 })) // ['shape.expected.keys', ['prop1', 'prop2']]
console.log(isExpectedKeys({ prop2: 1 })) // ['shape.expected.keys', ['prop1', 'prop2']]
console.log(isExpectedKeys({})) // ['shape.expected.keys', ['prop1', 'prop2']]
(static) forbiddenKeys(value) → {Array.<any>|null}
Checks whether value has forbidden properties
Parameters:
Name | Type | Description |
---|---|---|
value |
any |
accepts an object |
Returns:
returns ['shape.forbidden.keys']
- Type
- Array.<any> | null
- Source:
Example
import { validators } from 'egoist-js'
const { shape } = validators
const isForbiddenKeys = shape.forbiddenKeys(['prop1', 'prop2'])
console.log(isForbiddenKeys(undefined)) // null
console.log(isForbiddenKeys(null)) // null
console.log(isForbiddenKeys({ prop3: 1, prop4: 1 })) // null
console.log(isForbiddenKeys({ prop3: 1 })) // null
console.log(isForbiddenKeys({ prop5: 1 })) // null
console.log(isForbiddenKeys({})) // null
console.log(isForbiddenKeys({ prop1: 1 })) // ['shape.forbidden.keys', ['prop1', 'prop2']]
console.log(isForbiddenKeys({ prop1: 1, prop3: 1})) // ['shape.forbidden.keys', ['prop1', 'prop2']]
(static) isShape(value) → {Array.<any>|null}
Checks whether value is an object
Parameters:
Name | Type | Description |
---|---|---|
value |
any |
accepts any value |
Returns:
returns ['shape.type']
- Type
- Array.<any> | null
- Source:
Example
import { validators } from 'egoist-js'
const { shape } = validators
console.log(shape.isShape(undefined)) // null
console.log(shape.isShape(null)) // null
console.log(shape.isShape({ a: 1 })) // null
console.log(shape.isShape({})) // null
console.log(shape.isShape('5')) // ['shape.type']
console.log(shape.isShape([])) // ['shape.type']