1 |
3a515b92
|
cagy
|
# p-is-promise [![Build Status](https://travis-ci.org/sindresorhus/p-is-promise.svg?branch=master)](https://travis-ci.org/sindresorhus/p-is-promise)
|
2 |
|
|
|
3 |
|
|
> Check if something is a promise
|
4 |
|
|
|
5 |
|
|
Why not [`is-promise`](https://github.com/then/is-promise)? That module [checks for a thenable](https://github.com/then/is-promise/issues/6), not an ES2015 promise. This one is stricter.
|
6 |
|
|
|
7 |
|
|
You most likely don't need this. Just pass your value to `Promise.resolve()` and let it handle it.
|
8 |
|
|
|
9 |
|
|
Can be useful if you need to create a fast path for a synchronous operation.
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
## Install
|
13 |
|
|
|
14 |
|
|
```
|
15 |
|
|
$ npm install p-is-promise
|
16 |
|
|
```
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
## Usage
|
20 |
|
|
|
21 |
|
|
```js
|
22 |
|
|
const pIsPromise = require('p-is-promise');
|
23 |
|
|
const Bluebird = require('bluebird');
|
24 |
|
|
|
25 |
|
|
pIsPromise(Promise.resolve('🦄'));
|
26 |
|
|
//=> true
|
27 |
|
|
|
28 |
|
|
pIsPromise(Bluebird.resolve('🦄'));
|
29 |
|
|
//=> true
|
30 |
|
|
|
31 |
|
|
pIsPromise('🦄');
|
32 |
|
|
//=> false
|
33 |
|
|
```
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
## Related
|
37 |
|
|
|
38 |
|
|
- [More…](https://github.com/sindresorhus/promise-fun)
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
## License
|
42 |
|
|
|
43 |
|
|
MIT © [Sindre Sorhus](https://sindresorhus.com)
|