A simple Node.js package that helps you not to look up JavaScript promise syntax every time you use it.

Overview

cover


A simple Node.js package that helps you not to look up JavaScript promise syntax every time you use it.

separator

  • Simple: Provides abstraction of the promise syntax from you
  • Easy to use: No need to learn JavaScript promise syntax
  • Promise: Turns any function into a promis
  • All promises: Provides a way to chain all promises and returns the result collectively
  • Any promise: Takes array of promise and returns a promise that resolves when any of the promise is resolved
  • All settled promises: Takes array of promise and returns a promise that resolves when all promises are settled

Install

# install the package
npm install @msaaddev/promise-it

API

promiseIt()

Promisify a callback function

promiseItAll()

Creates a Promise that is resolved with an array of results when all of the provided Promises resolve, or rejected when any Promise is rejected.

promiseItAny()

Promisify any of the given callback functions

promiseItAllSettled()

Creates a Promise that is resolved with an array of results when all of the provided Promises resolve or reject.


Usage

  • promiseIt()
const { promiseIt } = require('@msaaddev/promise-it');

(async () => {
	const callback = (resolve, reject) => {
		exec(`networkQuality`, error => {
			if (error) {
				handleError(error);
				reject(error);
			}
			resolve('All good. Ran networkQuality.');
		});
	};

	try {
		const promise = await promiseIt(callback);
		console.log(promise);
	} catch (err) {
		console.log(err);
	}
})();
  • promiseItAll()
const { promiseItAll } = require('@msaaddev/promise-it');
const { exec } = require('child_process');

(async () => {
	const callback = (resolve, reject) => {
		exec(`networkQuality`, error => {
			if (error) {
				handleError(error);
				reject(error);
			}
			resolve('All good. Ran networkQuality.');
		});
	};

	const callback2 = (resolve, reject) => {
		exec(`networkQuality -v`, error => {
			if (error) {
				reject(error);
			}
			resolve('All good. Ran networkQuality -v.');
		});
	};

	try {
		const allPromises = await promiseItAll(callback, callback2);
		console.log(allPromises);
	} catch (err) {
		console.log(err);
	}
})();
  • promiseItAny()
const { promiseItAny } = require('@msaaddev/promise-it');
const { exec } = require('child_process');

(async () => {
	const callback = (resolve, reject) => {
		exec(`networkQuality`, error => {
			if (error) {
				handleError(error);
				reject(error);
			}
			resolve('All good. Ran networkQuality.');
		});
	};

	const callback2 = (resolve, reject) => {
		exec(`networkQuality -v`, error => {
			if (error) {
				reject(error);
			}
			resolve('All good. Ran networkQuality -v.');
		});
	};

	try {
		const anyPromise = await promiseItAny(callback, callback2);
		console.log(anyPromise);
	} catch (err) {
		console.log(err);
	}
})();
  • promiseItAllSettled()
const { promiseItAllSettled } = require('@msaaddev/promise-it');
const { exec } = require('child_process');

const { promiseIt, promiseItAll, promiseItAny } = require('./index');
const { exec } = require('child_process');

(async () => {
	const callback = (resolve, reject) => {
		exec(`networkQuality`, error => {
			if (error) {
				handleError(error);
				reject(error);
			}
			resolve('All good. Ran networkQuality.');
		});
	};

	const callback2 = (resolve, reject) => {
		exec(`networkQuality -v`, error => {
			if (error) {
				reject(error);
			}
			resolve('All good. Ran networkQuality -v.');
		});
	};

	try {
		const allSettledPromise = await promiseItAllSettled(
			callback,
			callback2
		);
		console.log(allSettledPromise);
	} catch (err) {
		console.log(err);
	}
})();

πŸ‘¨πŸ»β€πŸ’» Contributing

Make sure you read the contributing guidelines before opening a PR.

⚑️ Other Projects

I have curated a detailed list of all the open-source projects I have authored. Do take out a moment and take a look.

πŸ”‘ License & Conduct

You might also like...

🧩 TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types such as number or boolean (not Value Objects)

🧩 TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types such as number or boolean (not Value Objects)

🧩 TypeScript Primitives type TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types

Dec 7, 2022

375 DSA Tracker helps you build your confidence in solving any coding related question and helps you prepare for your placements. It is your personal web-based progress tracker based on 375 DSA Sheet by Aman Dhattarwal & Shradha Didi

375 DSA Tracker helps you build your confidence in solving any coding related question and helps you prepare for your placements. It is your personal web-based progress tracker based on 375 DSA Sheet by Aman Dhattarwal & Shradha Didi

375-DSA Tracker πŸ‘¨β€πŸ’» Me and my friend Abhilash Jena made a 375 DSA Tracker website based on 375 DSA Sheet by Aman Dhattarwal & Shradha Didi which hel

Nov 11, 2022

Check your data which may be stolen every time you visit a site. ⚠️

Check your data which may be stolen every time you visit a site. ⚠️

df : Digital Fingerprint πŸͺ„ Features Check your data which may be stolen every time you visit a site. 🌎 Geographical Data IP Address City Region Coun

Oct 17, 2022

Javascript client for Sanity. Works in node.js and modern browsers (older browsers needs a Promise polyfill).

@sanity/client Javascript client for Sanity. Works in node.js and modern browsers (older browsers needs a Promise polyfill). Requirements Sanity Clien

Nov 29, 2022

Get a desktop notification every time a new correction slot is available for your 42 project.

42_slot_watcher A simple node.js corrections slots watcher for 42, working on Windows - MacOS - Linux. What is this I was bored of having to refresh t

Dec 20, 2022

Promise based HTTP client for the browser and node.js

axios Promise based HTTP client for the browser and node.js New axios docs website: click here Table of Contents Features Browser Support Installing E

Jan 5, 2023

A set of small, responsive CSS modules that you can use in every web project.

A set of small, responsive CSS modules that you can use in every web project.

Pure A set of small, responsive CSS modules that you can use in every web project. https://purecss.io/ This project is looking for maintainers to supp

Jan 9, 2023

A simple Node.js code to get unlimited instagram public pictures by every user without api, without credentials.

A simple Node.js code to get unlimited instagram public pictures by every user without api, without credentials.

Instagram Without APIs Instagram Scraping in August 2022, no credentials required This is a Node.js library, are you looking for the same in PHP? go t

Dec 29, 2022
Releases(0.1.1)
  • 0.1.1(May 21, 2022)

    • Promisify a callback function
    • Provides a simple way to create a Promise that is resolved with an array of results when all of the provided Promises resolve or rejected when any Promise is rejected.
    • Promisify any of the given callback functions
    • Provides a way to create a Promise that is resolved with an array of results when all of the provided Promises resolve or reject.
    Source code(tar.gz)
    Source code(zip)
Owner
Saad Irfan ⚑️
Turning ideas into code...
Saad Irfan ⚑️
Inside-out promise; lets you call resolve and reject from outside the Promise constructor function.

Inside-out promise; lets you call resolve and reject from outside the Promise constructor function.

Lily Scott 3 Feb 28, 2022
Adds promise support (rejects(), doesNotReject()) to tape by decorating it using tape-promise.

Tape With Promises Adds promise support (rejects(), doesNotReject()) to tape by decorating it using tape-promise. Install npm install --save-dev @smal

Small Technology Foundation 3 Mar 21, 2022
JOSE ZEPEDA 10 Nov 18, 2022
This is a website for creating to-do tasks. "To-do list" is a tool that helps to organize your day. The main objective is to understand how to use proper ES6 syntax.

TO DO LIST To Do List This is a website for creating to-do tasks. "To-do list" is a tool that helps to organize your day. This project is part of the

Aleksandra Ujvari 2 Oct 3, 2022
Remix enables you to build fantastic user experiences for the web and feel happy with the code that got you there. In this workshop, we'll look at some more advanced use cases when building Remix applications.

?? Advanced Remix Workshop Remix enables you to build fantastic user experiences for the web and feel happy with the code that got you there. In this

Frontend Masters 167 Dec 9, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de crΓ©er un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
A "Basic-to-Lisp" compiler. But Basic is not real Basic, and Lisp is not real Lisp.

Basic2Lisp A "Basic-to-Lisp" compiler. But Basic is not real Basic, and Lisp is not real Lisp. Syntax Print-Sth Put some-value to standard output. PRI

Hana Yabuki 5 Jul 10, 2022