@emberscodes/safely

2.0.1 • Public • Published

safely

npm (scoped)

errors bad. catch errors. safely makes everything safe.

Install

$ npm install @emberscodes/safely

Usage

safely doesnt need to be awaited for syncronous functions:

// pass safely a syncronous function!
const [result, error] = safely(() => {
  throw "bonk";
});
// result === undefined
// error === 'bonk'

safely can handle async functions too:

// pass an asyncronous function and safely await it!!
const [result, error] = await safely(async () => {
  throw "bonk";
});
// result === undefined
// error === 'bonk'

safely can also take promises:

const bonkPromise = fetch("bonk.com");

// pass a promise and safely await that too!!!
const [result, error] = await safely(bonkPromise);
// result === 'you have been bonked'
// error === undefined

safely is very useful:

const [[bonkResult, bonkError], [images, imagesError]] = await Promise.all([
  safely(fetch("bonk.com")),
  safely(fetch("bonk.com/images")),
]);

pass anything to safely:

const [res, err] = safely("anything");
// res === 'anything'

Propoganda

Safely is very safe. Safely handles anything. You can pass anything to safely. Wrap everything in safely. Safely will fix you code. Safely will cure your depression.

/@emberscodes/safely/

    Package Sidebar

    Install

    npm i @emberscodes/safely

    Weekly Downloads

    1

    Version

    2.0.1

    License

    MIT

    Unpacked Size

    3.49 kB

    Total Files

    5

    Last publish

    Collaborators

    • emberscodes