coerce<T, Input>(schema: Schema<T, Input>, coercer: Object): Object
schema: Schema<T, Input>
coercer: Object
import { x } from 'unhoax'import pipe from 'just-pipe' // or from elsewhereconst numberFromString = pipe( x.string, x.coerce(x.number, Number),)numberFromString.parse('42') // { success: true, value: 42 }numberFromString.parse(42) // { success: false, … } 42 is not a string Copy
import { x } from 'unhoax'import pipe from 'just-pipe' // or from elsewhereconst numberFromString = pipe( x.string, x.coerce(x.number, Number),)numberFromString.parse('42') // { success: true, value: 42 }numberFromString.parse(42) // { success: false, … } 42 is not a string
const coerceAsNumber = x.coerce(x.number, Number)const numberFromString = coerceAsNumber(x.string)numberFromString.parse('42') // { success: true, value: 42 } Copy
const coerceAsNumber = x.coerce(x.number, Number)const numberFromString = coerceAsNumber(x.string)numberFromString.parse('42') // { success: true, value: 42 }
Example: Building x.numberFromString
Example: not using pipe