Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/modernpoacher/is-promise-like
https://github.com/modernpoacher/is-promise-like
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/modernpoacher/is-promise-like
- Owner: modernpoacher
- Created: 2017-06-26T20:02:55.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-02-24T16:54:09.000Z (9 months ago)
- Last Synced: 2024-04-25T16:02:42.499Z (7 months ago)
- Language: JavaScript
- Size: 2.77 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# IsPromiseLike
## Usage
```javascript
import {
isPromise,
isPromiseLike
} from 'is-promise-like'
````isPromise` identifies instances of the global `Promise` class.
`isPromiseLike` identifies instances of the global `Promise` class or other objects which are _like_ them.
### Examples: `isPromise`
Returns `true`:
```javascript
const p = new Promise(() => {})isPromise(p) // true
```
```javascript
const p = Promise.resolve({})isPromise(p) // true
```
```javascript
const p = Promise.all([])isPromise(p) // true
```Anything else should return `false`.
### Examples: `isPromiseLike`
All of the preceding examples returning `true`. In addition:
```javascript
class S {
static then () {}
}isPromiseLike(S) // true
```
```javascript
class S {
then () {}
}const s = new S()
isPromiseLike(s) // true
```
```javascript
const o = {}
o.then = () => {}isPromiseLike(o) // true
```
```javascript
const a = []
a.then = () => {}isPromiseLike(a) // true
```
And similar constructions for other types. Anything else should return `false`.