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