tcts
v0.0.16
Published
🤿 functional try ... catch implementation
Downloads
10
Readme
tcts 🤿
Dead simple, functional, curriable try ... catch implementation.
Install
npm i tcts
Usage
TC - Try catch
import { tc } from 'tcts'
const [error, value] = tc(() => {
// errorable code
return value
})
// use atc for an async try catch
atc(async () => ..)
TCF - Try catch fallback
import { tcf } from 'tcts'
const safeParseNum = tcf(0, parseNum)
// partial application to reuse
const tcNumber = tcf(0)
const tcAction = tcf({ error: true })
Safely access deeply nested objects using tcf
const translation = tcf("No translation", (t) => t.a.b.c)(translations)
TCF helpers
// other helpers
import { tcNull, tcNullish, tcNumber, tcRetry } from 'tcts'
tcNull(fn) // tcf(null, fn)
tcNullish(fn) // tcf(undefined, fn)
tcNumber(fn) // tcf(0, fn)
tcRetry(fn) // tcf(fn, fn)