@queso/attempt
v1.2.0
Published
Wraps func in a try...catch.
Downloads
7
Maintainers
Readme
@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)?]