Travis build: 734 [ci skip]
This commit is contained in:
32
README.md
32
README.md
@ -250,6 +250,7 @@
|
|||||||
* [`isFunction`](#isfunction)
|
* [`isFunction`](#isfunction)
|
||||||
* [`isNull`](#isnull)
|
* [`isNull`](#isnull)
|
||||||
* [`isNumber`](#isnumber)
|
* [`isNumber`](#isnumber)
|
||||||
|
* [`isPromiseLike`](#ispromiselike)
|
||||||
* [`isString`](#isstring)
|
* [`isString`](#isstring)
|
||||||
* [`isSymbol`](#issymbol)
|
* [`isSymbol`](#issymbol)
|
||||||
* [`isValidJSON`](#isvalidjson)
|
* [`isValidJSON`](#isvalidjson)
|
||||||
@ -4196,6 +4197,37 @@ isNumber(1); // true
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### isPromiseLike
|
||||||
|
|
||||||
|
Returns `true` if an object looks like a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), `false` otherwise.
|
||||||
|
|
||||||
|
Check if the object is not `null`, its `typeof` matches either `object` or `function` and if it has a `.then` property, which is also a `function`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const isPromiseLike = obj =>
|
||||||
|
obj !== null &&
|
||||||
|
(typeof obj === 'object' || typeof obj === 'function') &&
|
||||||
|
typeof obj.then === 'function';
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
isPromiseLike({
|
||||||
|
then: function() {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}); // true
|
||||||
|
isPromiseLike(null); // false
|
||||||
|
isPromiseLike({}); // false
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### isString
|
### isString
|
||||||
|
|
||||||
Checks if the given argument is a string.
|
Checks if the given argument is a string.
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -6,11 +6,17 @@ Check if the object is not `null`, its `typeof` matches either `object` or `func
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const isPromiseLike = obj =>
|
const isPromiseLike = obj =>
|
||||||
obj !== null && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
obj !== null &&
|
||||||
|
(typeof obj === 'object' || typeof obj === 'function') &&
|
||||||
|
typeof obj.then === 'function';
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
isPromiseLike({then:function () {return ''}}); // true
|
isPromiseLike({
|
||||||
|
then: function() {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}); // true
|
||||||
isPromiseLike(null); // false
|
isPromiseLike(null); // false
|
||||||
isPromiseLike({}); // false
|
isPromiseLike({}); // false
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user