UNPKG

@piyawasin/attempt

Version:

A minimal, type-safe utility for defensive error handling in JS/TS. Inspired by Go, it uses tuple-based returns to eliminate try-catch nesting and handle synchronous/asynchronous errors predictably.

17 lines (16 loc) 393 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.attempt = void 0; function attempt(func) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } try { return [func.apply(void 0, args), null]; } catch (error) { return [null, error]; } } exports.attempt = attempt;