es-toolkit 1.3.1 → 1.4.0-dev.82
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/CHANGELOG.md +14 -0
- package/dist/array/index.js +9 -2
- package/dist/array/index.js.map +1 -1
- package/dist/array/index.mjs +24 -24
- package/dist/array/unionBy.js +1 -1
- package/dist/array/unionBy.js.map +1 -1
- package/dist/array/unionBy.mjs +1 -1
- package/dist/array/uniqBy.js +6 -13
- package/dist/array/uniqBy.js.map +1 -1
- package/dist/array/uniqBy.mjs +1 -2
- package/dist/array/xorBy.js +1 -1
- package/dist/array/xorBy.js.map +1 -1
- package/dist/array/xorBy.mjs +2 -2
- package/dist/chunk-AL3GJBEI.mjs +26 -0
- package/dist/chunk-AL3GJBEI.mjs.map +1 -0
- package/dist/{chunk-EW3RT4QW.mjs → chunk-AM2EGFCU.mjs} +2 -2
- package/dist/chunk-FZEZH22H.mjs +1 -0
- package/dist/{chunk-GOXQV6DX.mjs → chunk-MKETZ2RP.mjs} +2 -3
- package/dist/{chunk-GOXQV6DX.mjs.map → chunk-MKETZ2RP.mjs.map} +1 -1
- package/dist/{chunk-JBDGK6X4.mjs → chunk-NRNKP6JF.mjs} +2 -2
- package/dist/{chunk-JBDGK6X4.mjs.map → chunk-NRNKP6JF.mjs.map} +1 -1
- package/dist/chunk-QWJDITYJ.mjs +13 -0
- package/dist/chunk-QWJDITYJ.mjs.map +1 -0
- package/dist/chunk-UGFVAAVO.mjs +12 -0
- package/dist/chunk-UGFVAAVO.mjs.map +1 -0
- package/dist/chunk-VAV4XHLO.mjs +1 -0
- package/dist/chunk-VAV4XHLO.mjs.map +1 -0
- package/dist/chunk-VP2LXY75.mjs +12 -0
- package/dist/chunk-VP2LXY75.mjs.map +1 -0
- package/dist/chunk-WPDDOUQT.mjs +16 -0
- package/dist/chunk-WPDDOUQT.mjs.map +1 -0
- package/dist/error/AbortError.d.mts +5 -0
- package/dist/error/AbortError.d.ts +5 -0
- package/dist/error/AbortError.js +36 -0
- package/dist/error/AbortError.js.map +1 -0
- package/dist/error/AbortError.mjs +8 -0
- package/dist/error/AbortError.mjs.map +1 -0
- package/dist/error/index.d.mts +1 -0
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.js +38 -0
- package/dist/error/index.js.map +1 -0
- package/dist/error/index.mjs +9 -0
- package/dist/error/index.mjs.map +1 -0
- package/dist/function/debounce.js +1 -2
- package/dist/function/debounce.js.map +1 -1
- package/dist/function/debounce.mjs +1 -1
- package/dist/function/index.js +1 -2
- package/dist/function/index.js.map +1 -1
- package/dist/function/index.mjs +4 -4
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +51 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -54
- package/dist/math/index.d.mts +2 -0
- package/dist/math/index.d.ts +2 -0
- package/dist/math/index.js +17 -0
- package/dist/math/index.js.map +1 -1
- package/dist/math/index.mjs +11 -3
- package/dist/math/random.d.mts +16 -0
- package/dist/math/random.d.ts +16 -0
- package/dist/math/random.js +36 -0
- package/dist/math/random.js.map +1 -0
- package/dist/math/random.mjs +8 -0
- package/dist/math/random.mjs.map +1 -0
- package/dist/math/randomInt.d.mts +15 -0
- package/dist/math/randomInt.d.ts +15 -0
- package/dist/math/randomInt.js +43 -0
- package/dist/math/randomInt.js.map +1 -0
- package/dist/math/randomInt.mjs +9 -0
- package/dist/math/randomInt.mjs.map +1 -0
- package/dist/object/index.mjs +6 -6
- package/dist/predicate/index.mjs +3 -3
- package/dist/promise/delay.d.mts +18 -1
- package/dist/promise/delay.d.ts +18 -1
- package/dist/promise/delay.js +24 -3
- package/dist/promise/delay.js.map +1 -1
- package/dist/promise/delay.mjs +2 -1
- package/dist/promise/index.js +22 -3
- package/dist/promise/index.js.map +1 -1
- package/dist/promise/index.mjs +2 -1
- package/package.json +1 -1
- package/dist/chunk-ASFOKYTY.mjs +0 -13
- package/dist/chunk-ASFOKYTY.mjs.map +0 -1
- package/dist/chunk-IJLQVGW4.mjs +0 -1
- package/dist/chunk-ZBG3EYM3.mjs +0 -11
- package/dist/chunk-ZBG3EYM3.mjs.map +0 -1
- /package/dist/{chunk-EW3RT4QW.mjs.map → chunk-AM2EGFCU.mjs.map} +0 -0
- /package/dist/{chunk-IJLQVGW4.mjs.map → chunk-FZEZH22H.mjs.map} +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/math/random.ts
|
|
21
|
+
var random_exports = {};
|
|
22
|
+
__export(random_exports, {
|
|
23
|
+
random: () => random
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(random_exports);
|
|
26
|
+
function random(minimum, maximum) {
|
|
27
|
+
if (minimum >= maximum) {
|
|
28
|
+
throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
|
|
29
|
+
}
|
|
30
|
+
return Math.random() * (maximum - minimum) + minimum;
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
random
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=random.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/math/random.ts"],"sourcesContent":["/**\n * Generates a random floating-point number between minimum (inclusive) and maximum (exclusive).\n * If min is greater than maximum, the values are swapped.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result = random(0, 5); // result will be a random floating-point number between 0 (inclusive) and 5 (exclusive)\n * const result2 = random(5, 0); // This will throw an error\n */\nexport function random(minimum: number, maximum: number): number {\n if (minimum >= maximum) {\n throw new Error('Invalid input: The maximum value must be greater than the minimum value.');\n }\n\n return Math.random() * (maximum - minimum) + minimum;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,SAAS,OAAO,SAAiB,SAAyB;AAC/D,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a random integer between minimum (inclusive) and maximum (exclusive).
|
|
3
|
+
*
|
|
4
|
+
* @param {number} minimum - The lower bound (inclusive).
|
|
5
|
+
* @param {number} maximum - The upper bound (exclusive).
|
|
6
|
+
* @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).
|
|
7
|
+
* @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)
|
|
11
|
+
* const result2 = randomInt(5, 0); // This will throw an error
|
|
12
|
+
*/
|
|
13
|
+
declare function randomInt(minimum: number, maximum: number): number;
|
|
14
|
+
|
|
15
|
+
export { randomInt };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a random integer between minimum (inclusive) and maximum (exclusive).
|
|
3
|
+
*
|
|
4
|
+
* @param {number} minimum - The lower bound (inclusive).
|
|
5
|
+
* @param {number} maximum - The upper bound (exclusive).
|
|
6
|
+
* @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).
|
|
7
|
+
* @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)
|
|
11
|
+
* const result2 = randomInt(5, 0); // This will throw an error
|
|
12
|
+
*/
|
|
13
|
+
declare function randomInt(minimum: number, maximum: number): number;
|
|
14
|
+
|
|
15
|
+
export { randomInt };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/math/randomInt.ts
|
|
21
|
+
var randomInt_exports = {};
|
|
22
|
+
__export(randomInt_exports, {
|
|
23
|
+
randomInt: () => randomInt
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(randomInt_exports);
|
|
26
|
+
|
|
27
|
+
// src/math/random.ts
|
|
28
|
+
function random(minimum, maximum) {
|
|
29
|
+
if (minimum >= maximum) {
|
|
30
|
+
throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
|
|
31
|
+
}
|
|
32
|
+
return Math.random() * (maximum - minimum) + minimum;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/math/randomInt.ts
|
|
36
|
+
function randomInt(minimum, maximum) {
|
|
37
|
+
return Math.floor(random(minimum, maximum));
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
randomInt
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=randomInt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/math/randomInt.ts","../../src/math/random.ts"],"sourcesContent":["import { random } from './random';\n\n/**\n * Generates a random integer between minimum (inclusive) and maximum (exclusive).\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)\n * const result2 = randomInt(5, 0); // This will throw an error\n */\nexport function randomInt(minimum: number, maximum: number): number {\n return Math.floor(random(minimum, maximum));\n}\n","/**\n * Generates a random floating-point number between minimum (inclusive) and maximum (exclusive).\n * If min is greater than maximum, the values are swapped.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result = random(0, 5); // result will be a random floating-point number between 0 (inclusive) and 5 (exclusive)\n * const result2 = random(5, 0); // This will throw an error\n */\nexport function random(minimum: number, maximum: number): number {\n if (minimum >= maximum) {\n throw new Error('Invalid input: The maximum value must be greater than the minimum value.');\n }\n\n return Math.random() * (maximum - minimum) + minimum;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,SAAS,OAAO,SAAiB,SAAyB;AAC/D,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;;;ADLO,SAAS,UAAU,SAAiB,SAAyB;AAClE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAO,CAAC;AAC5C;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/object/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import "../chunk-T5JCRGXA.mjs";
|
|
2
|
-
import {
|
|
3
|
-
omit
|
|
4
|
-
} from "../chunk-PLTO44KM.mjs";
|
|
5
|
-
import {
|
|
6
|
-
omitBy
|
|
7
|
-
} from "../chunk-SF3V7XXM.mjs";
|
|
8
2
|
import {
|
|
9
3
|
pick
|
|
10
4
|
} from "../chunk-OFWKFUFZ.mjs";
|
|
11
5
|
import {
|
|
12
6
|
pickBy
|
|
13
7
|
} from "../chunk-T2C2WVFL.mjs";
|
|
8
|
+
import {
|
|
9
|
+
omit
|
|
10
|
+
} from "../chunk-PLTO44KM.mjs";
|
|
11
|
+
import {
|
|
12
|
+
omitBy
|
|
13
|
+
} from "../chunk-SF3V7XXM.mjs";
|
|
14
14
|
import "../chunk-2MM5EJJX.mjs";
|
|
15
15
|
export {
|
|
16
16
|
omit,
|
package/dist/predicate/index.mjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import "../chunk-MAJSPFA6.mjs";
|
|
2
|
+
import {
|
|
3
|
+
isNil
|
|
4
|
+
} from "../chunk-OHQAR5AU.mjs";
|
|
2
5
|
import {
|
|
3
6
|
isNotNil
|
|
4
7
|
} from "../chunk-ZQNAZPSK.mjs";
|
|
@@ -8,9 +11,6 @@ import {
|
|
|
8
11
|
import {
|
|
9
12
|
isUndefined
|
|
10
13
|
} from "../chunk-VH2PV426.mjs";
|
|
11
|
-
import {
|
|
12
|
-
isNil
|
|
13
|
-
} from "../chunk-OHQAR5AU.mjs";
|
|
14
14
|
import "../chunk-2MM5EJJX.mjs";
|
|
15
15
|
export {
|
|
16
16
|
isNil,
|
package/dist/promise/delay.d.mts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
interface DelayOptions {
|
|
2
|
+
signal?: AbortSignal;
|
|
3
|
+
}
|
|
1
4
|
/**
|
|
2
5
|
* Delays the execution of code for a specified number of milliseconds.
|
|
3
6
|
*
|
|
@@ -5,6 +8,8 @@
|
|
|
5
8
|
* with async/await to pause execution.
|
|
6
9
|
*
|
|
7
10
|
* @param {number} ms - The number of milliseconds to delay.
|
|
11
|
+
* @param {DelayOptions} options - The options object.
|
|
12
|
+
* @param {AbortSignal} options.signal - An optional AbortSignal to cancel the delay.
|
|
8
13
|
* @returns {Promise<void>} A Promise that resolves after the specified delay.
|
|
9
14
|
*
|
|
10
15
|
* @example
|
|
@@ -15,7 +20,19 @@
|
|
|
15
20
|
* }
|
|
16
21
|
*
|
|
17
22
|
* foo();
|
|
23
|
+
*
|
|
24
|
+
* // With AbortSignal
|
|
25
|
+
* const controller = new AbortController();
|
|
26
|
+
* const { signal } = controller;
|
|
27
|
+
*
|
|
28
|
+
* setTimeout(() => controller.abort(), 50); // Will cancel the delay after 50ms
|
|
29
|
+
* try {
|
|
30
|
+
* await delay(100, { signal });
|
|
31
|
+
* } catch (error) {
|
|
32
|
+
* console.error(error); // Will log 'AbortError'
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
18
35
|
*/
|
|
19
|
-
declare function delay(ms: number): Promise<void>;
|
|
36
|
+
declare function delay(ms: number, { signal }?: DelayOptions): Promise<void>;
|
|
20
37
|
|
|
21
38
|
export { delay };
|
package/dist/promise/delay.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
interface DelayOptions {
|
|
2
|
+
signal?: AbortSignal;
|
|
3
|
+
}
|
|
1
4
|
/**
|
|
2
5
|
* Delays the execution of code for a specified number of milliseconds.
|
|
3
6
|
*
|
|
@@ -5,6 +8,8 @@
|
|
|
5
8
|
* with async/await to pause execution.
|
|
6
9
|
*
|
|
7
10
|
* @param {number} ms - The number of milliseconds to delay.
|
|
11
|
+
* @param {DelayOptions} options - The options object.
|
|
12
|
+
* @param {AbortSignal} options.signal - An optional AbortSignal to cancel the delay.
|
|
8
13
|
* @returns {Promise<void>} A Promise that resolves after the specified delay.
|
|
9
14
|
*
|
|
10
15
|
* @example
|
|
@@ -15,7 +20,19 @@
|
|
|
15
20
|
* }
|
|
16
21
|
*
|
|
17
22
|
* foo();
|
|
23
|
+
*
|
|
24
|
+
* // With AbortSignal
|
|
25
|
+
* const controller = new AbortController();
|
|
26
|
+
* const { signal } = controller;
|
|
27
|
+
*
|
|
28
|
+
* setTimeout(() => controller.abort(), 50); // Will cancel the delay after 50ms
|
|
29
|
+
* try {
|
|
30
|
+
* await delay(100, { signal });
|
|
31
|
+
* } catch (error) {
|
|
32
|
+
* console.error(error); // Will log 'AbortError'
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
18
35
|
*/
|
|
19
|
-
declare function delay(ms: number): Promise<void>;
|
|
36
|
+
declare function delay(ms: number, { signal }?: DelayOptions): Promise<void>;
|
|
20
37
|
|
|
21
38
|
export { delay };
|
package/dist/promise/delay.js
CHANGED
|
@@ -23,9 +23,30 @@ __export(delay_exports, {
|
|
|
23
23
|
delay: () => delay
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(delay_exports);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
|
|
27
|
+
// src/error/AbortError.ts
|
|
28
|
+
var AbortError = class extends Error {
|
|
29
|
+
constructor(message = "The operation was aborted") {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = "AbortError";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/promise/delay.ts
|
|
36
|
+
function delay(ms, { signal } = {}) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
const abortError = () => {
|
|
39
|
+
reject(new AbortError());
|
|
40
|
+
};
|
|
41
|
+
const abortHandler = () => {
|
|
42
|
+
clearTimeout(timeoutId);
|
|
43
|
+
abortError();
|
|
44
|
+
};
|
|
45
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
46
|
+
return abortError();
|
|
47
|
+
}
|
|
48
|
+
const timeoutId = setTimeout(resolve, ms);
|
|
49
|
+
signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
|
|
29
50
|
});
|
|
30
51
|
}
|
|
31
52
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/promise/delay.ts"],"sourcesContent":["/**\n * Delays the execution of code for a specified number of milliseconds.\n *\n * This function returns a Promise that resolves after the specified delay, allowing you to use it\n * with async/await to pause execution.\n *\n * @param {number} ms - The number of milliseconds to delay.\n * @returns {Promise<void>} A Promise that resolves after the specified delay.\n *\n * @example\n * async function foo() {\n * console.log('Start');\n * await delay(1000); // Delays execution for 1 second\n * console.log('End');\n * }\n *\n * foo();\n */\nexport function delay(ms: number): Promise<void> {\n return new Promise(resolve => {\n setTimeout(resolve, ms);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../../src/promise/delay.ts","../../src/error/AbortError.ts"],"sourcesContent":["import { AbortError } from '../error/AbortError';\n\ninterface DelayOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Delays the execution of code for a specified number of milliseconds.\n *\n * This function returns a Promise that resolves after the specified delay, allowing you to use it\n * with async/await to pause execution.\n *\n * @param {number} ms - The number of milliseconds to delay.\n * @param {DelayOptions} options - The options object.\n * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the delay.\n * @returns {Promise<void>} A Promise that resolves after the specified delay.\n *\n * @example\n * async function foo() {\n * console.log('Start');\n * await delay(1000); // Delays execution for 1 second\n * console.log('End');\n * }\n *\n * foo();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const { signal } = controller;\n *\n * setTimeout(() => controller.abort(), 50); // Will cancel the delay after 50ms\n * try {\n * await delay(100, { signal });\n * } catch (error) {\n * console.error(error); // Will log 'AbortError'\n * }\n * }\n */\nexport function delay(ms: number, { signal }: DelayOptions = {}): Promise<void> {\n return new Promise((resolve, reject) => {\n const abortError = () => {\n reject(new AbortError());\n };\n\n const abortHandler = () => {\n clearTimeout(timeoutId);\n abortError();\n };\n\n if (signal?.aborted) {\n return abortError();\n }\n\n const timeoutId = setTimeout(resolve, ms);\n\n signal?.addEventListener('abort', abortHandler, { once: true });\n });\n}\n","export class AbortError extends Error {\n constructor(message = 'The operation was aborted') {\n super(message);\n this.name = 'AbortError';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ADiCO,SAAS,MAAM,IAAY,EAAE,OAAO,IAAkB,CAAC,GAAkB;AAC9E,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,aAAa,MAAM;AACvB,aAAO,IAAI,WAAW,CAAC;AAAA,IACzB;AAEA,UAAM,eAAe,MAAM;AACzB,mBAAa,SAAS;AACtB,iBAAW;AAAA,IACb;AAEA,QAAI,iCAAQ,SAAS;AACnB,aAAO,WAAW;AAAA,IACpB;AAEA,UAAM,YAAY,WAAW,SAAS,EAAE;AAExC,qCAAQ,iBAAiB,SAAS,cAAc,EAAE,MAAM,KAAK;AAAA,EAC/D,CAAC;AACH;","names":[]}
|
package/dist/promise/delay.mjs
CHANGED
package/dist/promise/index.js
CHANGED
|
@@ -24,10 +24,29 @@ __export(promise_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(promise_exports);
|
|
26
26
|
|
|
27
|
+
// src/error/AbortError.ts
|
|
28
|
+
var AbortError = class extends Error {
|
|
29
|
+
constructor(message = "The operation was aborted") {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = "AbortError";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
27
35
|
// src/promise/delay.ts
|
|
28
|
-
function delay(ms) {
|
|
29
|
-
return new Promise((resolve) => {
|
|
30
|
-
|
|
36
|
+
function delay(ms, { signal } = {}) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
const abortError = () => {
|
|
39
|
+
reject(new AbortError());
|
|
40
|
+
};
|
|
41
|
+
const abortHandler = () => {
|
|
42
|
+
clearTimeout(timeoutId);
|
|
43
|
+
abortError();
|
|
44
|
+
};
|
|
45
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
46
|
+
return abortError();
|
|
47
|
+
}
|
|
48
|
+
const timeoutId = setTimeout(resolve, ms);
|
|
49
|
+
signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
|
|
31
50
|
});
|
|
32
51
|
}
|
|
33
52
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/promise/index.ts","../../src/promise/delay.ts"],"sourcesContent":["export { delay } from './delay';\n","/**\n * Delays the execution of code for a specified number of milliseconds.\n *\n * This function returns a Promise that resolves after the specified delay, allowing you to use it\n * with async/await to pause execution.\n *\n * @param {number} ms - The number of milliseconds to delay.\n * @returns {Promise<void>} A Promise that resolves after the specified delay.\n *\n * @example\n * async function foo() {\n * console.log('Start');\n * await delay(1000); // Delays execution for 1 second\n * console.log('End');\n * }\n *\n * foo();\n */\nexport function delay(ms: number): Promise<void> {\n return new Promise(resolve => {\n setTimeout(resolve, ms);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;
|
|
1
|
+
{"version":3,"sources":["../../src/promise/index.ts","../../src/error/AbortError.ts","../../src/promise/delay.ts"],"sourcesContent":["export { delay } from './delay';\n","export class AbortError extends Error {\n constructor(message = 'The operation was aborted') {\n super(message);\n this.name = 'AbortError';\n }\n}\n","import { AbortError } from '../error/AbortError';\n\ninterface DelayOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Delays the execution of code for a specified number of milliseconds.\n *\n * This function returns a Promise that resolves after the specified delay, allowing you to use it\n * with async/await to pause execution.\n *\n * @param {number} ms - The number of milliseconds to delay.\n * @param {DelayOptions} options - The options object.\n * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the delay.\n * @returns {Promise<void>} A Promise that resolves after the specified delay.\n *\n * @example\n * async function foo() {\n * console.log('Start');\n * await delay(1000); // Delays execution for 1 second\n * console.log('End');\n * }\n *\n * foo();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const { signal } = controller;\n *\n * setTimeout(() => controller.abort(), 50); // Will cancel the delay after 50ms\n * try {\n * await delay(100, { signal });\n * } catch (error) {\n * console.error(error); // Will log 'AbortError'\n * }\n * }\n */\nexport function delay(ms: number, { signal }: DelayOptions = {}): Promise<void> {\n return new Promise((resolve, reject) => {\n const abortError = () => {\n reject(new AbortError());\n };\n\n const abortHandler = () => {\n clearTimeout(timeoutId);\n abortError();\n };\n\n if (signal?.aborted) {\n return abortError();\n }\n\n const timeoutId = setTimeout(resolve, ms);\n\n signal?.addEventListener('abort', abortHandler, { once: true });\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ACiCO,SAAS,MAAM,IAAY,EAAE,OAAO,IAAkB,CAAC,GAAkB;AAC9E,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,aAAa,MAAM;AACvB,aAAO,IAAI,WAAW,CAAC;AAAA,IACzB;AAEA,UAAM,eAAe,MAAM;AACzB,mBAAa,SAAS;AACtB,iBAAW;AAAA,IACb;AAEA,QAAI,iCAAQ,SAAS;AACnB,aAAO,WAAW;AAAA,IACpB;AAEA,UAAM,YAAY,WAAW,SAAS,EAAE;AAExC,qCAAQ,iBAAiB,SAAS,cAAc,EAAE,MAAM,KAAK;AAAA,EAC/D,CAAC;AACH;","names":[]}
|
package/dist/promise/index.mjs
CHANGED
package/package.json
CHANGED
package/dist/chunk-ASFOKYTY.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
uniqWith
|
|
3
|
-
} from "./chunk-2PFDLYQC.mjs";
|
|
4
|
-
|
|
5
|
-
// src/array/uniqBy.ts
|
|
6
|
-
function uniqBy(arr, mapper) {
|
|
7
|
-
return uniqWith(arr, (item1, item2) => mapper(item1) === mapper(item2));
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export {
|
|
11
|
-
uniqBy
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=chunk-ASFOKYTY.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/array/uniqBy.ts"],"sourcesContent":["import { uniqWith } from './uniqWith';\n\n/**\n * Returns a new array containing only the unique elements from the original array,\n * based on the values returned by the mapper function.\n *\n * @param {T[]} arr - The array to process.\n * @param {(item: T) => U} mapper - The function used to convert the array elements.\n * @returns {T[]} A new array containing only the unique elements from the original array, based on the values returned by the mapper function.\n *\n * @example\n * ```ts\n * uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor);\n * // [1.2, 2.1, 3.3, 5.7, 7.19]\n * ```\n */\nexport function uniqBy<T, U>(arr: readonly T[], mapper: (item: T) => U): T[] {\n return uniqWith(arr, (item1, item2) => mapper(item1) === mapper(item2));\n}\n"],"mappings":";;;;;AAgBO,SAAS,OAAa,KAAmB,QAA6B;AAC3E,SAAO,SAAS,KAAK,CAAC,OAAO,UAAU,OAAO,KAAK,MAAM,OAAO,KAAK,CAAC;AACxE;","names":[]}
|
package/dist/chunk-IJLQVGW4.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-IJLQVGW4.mjs.map
|
package/dist/chunk-ZBG3EYM3.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/promise/delay.ts"],"sourcesContent":["/**\n * Delays the execution of code for a specified number of milliseconds.\n *\n * This function returns a Promise that resolves after the specified delay, allowing you to use it\n * with async/await to pause execution.\n *\n * @param {number} ms - The number of milliseconds to delay.\n * @returns {Promise<void>} A Promise that resolves after the specified delay.\n *\n * @example\n * async function foo() {\n * console.log('Start');\n * await delay(1000); // Delays execution for 1 second\n * console.log('End');\n * }\n *\n * foo();\n */\nexport function delay(ms: number): Promise<void> {\n return new Promise(resolve => {\n setTimeout(resolve, ms);\n });\n}\n"],"mappings":";AAkBO,SAAS,MAAM,IAA2B;AAC/C,SAAO,IAAI,QAAQ,aAAW;AAC5B,eAAW,SAAS,EAAE;AAAA,EACxB,CAAC;AACH;","names":[]}
|
|
File without changes
|
|
File without changes
|