1.2.0 • Published 6 years ago
@queso/attempt v1.2.0
@queso/attempt
Part of a library of zero-dependency npm modules that do just one thing.
- 100% TypeScript support.
- It's not a party without
Queso!
min + gzip | 126 bytes
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)?]