BlueGit

blue-star danique-bot

Files

danique-bot / node_modules / pinkie / readme.md

readme.md

Import template
timfa Tim · pushed by timfa · 4 years ago
c788ad20 History
readme.md 2.6 KiB Download Raw

<h1 align="center">
pinkie

</h1>

> Itty bitty little widdle twinkie pinkie ES2015 Promise implementation

Build Status Coverage Status

There are tons of Promise implementations out there, but all of them focus on browser compatibility and are often bloated with functionality.

This module is an exact Promise specification polyfill (like native-promise-only), but in Node.js land (it should be browserify-able though).

Install

$ npm install --save pinkie

Usage

var fs = require('fs');
var Promise = require('pinkie');

new Promise(function (resolve, reject) {
	fs.readFile('foo.json', 'utf8', function (err, data) {
		if (err) {
			reject(err);
			return;
		}

		resolve(data);
	});
});
//=> Promise

API

pinkie exports bare ES2015 Promise implementation and polyfills Node.js rejection events. In case you forgot:

new Promise(executor)

Returns new instance of Promise.

executor

Required Type: function

Function with two arguments resolve and reject. The first argument fulfills the promise, the second argument rejects it.

pinkie.all(promises)

Returns a promise that resolves when all of the promises in the promises Array argument have resolved.

pinkie.race(promises)

Returns a promise that resolves or rejects as soon as one of the promises in the promises Array resolves or rejects, with the value or reason from that promise.

pinkie.reject(reason)

Returns a Promise object that is rejected with the given reason.

pinkie.resolve(value)

Returns a Promise object that is resolved with the given value. If the value is a thenable (i.e. has a then method), the returned promise will "follow" that thenable, adopting its eventual state; otherwise the returned promise will be fulfilled with the value.

Related

License

MIT © Vsevolod Strukchinsky

Source
1<h1 align="center">
2 <br>
3 <img width="256" src="media/logo.png" alt="pinkie">
4 <br>
5 <br>
6</h1>
7
8> Itty bitty little widdle twinkie pinkie [ES2015 Promise](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-objects) implementation
9
10[![Build Status](https://travis-ci.org/floatdrop/pinkie.svg?branch=master)](https://travis-ci.org/floatdrop/pinkie) [![Coverage Status](https://coveralls.io/repos/floatdrop/pinkie/badge.svg?branch=master&service=github)](https://coveralls.io/github/floatdrop/pinkie?branch=master)
11
12There are [tons of Promise implementations](https://github.com/promises-aplus/promises-spec/blob/master/implementations.md#standalone) out there, but all of them focus on browser compatibility and are often bloated with functionality.
13
14This module is an exact Promise specification polyfill (like [native-promise-only](https://github.com/getify/native-promise-only)), but in Node.js land (it should be browserify-able though).
15
16
17## Install
18
19```
20$ npm install --save pinkie
21```
22
23
24## Usage
25
26```js
27var fs = require('fs');
28var Promise = require('pinkie');
29
30new Promise(function (resolve, reject) {
31 fs.readFile('foo.json', 'utf8', function (err, data) {
32 if (err) {
33 reject(err);
34 return;
35 }
36
37 resolve(data);
38 });
39});
40//=> Promise
41```
42
43
44### API
45
46`pinkie` exports bare [ES2015 Promise](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-objects) implementation and polyfills [Node.js rejection events](https://nodejs.org/api/process.html#process_event_unhandledrejection). In case you forgot:
47
48#### new Promise(executor)
49
50Returns new instance of `Promise`.
51
52##### executor
53
54*Required*
55Type: `function`
56
57Function with two arguments `resolve` and `reject`. The first argument fulfills the promise, the second argument rejects it.
58
59#### pinkie.all(promises)
60
61Returns a promise that resolves when all of the promises in the `promises` Array argument have resolved.
62
63#### pinkie.race(promises)
64
65Returns a promise that resolves or rejects as soon as one of the promises in the `promises` Array resolves or rejects, with the value or reason from that promise.
66
67#### pinkie.reject(reason)
68
69Returns a Promise object that is rejected with the given `reason`.
70
71#### pinkie.resolve(value)
72
73Returns a Promise object that is resolved with the given `value`. If the `value` is a thenable (i.e. has a then method), the returned promise will "follow" that thenable, adopting its eventual state; otherwise the returned promise will be fulfilled with the `value`.
74
75
76## Related
77
78- [pinkie-promise](https://github.com/floatdrop/pinkie-promise) - Returns the native Promise or this module
79
80
81## License
82
83MIT © [Vsevolod Strukchinsky](http://github.com/floatdrop)