@prexjs/promise 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +81 -2
- package/lib/index.cjs +7 -0
- package/lib/index.d.cts +12 -0
- package/lib/index.d.mts +12 -0
- package/lib/index.mjs +7 -0
- package/package.json +62 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Prexjs (https://prexjs.com)
|
|
4
|
+
Copyright (c) 2026 Sorabh (https://sorabh.org)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,82 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @prexjs/promise
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Lightweight, zero-dependency type guard utility to test if a value is a Promise or Thenable.**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@prexjs/promise)
|
|
6
|
+
[](https://www.npmjs.com/package/@prexjs/promise)
|
|
7
|
+
[](./LICENSE)
|
|
8
|
+
[](https://www.typescriptlang.org/)
|
|
9
|
+
|
|
10
|
+
`@prexjs/promise` provides an ultra-fast, robust TypeScript type guard `isPromise(val)` to determine if a value is an ES6 Promise, async thenable, or third-party promise (Bluebird, Q, etc.).
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- Validates whether an object or function qualifies as a Promise/A+ thenable.
|
|
15
|
+
- TypeScript user-defined type guard narrowing (`value is PromiseLike<T>`).
|
|
16
|
+
- Dual ES Module (`.mjs`) and CommonJS (`.cjs`) support with TypeScript definitions.
|
|
17
|
+
- Zero runtime dependencies.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
Install using your preferred package manager:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# npm
|
|
25
|
+
npm install @prexjs/promise
|
|
26
|
+
|
|
27
|
+
# pnpm
|
|
28
|
+
pnpm add @prexjs/promise
|
|
29
|
+
|
|
30
|
+
# Yarn
|
|
31
|
+
yarn add @prexjs/promise
|
|
32
|
+
|
|
33
|
+
# Bun
|
|
34
|
+
bun add @prexjs/promise
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick start
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import isPromise from '@prexjs/promise';
|
|
41
|
+
|
|
42
|
+
console.log(isPromise(Promise.resolve('antigravity'))); // true
|
|
43
|
+
console.log(isPromise({ then: (resolve) => resolve(1) })); // true
|
|
44
|
+
console.log(isPromise('not a promise')); // false
|
|
45
|
+
console.log(isPromise(null)); // false
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Both default and named exports are supported:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import isPromise, { isPromise as namedIsPromise } from '@prexjs/promise';
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Examples
|
|
55
|
+
|
|
56
|
+
### Handling synchronous or asynchronous results
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import isPromise from '@prexjs/promise';
|
|
60
|
+
|
|
61
|
+
function handle(result: unknown) {
|
|
62
|
+
if (isPromise(result)) {
|
|
63
|
+
result.then((val) => {
|
|
64
|
+
console.log('Async resolved:', val);
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
console.log('Sync result:', result);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Compatibility
|
|
73
|
+
|
|
74
|
+
`@prexjs/promise` runs anywhere ECMAScript executes (Node.js, Deno, Bun, and all browsers).
|
|
75
|
+
|
|
76
|
+
## License
|
|
77
|
+
|
|
78
|
+
This project is licensed under the MIT License. See [LICENSE](./LICENSE) for the full license text.
|
|
79
|
+
|
|
80
|
+
## Related projects
|
|
81
|
+
|
|
82
|
+
- [prex.js](https://github.com/prexjs/prex.js) — prex.js monorepo and ecosystem.
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @prexjs/promise
|
|
3
|
+
* Copyright (c) 2026 Prexjs (https://prexjs.com)
|
|
4
|
+
* Copyright (c) 2026 Sorabh (https://Sorabh.org)
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
"use strict";function e(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then}Object.defineProperty(exports,"__esModule",{value:!0}),e.default=e,e.isPromise=e,exports.default=e,exports.isPromise=e;
|
package/lib/index.d.cts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether a value is a promise or any "thenable"
|
|
3
|
+
* (an object or function with a `then` method).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* isPromise(Promise.resolve(1)); // true
|
|
7
|
+
* isPromise({ then() {} }); // true
|
|
8
|
+
* isPromise(42); // false
|
|
9
|
+
*/
|
|
10
|
+
declare function isPromise<T, S>(obj: PromiseLike<T> | S): obj is PromiseLike<T>;
|
|
11
|
+
|
|
12
|
+
export { isPromise as default, isPromise };
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether a value is a promise or any "thenable"
|
|
3
|
+
* (an object or function with a `then` method).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* isPromise(Promise.resolve(1)); // true
|
|
7
|
+
* isPromise({ then() {} }); // true
|
|
8
|
+
* isPromise(42); // false
|
|
9
|
+
*/
|
|
10
|
+
declare function isPromise<T, S>(obj: PromiseLike<T> | S): obj is PromiseLike<T>;
|
|
11
|
+
|
|
12
|
+
export { isPromise as default, isPromise };
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @prexjs/promise
|
|
3
|
+
* Copyright (c) 2026 Prexjs (https://prexjs.com)
|
|
4
|
+
* Copyright (c) 2026 Sorabh (https://Sorabh.org)
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
function t(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}t.default=t,t.isPromise=t;export{t as default,t as isPromise};
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prexjs/promise",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Lightweight, zero-dependency type guard utility to test if a value is a Promise or Thenable.",
|
|
5
|
+
"authors": [
|
|
6
|
+
{
|
|
7
|
+
"name": "Prexjs",
|
|
8
|
+
"email": "hello@prexjs.com",
|
|
9
|
+
"url": "https://prexjs.com"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "Sorabh",
|
|
13
|
+
"email": "hello@sorabh.org",
|
|
14
|
+
"url": "https://sorabh.org"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"files": [
|
|
21
|
+
"lib",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"main": "./lib/index.cjs",
|
|
26
|
+
"module": "./lib/index.mjs",
|
|
27
|
+
"types": "./lib/index.d.cts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./lib/index.d.mts",
|
|
32
|
+
"default": "./lib/index.mjs"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./lib/index.d.cts",
|
|
36
|
+
"default": "./lib/index.cjs"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/prexjs/prex.js.git",
|
|
44
|
+
"directory": "packages/promise"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/prexjs/prex.js/tree/main/packages/promise#readme",
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/prexjs/prex.js/issues"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"keywords": [
|
|
54
|
+
"prexjs",
|
|
55
|
+
"promise",
|
|
56
|
+
"ispromise",
|
|
57
|
+
"thenable",
|
|
58
|
+
"async",
|
|
59
|
+
"typeguard",
|
|
60
|
+
"deferred",
|
|
61
|
+
"check",
|
|
62
|
+
"typescript"
|
|
63
|
+
]
|
|
64
|
+
}
|