1.1.1 • Published 5 years ago

safe-func-safe-prom v1.1.1

Weekly downloads
1
License
MIT
Repository
gitlab
Last release
5 years ago

safe-func-safe-prom


This module quickly turned into tri-fp which is the active library for this functionality. You can:

import { tri as safe, triP as safeP } from "tri-fp";

...if you like the names in this module.


  • Make both functions and promises more functional by removing the need for try-catch.
  • Handle application errors and native exceptions differently.

Wrap a function in safe, or a promise in safeP, to transform all outcomes except native exceptions into an error-first pair. Don't use try-catch or .catch.

import { safe, safeP } from "safe-func-safe-prom";

// Sync
const [error, result] = safe(myFunction)(arg1, arg2);

// Async, direct promise
const [error, result] = await safeP(myPromise);

// Async, promise returning function
const [error, result] = await safeP(myPromiseReturningFunc)(arg1, arg2);

// Native errors/exceptions will still throw. Don't catch these; Find your bug.

Motivation

Inspired by / Thanks to

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago