From a2359a7c229db3bc111f47a86c889216951162ef Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sun, 31 Dec 2017 14:20:21 +0200 Subject: [PATCH 1/3] Add isPromise snippet --- snippets/isPromise.md | 16 ++++++++++++++++ tag_database | 1 + 2 files changed, 17 insertions(+) create mode 100644 snippets/isPromise.md diff --git a/snippets/isPromise.md b/snippets/isPromise.md new file mode 100644 index 000000000..7a6e32d3f --- /dev/null +++ b/snippets/isPromise.md @@ -0,0 +1,16 @@ +### isPromise + +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 isPromise = obj => + obj !== null && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; +``` + +```js +isPromise({then:function () {return ''}}); // true +isPromise(null); // false +isPromise({}); // false +``` diff --git a/tag_database b/tag_database index e2bb75c7e..5c9edee5d 100644 --- a/tag_database +++ b/tag_database @@ -73,6 +73,7 @@ isFunction:utility isNull:utility isNumber:utility isPrime:math +isPromise:utility isString:utility isSymbol:utility JSONToDate:date From be3f67971f936ae0a6f028e76a59890762fc8df3 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sun, 31 Dec 2017 14:25:43 +0200 Subject: [PATCH 2/3] Update and rename isPromise.md to isPromiseLike.md --- snippets/{isPromise.md => isPromiseLike.md} | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename snippets/{isPromise.md => isPromiseLike.md} (73%) diff --git a/snippets/isPromise.md b/snippets/isPromiseLike.md similarity index 73% rename from snippets/isPromise.md rename to snippets/isPromiseLike.md index 7a6e32d3f..d7bb9a75b 100644 --- a/snippets/isPromise.md +++ b/snippets/isPromiseLike.md @@ -1,16 +1,16 @@ -### isPromise +### 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 isPromise = obj => +const isPromiseLike = obj => obj !== null && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; ``` ```js -isPromise({then:function () {return ''}}); // true -isPromise(null); // false -isPromise({}); // false +isPromiseLike({then:function () {return ''}}); // true +isPromiseLike(null); // false +isPromiseLike({}); // false ``` From b4ecf35ad236a5075cfff1ee89d791cf904d511d Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sun, 31 Dec 2017 14:25:55 +0200 Subject: [PATCH 3/3] Update tag_database --- tag_database | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tag_database b/tag_database index 5c9edee5d..750f9d0bd 100644 --- a/tag_database +++ b/tag_database @@ -73,7 +73,7 @@ isFunction:utility isNull:utility isNumber:utility isPrime:math -isPromise:utility +isPromiseLike:utility isString:utility isSymbol:utility JSONToDate:date