1.4.1 • Published 5 years ago
@lavadrop/attempt v1.4.1
@lavadrop/attempt
Part of a library of zero-dependency npm modules that do just one thing.
- 100% TypeScript support.
- It's not a party without
Lavadrop
!
min + gzip | 126 bytes
Wraps func
in a try...catch
.
Usage
import attempt from '@lavadrop/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)?]