JSPM

@queso/attempt

1.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q27921F
  • License MIT

Wraps func in a try...catch.

Package Exports

  • @queso/attempt

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@queso/attempt) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@queso/attempt

npm license Travis Build Status codecov Try @queso/attempt on RunKit

Part of a library of zero-dependency npm modules that do just one thing.

npm

min + gzip | 126 bytes

source

Wraps func in a try...catch.

Usage

import attempt from '@queso/attempt'

function exclaim(message: string) {
return message + '!'
}
attempt(exclaim)('hi')

Parameters

Name Type Description
func TFunc The function to wrap.

Type parameters

Name Constraint Default
TFunc (...args: any[]) => any
TReason Error

Returns

A new wrapper function that, when called, returns a tuple of [err, success].

Return type

<TReason = Error>(
    ...args: Parameters<TFunc>
) => [TReason | null, (ReturnType<TFunc> | undefined)?]