@splendidlabz/utils 1.16.0 → 1.17.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.md +95 -0
- package/dist/cjs/lib/index.cjs +31 -0
- package/dist/cjs/lib/promises/index.cjs +33 -2
- package/dist/cjs/lib/promises/settle.cjs +55 -0
- package/dist/esm/lib/promises/index.js +1 -0
- package/dist/esm/lib/promises/settle.js +30 -0
- package/dist/types/lib/index.d.cts +1 -0
- package/dist/types/lib/promises/index.d.cts +1 -0
- package/dist/types/lib/promises/settle.d.cts +21 -0
- package/package.json +3 -2
package/LICENSE.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
Copyright (c) 2024-present Splendid Labz Pte. Ltd.
|
|
2
|
+
|
|
3
|
+
Elastic License 2.0
|
|
4
|
+
|
|
5
|
+
URL: https://www.elastic.co/licensing/elastic-license
|
|
6
|
+
|
|
7
|
+
## Acceptance
|
|
8
|
+
|
|
9
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
14
|
+
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
15
|
+
available, and prepare derivative works of the software, in each case subject to
|
|
16
|
+
the limitations and conditions below.
|
|
17
|
+
|
|
18
|
+
## Limitations
|
|
19
|
+
|
|
20
|
+
You may not provide the software to third parties as a hosted or managed
|
|
21
|
+
service, where the service provides users with access to any substantial set of
|
|
22
|
+
the features or functionality of the software.
|
|
23
|
+
|
|
24
|
+
You may not move, change, disable, or circumvent the license key functionality
|
|
25
|
+
in the software, and you may not remove or obscure any functionality in the
|
|
26
|
+
software that is protected by the license key.
|
|
27
|
+
|
|
28
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices
|
|
29
|
+
of the licensor in the software. Any use of the licensor’s trademarks is subject
|
|
30
|
+
to applicable law.
|
|
31
|
+
|
|
32
|
+
## Patents
|
|
33
|
+
|
|
34
|
+
The licensor grants you a license, under any patent claims the licensor can
|
|
35
|
+
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
36
|
+
sale, import and have imported the software, in each case subject to the
|
|
37
|
+
limitations and conditions in this license. This license does not cover any
|
|
38
|
+
patent claims that you cause to be infringed by modifications or additions to
|
|
39
|
+
the software. If you or your company make any written claim that the software
|
|
40
|
+
infringes or contributes to infringement of any patent, your patent license for
|
|
41
|
+
the software granted under these terms ends immediately. If your company makes
|
|
42
|
+
such a claim, your patent license ends immediately for work on behalf of your
|
|
43
|
+
company.
|
|
44
|
+
|
|
45
|
+
## Notices
|
|
46
|
+
|
|
47
|
+
You must ensure that anyone who gets a copy of any part of the software from you
|
|
48
|
+
also gets a copy of these terms.
|
|
49
|
+
|
|
50
|
+
If you modify the software, you must include in any modified copies of the
|
|
51
|
+
software prominent notices stating that you have modified the software.
|
|
52
|
+
|
|
53
|
+
## No Other Rights
|
|
54
|
+
|
|
55
|
+
These terms do not imply any licenses other than those expressly granted in
|
|
56
|
+
these terms.
|
|
57
|
+
|
|
58
|
+
## Termination
|
|
59
|
+
|
|
60
|
+
If you use the software in violation of these terms, such use is not licensed,
|
|
61
|
+
and your licenses will automatically terminate. If the licensor provides you
|
|
62
|
+
with a notice of your violation, and you cease all violation of this license no
|
|
63
|
+
later than 30 days after you receive that notice, your licenses will be
|
|
64
|
+
reinstated retroactively. However, if you violate these terms after such
|
|
65
|
+
reinstatement, any additional violation of these terms will cause your licenses
|
|
66
|
+
to terminate automatically and permanently.
|
|
67
|
+
|
|
68
|
+
## No Liability
|
|
69
|
+
|
|
70
|
+
_As far as the law allows, the software comes as is, without any warranty or
|
|
71
|
+
condition, and the licensor will not be liable to you for any damages arising
|
|
72
|
+
out of these terms or the use or nature of the software, under any kind of
|
|
73
|
+
legal claim._
|
|
74
|
+
|
|
75
|
+
## Definitions
|
|
76
|
+
|
|
77
|
+
The **licensor** is the entity offering these terms, and the **software** is the
|
|
78
|
+
software the licensor makes available under these terms, including any portion
|
|
79
|
+
of it.
|
|
80
|
+
|
|
81
|
+
**you** refers to the individual or entity agreeing to these terms.
|
|
82
|
+
|
|
83
|
+
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
84
|
+
organization that you work for, plus all organizations that have control over,
|
|
85
|
+
are under the control of, or are under common control with that
|
|
86
|
+
organization. **control** means ownership of substantially all the assets of an
|
|
87
|
+
entity, or the power to direct its management and policies by vote, contract, or
|
|
88
|
+
otherwise. Control can be direct or indirect.
|
|
89
|
+
|
|
90
|
+
**your licenses** are all the licenses granted to you for the software under
|
|
91
|
+
these terms.
|
|
92
|
+
|
|
93
|
+
**use** means anything you do with the software requiring one of your licenses.
|
|
94
|
+
|
|
95
|
+
**trademark** means trademarks, service marks, and similar rights.
|
package/dist/cjs/lib/index.cjs
CHANGED
|
@@ -98,6 +98,7 @@ __export(lib_exports, {
|
|
|
98
98
|
sanitizeObject: () => sanitizeObject,
|
|
99
99
|
scatter: () => scatter,
|
|
100
100
|
seededRandom: () => seededRandom,
|
|
101
|
+
settle: () => settle,
|
|
101
102
|
shuffle: () => shuffle,
|
|
102
103
|
singular: () => singular,
|
|
103
104
|
sizeOf: () => sizeOf,
|
|
@@ -1097,6 +1098,35 @@ function reject(props, { includeStack = true } = {}) {
|
|
|
1097
1098
|
return Promise.reject(omitEmpty(err));
|
|
1098
1099
|
}
|
|
1099
1100
|
|
|
1101
|
+
// src/lib/promises/settle.js
|
|
1102
|
+
async function settle(promise) {
|
|
1103
|
+
try {
|
|
1104
|
+
return toSettled(await promise, null);
|
|
1105
|
+
} catch (error) {
|
|
1106
|
+
return toSettled(null, error);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
function toSettled(result, error) {
|
|
1110
|
+
const settled = Object.defineProperties(
|
|
1111
|
+
{ result, error },
|
|
1112
|
+
{
|
|
1113
|
+
r: { value: result },
|
|
1114
|
+
e: { value: error },
|
|
1115
|
+
[Symbol.iterator]: {
|
|
1116
|
+
value: function* () {
|
|
1117
|
+
yield result;
|
|
1118
|
+
yield error;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
);
|
|
1123
|
+
return (
|
|
1124
|
+
/** @type {Settled<T>} */
|
|
1125
|
+
/** @type {unknown} */
|
|
1126
|
+
settled
|
|
1127
|
+
);
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1100
1130
|
// src/lib/sse.js
|
|
1101
1131
|
function createSSE({ event, data, id, retry }) {
|
|
1102
1132
|
const eventString = event ? `event: ${event}
|
|
@@ -1791,6 +1821,7 @@ function getSymbolValue(object, description) {
|
|
|
1791
1821
|
sanitizeObject,
|
|
1792
1822
|
scatter,
|
|
1793
1823
|
seededRandom,
|
|
1824
|
+
settle,
|
|
1794
1825
|
shuffle,
|
|
1795
1826
|
singular,
|
|
1796
1827
|
sizeOf,
|
|
@@ -19,7 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/lib/promises/index.js
|
|
20
20
|
var promises_exports = {};
|
|
21
21
|
__export(promises_exports, {
|
|
22
|
-
reject: () => reject
|
|
22
|
+
reject: () => reject,
|
|
23
|
+
settle: () => settle
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(promises_exports);
|
|
25
26
|
|
|
@@ -139,7 +140,37 @@ function reject(props, { includeStack = true } = {}) {
|
|
|
139
140
|
};
|
|
140
141
|
return Promise.reject(omitEmpty(err));
|
|
141
142
|
}
|
|
143
|
+
|
|
144
|
+
// src/lib/promises/settle.js
|
|
145
|
+
async function settle(promise) {
|
|
146
|
+
try {
|
|
147
|
+
return toSettled(await promise, null);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
return toSettled(null, error);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function toSettled(result, error) {
|
|
153
|
+
const settled = Object.defineProperties(
|
|
154
|
+
{ result, error },
|
|
155
|
+
{
|
|
156
|
+
r: { value: result },
|
|
157
|
+
e: { value: error },
|
|
158
|
+
[Symbol.iterator]: {
|
|
159
|
+
value: function* () {
|
|
160
|
+
yield result;
|
|
161
|
+
yield error;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
return (
|
|
167
|
+
/** @type {Settled<T>} */
|
|
168
|
+
/** @type {unknown} */
|
|
169
|
+
settled
|
|
170
|
+
);
|
|
171
|
+
}
|
|
142
172
|
// Annotate the CommonJS export names for ESM import in node:
|
|
143
173
|
0 && (module.exports = {
|
|
144
|
-
reject
|
|
174
|
+
reject,
|
|
175
|
+
settle
|
|
145
176
|
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/lib/promises/settle.js
|
|
20
|
+
var settle_exports = {};
|
|
21
|
+
__export(settle_exports, {
|
|
22
|
+
settle: () => settle
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(settle_exports);
|
|
25
|
+
async function settle(promise) {
|
|
26
|
+
try {
|
|
27
|
+
return toSettled(await promise, null);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
return toSettled(null, error);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function toSettled(result, error) {
|
|
33
|
+
const settled = Object.defineProperties(
|
|
34
|
+
{ result, error },
|
|
35
|
+
{
|
|
36
|
+
r: { value: result },
|
|
37
|
+
e: { value: error },
|
|
38
|
+
[Symbol.iterator]: {
|
|
39
|
+
value: function* () {
|
|
40
|
+
yield result;
|
|
41
|
+
yield error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
return (
|
|
47
|
+
/** @type {Settled<T>} */
|
|
48
|
+
/** @type {unknown} */
|
|
49
|
+
settled
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
settle
|
|
55
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
async function settle(promise) {
|
|
2
|
+
try {
|
|
3
|
+
return toSettled(await promise, null);
|
|
4
|
+
} catch (error) {
|
|
5
|
+
return toSettled(null, error);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
function toSettled(result, error) {
|
|
9
|
+
const settled = Object.defineProperties(
|
|
10
|
+
{ result, error },
|
|
11
|
+
{
|
|
12
|
+
r: { value: result },
|
|
13
|
+
e: { value: error },
|
|
14
|
+
[Symbol.iterator]: {
|
|
15
|
+
value: function* () {
|
|
16
|
+
yield result;
|
|
17
|
+
yield error;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
return (
|
|
23
|
+
/** @type {Settled<T>} */
|
|
24
|
+
/** @type {unknown} */
|
|
25
|
+
settled
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
settle
|
|
30
|
+
};
|
|
@@ -38,6 +38,7 @@ export { sizeOf } from './objects/size.cjs';
|
|
|
38
38
|
export { splitObject } from './objects/split.cjs';
|
|
39
39
|
export { trimValues } from './objects/trim-values.cjs';
|
|
40
40
|
export { reject } from './promises/reject.cjs';
|
|
41
|
+
export { Settled, settle } from './promises/settle.cjs';
|
|
41
42
|
export { createSSE, parseSSE } from './sse.cjs';
|
|
42
43
|
export { toCamel, toKebab, toLower, toPascal, toSentence, toSlug, toTitle, toUpper } from './strings/convert-case/convert-case.cjs';
|
|
43
44
|
export { markdown, treatMarkdownWhitespace } from './strings/markdown.cjs';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @template T
|
|
3
|
+
* @typedef {{ result: T | null, error: unknown, r: T | null, e: unknown } & [T | null, unknown]} Settled
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* settle
|
|
7
|
+
* Awaits a promise and returns its error instead of throwing.
|
|
8
|
+
*
|
|
9
|
+
* @template T
|
|
10
|
+
* @param {Promise<T>} promise
|
|
11
|
+
* @returns {Promise<Settled<T>>}
|
|
12
|
+
*/
|
|
13
|
+
declare function settle<T>(promise: Promise<T>): Promise<Settled<T>>;
|
|
14
|
+
type Settled<T> = {
|
|
15
|
+
result: T | null;
|
|
16
|
+
error: unknown;
|
|
17
|
+
r: T | null;
|
|
18
|
+
e: unknown;
|
|
19
|
+
} & [T | null, unknown];
|
|
20
|
+
|
|
21
|
+
export { type Settled, settle };
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splendidlabz/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"description": "",
|
|
5
|
+
"license": "Elastic-2.0",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"homepage": "https://splendidlabz.com/docs/utils",
|
|
7
8
|
"sideEffects": false,
|
|
@@ -67,7 +68,7 @@
|
|
|
67
68
|
"sanitize-html": "^2.17.3"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
70
|
-
"@splendidlabz/eslint-config": "2.
|
|
71
|
+
"@splendidlabz/eslint-config": "2.2.0",
|
|
71
72
|
"np": "^11.1.0",
|
|
72
73
|
"tsup": "^8.5.1",
|
|
73
74
|
"typescript": "^6.0.3",
|