1.2.0 • Published 5 years ago

@queso/attempt v1.2.0

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

@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

NameTypeDescription
funcTFuncThe function to wrap.

Type parameters

NameConstraintDefault
TFunc(...args: any[]) => any
TReasonError

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)?]