@replygirl/tc
TypeScript icon, indicating that this package has built-in type declarations

4.0.2 • Public • Published

tc

node-current (scoped) GitHub top language Libraries.io dependency status for latest release, scoped npm package Maintainability Test Coverage GitHub issues GitHub pull requests

destructurable, async-friendly try...catch wrapper function with support for error side effects and fallback values

Installation & usage

See the docs for full details.

import tc from '@replygirl/tc'

// get the return value and error of a try callback
const [x, e] = tc(() => { /* ... */ })

// or put complex error handling in a catch callback
const [y] = await tc(doSomething, async e => {
  await reportError(e)
  return getFallbackValue(e)
})

// reuse your error handling by defining your own wrapper
const tce = (t, c) => tc(t, async e => {
  await reportError(e)
  return c(e)
})
const [z] = tce(doSomething, getFallbackValue)

ISC License | Copyright © 2020–present replygirl

Package Sidebar

Install

npm i @replygirl/tc

Weekly Downloads

10

Version

4.0.2

License

ISC

Unpacked Size

18.4 kB

Total Files

12

Last publish

Collaborators

  • imogen