import { check } from '@traversable/json-schema-types'
const myCheck = check({ type: 'boolean' })
console.log(myCheck(false)) // => true
console.log(myCheck('true')) // => false
const myTypeGuard = check({ type: 'boolean' }, { asTypeGuard: true })
declare const input: unknown
if (myTypeGuard(input)) {
input
// ^? const input: boolean
}
JsonSchema.check
Given a JSON Schema spec, returns a predicate function that accepts any input and returns a boolean indicating whether the input satisfied the spec.
Note:
JsonSchema.check
has better performance than JsonSchema.check.writeable
See also:
import { check } from '@traversable/json-schema-types'
const myCheck = check({ type: 'boolean' })
console.log(myCheck(false)) // => true
console.log(myCheck('true')) // => false
const myTypeGuard = check({ type: 'boolean' }, { asTypeGuard: true })
declare const input: unknown
if (myTypeGuard(input)) {
input
// ^? const input: boolean
}
JsonSchema.check
Given a JSON Schema spec, returns a predicate function that accepts any input and returns a boolean indicating whether the input satisfied the spec.
Note:
JsonSchema.check
has better performance thanJsonSchema.check.writeable
See also:
JsonSchema.check.classic
JsonSchema.check.writeable