From feb90a40501c8ef69b0c65bdf1eb703182214407 Mon Sep 17 00:00:00 2001 From: Forbes Lindesay Date: Sat, 25 Apr 2020 16:01:45 +0100 Subject: [PATCH] feat: support type narrowing via isPromise and default export --- index.d.ts | 4 ++-- index.js | 1 + index.mjs | 3 +++ package.json | 9 +++++++-- 4 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 index.mjs diff --git a/index.d.ts b/index.d.ts index a3d4b0d..bf76299 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,2 +1,2 @@ -declare function isPromise(obj: any): boolean; -export = isPromise; \ No newline at end of file +declare function isPromise(obj: Promise | S): obj is Promise; +export default isPromise; \ No newline at end of file diff --git a/index.js b/index.js index ca2444c..1bed087 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ module.exports = isPromise; +module.exports.default = isPromise; function isPromise(obj) { return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bf9e99b --- /dev/null +++ b/index.mjs @@ -0,0 +1,3 @@ +export default function isPromise(obj) { + return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; +} diff --git a/package.json b/package.json index 7e55dfe..100a512 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,11 @@ "version": "2.1.0", "description": "Test whether an object looks like a promises-a+ promise", "main": "index.js", + "type": "module", + "exports": { + "import": "index.mjs", + "require": "index.js" + }, "scripts": { "test": "mocha -R spec" }, @@ -16,7 +21,7 @@ "author": "ForbesLindesay", "license": "MIT", "devDependencies": { - "better-assert": "~0.1.0", - "mocha": "~1.7.4" + "better-assert": "^1.0.2", + "mocha": "^7.1.1" } }