Search


Search something to see results

recover

Allows to never fail from parsing an input by providing a lazy fallback.

Type Parameters

  • U

Parameters

  • getFallback: Object

Returns Object

fallback for usage without callback

import { x } from 'unhoax'
import pipe from 'just-pipe' // or from elsewhere

const schema = pipe(x.number, x.recover(() => 'not a number'))

schema.parse(42) // { success: true, value: 42 }
schema.parse('toto') // { success: true, value: 'not a number' }
import { x } from 'unhoax'

const recoverFromNaN = x.recover(() => 'not a number')
const schema = recoverFromNaN(x.number)