Socket
Socket
Sign inDemoInstall

promise-disarm

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    promise-disarm

Utilities for making promises return errors instead of throwing them


Version published
Weekly downloads
5
Maintainers
1
Install size
2.90 kB
Created
Weekly downloads
 

Readme

Source

promise-disarm :bomb:

Build Status

Utilities for making promises return errors instead of throwing them... and just like disarming actual bombs THIS IS POTENTIALLY UNSAFE, BE WARNED. Make sure you actually handle the errors somehow.

If the provided promise does not reject, it will just resolve as usual. If anything other than a promise is provided, it will return a promise that resolve to whatever was provided.

Usage example

import { disarm, disarmAll } from 'promise-disarm';

const promise = new Promise(_, reject) => reject(new Error())

// for a single promise...
disarm(promise).then(result => {
  // a "cold" error, not thrown. Make sure you handle it.
  console.log(result instanceof Error); // true
});

// for an array of promises... just like Promise.all
// except it does not fail after a single promise rejects
// NOTE: this function itself may throw if argument is not an array
disarmAll([promise, promise]).then(result => {
  // an array of either values or errors
  console.log(result.every(item => item instanceof Error));
});

Development scripts

  • build: transpiles and minifies all code in ./src into ./lib using babel;
  • lint: lints code in ./src using eslint;
  • precommit: (automatic) runs linter before every commit;
  • prepublish: (automatic) runs tests before attempting to publish the package;
  • test: runs tests in __tests__ using jest.

Note: scripts assume you use yarn, because you should ;)

Forked from vspedr/jables

Prueba de bomba, prueba de bala - Kontrust

Keywords

FAQs

Last updated on 08 Aug 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc