promiseful

0.1.3 • Public • Published

promiseful

Useful patterns with Promise functions

NPM version Build Status Known Vulnerabilities

Installation

$ npm install promiseful --save

To use in the browser, download the library from dist folder.

Usage

node.js

promiseful uses native ES2015 Promise.

To use non-native, 3rd-party Promise libraries, like bluebird or Promise polyfill, call promiseful.promise() with the Promise object, before using the API.

e.g.:

var Promise = require('bluebird');
// var Promise = require('es6-promise');
// var Promise = require('pinkie-promise');
 
var promiseful = require('promiseful');
 
promiseful.promise(Promise);

See example

Browser

promiseful uses native ES2015 Promise.

To use non-native, 3rd-party Promise libraries, like bluebird or Promise polyfill, include the library, before including promiseful.

e.g.:

<script src="https://cdn.jsdelivr.net/bluebird/latest/bluebird.min.js"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.0/es6-promise.min.js"></script> -->
<script src="promiseful.js"></script>

See example

API

A promiseful function is a function that returns a Promise.

e.g.:

function readPasswd() {
  return new Promise((resolve, reject) => {
    fs.readFile('/etc/passwd', (err, data) => {
      if (err) {
        reject(err);
      } else {
        resolve(data);
      }
    });
  });
}

The API works with promiseful functions. Do not pass Promise objects.

Methods follow pattern, similar to the excellent caolan/async library.

API Documentation

API

Examples

Node.js

  1. server-time
  2. es5

Browser

  1. fetch-image-dimension
  2. bluebird

License

MIT

Dependents (0)

Package Sidebar

Install

npm i promiseful

Weekly Downloads

3

Version

0.1.3

License

MIT

Last publish

Collaborators

  • palanik