es-toolkit 1.10.1-dev.250 → 1.10.1-dev.252
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/dist/array/chunk.mjs +1 -1
- package/dist/array/compact.mjs +1 -1
- package/dist/array/countBy.mjs +1 -1
- package/dist/array/difference.mjs +1 -1
- package/dist/array/differenceBy.mjs +1 -1
- package/dist/array/differenceWith.mjs +1 -1
- package/dist/array/drop.mjs +1 -1
- package/dist/array/dropRight.mjs +1 -1
- package/dist/array/dropRightWhile.mjs +1 -1
- package/dist/array/dropWhile.mjs +1 -1
- package/dist/array/fill.mjs +1 -1
- package/dist/array/flatMap.mjs +1 -1
- package/dist/array/flatten.mjs +1 -1
- package/dist/array/flattenDeep.mjs +1 -1
- package/dist/array/forEachRight.mjs +1 -1
- package/dist/array/groupBy.mjs +1 -1
- package/dist/array/head.mjs +1 -1
- package/dist/array/index.mjs +20 -20
- package/dist/array/initial.mjs +1 -1
- package/dist/array/intersection.mjs +1 -1
- package/dist/array/intersectionBy.mjs +1 -1
- package/dist/array/intersectionWith.mjs +1 -1
- package/dist/array/keyBy.mjs +1 -1
- package/dist/array/last.mjs +1 -1
- package/dist/array/maxBy.mjs +1 -1
- package/dist/array/minBy.mjs +1 -1
- package/dist/array/orderBy.mjs +1 -1
- package/dist/array/partition.mjs +1 -1
- package/dist/array/sample.mjs +1 -1
- package/dist/array/sampleSize.mjs +1 -1
- package/dist/array/shuffle.mjs +1 -1
- package/dist/array/tail.mjs +1 -1
- package/dist/array/take.mjs +1 -1
- package/dist/array/takeRight.mjs +1 -1
- package/dist/array/takeRightWhile.mjs +1 -1
- package/dist/array/takeWhile.mjs +1 -1
- package/dist/array/toFilled.mjs +1 -1
- package/dist/array/union.mjs +1 -1
- package/dist/array/unionBy.mjs +1 -1
- package/dist/array/unionWith.mjs +1 -1
- package/dist/array/uniq.mjs +1 -1
- package/dist/array/uniqBy.mjs +1 -1
- package/dist/array/uniqWith.mjs +1 -1
- package/dist/array/unzip.mjs +1 -1
- package/dist/array/unzipWith.mjs +1 -1
- package/dist/array/without.mjs +1 -1
- package/dist/array/xor.mjs +1 -1
- package/dist/array/xorBy.mjs +1 -1
- package/dist/array/xorWith.mjs +1 -1
- package/dist/array/zip.mjs +1 -1
- package/dist/array/zipObject.mjs +1 -1
- package/dist/array/zipWith.mjs +1 -1
- package/dist/{chunk-2MM5EJJX.mjs → chunk-424M7IR7.mjs} +23 -2
- package/dist/chunk-4OIZM4HS.mjs +1 -0
- package/dist/chunk-F47GLYUU.mjs +1 -0
- package/dist/chunk-J3GE7DEU.mjs +22 -0
- package/dist/chunk-J3GE7DEU.mjs.map +1 -0
- package/dist/chunk-KIOYQRMQ.mjs +12 -0
- package/dist/chunk-KIOYQRMQ.mjs.map +1 -0
- package/dist/{chunk-QZITBKWX.mjs → chunk-U7V3G7CR.mjs} +2 -2
- package/dist/chunk-XT74R35S.mjs +1 -0
- package/dist/chunk-XWPCDIFC.mjs +18 -0
- package/dist/chunk-XWPCDIFC.mjs.map +1 -0
- package/dist/compat/index.d.mts +41 -3
- package/dist/compat/index.d.ts +41 -3
- package/dist/compat/index.js +57 -10
- package/dist/compat/index.js.map +1 -1
- package/dist/compat/index.mjs +68 -55
- package/dist/compat/index.mjs.map +1 -1
- package/dist/error/AbortError.mjs +1 -1
- package/dist/error/TimeoutError.d.mts +9 -0
- package/dist/error/TimeoutError.d.ts +9 -0
- package/dist/{string/startsWith.js → error/TimeoutError.js} +12 -9
- package/dist/error/TimeoutError.js.map +1 -0
- package/dist/error/TimeoutError.mjs +8 -0
- package/dist/error/index.d.mts +1 -0
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.js +12 -2
- package/dist/error/index.js.map +1 -1
- package/dist/error/index.mjs +7 -3
- package/dist/function/debounce.mjs +1 -1
- package/dist/function/index.mjs +4 -4
- package/dist/function/negate.mjs +1 -1
- package/dist/function/noop.mjs +1 -1
- package/dist/function/once.mjs +1 -1
- package/dist/function/throttle.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +47 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -57
- package/dist/math/clamp.mjs +1 -1
- package/dist/math/inRange.mjs +1 -1
- package/dist/math/index.mjs +7 -7
- package/dist/math/mean.mjs +1 -1
- package/dist/math/meanBy.mjs +1 -1
- package/dist/math/random.mjs +1 -1
- package/dist/math/randomInt.mjs +1 -1
- package/dist/math/range.mjs +1 -1
- package/dist/math/round.mjs +1 -1
- package/dist/math/sum.mjs +1 -1
- package/dist/math/sumBy.mjs +1 -1
- package/dist/object/clone.mjs +1 -1
- package/dist/object/get.mjs +1 -1
- package/dist/object/index.mjs +5 -5
- package/dist/object/invert.mjs +1 -1
- package/dist/object/omit.mjs +2 -2
- package/dist/object/omitBy.mjs +1 -1
- package/dist/object/pick.mjs +1 -1
- package/dist/object/pickBy.mjs +1 -1
- package/dist/predicate/index.mjs +1 -1
- package/dist/predicate/isEqual.mjs +1 -1
- package/dist/predicate/isNil.mjs +1 -1
- package/dist/predicate/isNotNil.mjs +1 -1
- package/dist/predicate/isNull.mjs +1 -1
- package/dist/predicate/isUndefined.mjs +1 -1
- package/dist/promise/delay.mjs +1 -1
- package/dist/promise/index.d.mts +1 -0
- package/dist/promise/index.d.ts +1 -0
- package/dist/promise/index.js +47 -2
- package/dist/promise/index.js.map +1 -1
- package/dist/promise/index.mjs +9 -3
- package/dist/promise/timeout.d.mts +10 -0
- package/dist/promise/timeout.d.ts +10 -0
- package/dist/promise/timeout.js +92 -0
- package/dist/promise/timeout.js.map +1 -0
- package/dist/promise/timeout.mjs +11 -0
- package/dist/promise/withTimeout.d.mts +22 -0
- package/dist/promise/withTimeout.d.ts +22 -0
- package/dist/promise/withTimeout.js +99 -0
- package/dist/promise/withTimeout.js.map +1 -0
- package/dist/promise/withTimeout.mjs +12 -0
- package/dist/promise/withTimeout.mjs.map +1 -0
- package/dist/string/camelCase.mjs +1 -1
- package/dist/string/capitalize.mjs +1 -1
- package/dist/string/index.d.mts +0 -2
- package/dist/string/index.d.ts +0 -2
- package/dist/string/index.js +2 -16
- package/dist/string/index.js.map +1 -1
- package/dist/string/index.mjs +9 -17
- package/dist/string/kebabCase.mjs +1 -1
- package/dist/string/lowerCase.mjs +1 -1
- package/dist/string/snakeCase.mjs +1 -1
- package/dist/string/startCase.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-ARZ5BDR6.mjs +0 -1
- package/dist/chunk-FZEZH22H.mjs +0 -1
- package/dist/chunk-SR5RPVRM.mjs +0 -9
- package/dist/chunk-SR5RPVRM.mjs.map +0 -1
- package/dist/chunk-YCTGSM4S.mjs +0 -1
- package/dist/chunk-ZFRI6VS4.mjs +0 -9
- package/dist/chunk-ZFRI6VS4.mjs.map +0 -1
- package/dist/string/endsWith.d.mts +0 -20
- package/dist/string/endsWith.d.ts +0 -20
- package/dist/string/endsWith.js +0 -33
- package/dist/string/endsWith.js.map +0 -1
- package/dist/string/endsWith.mjs +0 -8
- package/dist/string/startsWith.d.mts +0 -20
- package/dist/string/startsWith.d.ts +0 -20
- package/dist/string/startsWith.js.map +0 -1
- package/dist/string/startsWith.mjs +0 -8
- /package/dist/{chunk-2MM5EJJX.mjs.map → chunk-424M7IR7.mjs.map} +0 -0
- /package/dist/{chunk-ARZ5BDR6.mjs.map → chunk-4OIZM4HS.mjs.map} +0 -0
- /package/dist/{chunk-FZEZH22H.mjs.map → chunk-F47GLYUU.mjs.map} +0 -0
- /package/dist/{chunk-QZITBKWX.mjs.map → chunk-U7V3G7CR.mjs.map} +0 -0
- /package/dist/{chunk-YCTGSM4S.mjs.map → chunk-XT74R35S.mjs.map} +0 -0
- /package/dist/{string/endsWith.mjs.map → error/TimeoutError.mjs.map} +0 -0
- /package/dist/{string/startsWith.mjs.map → promise/timeout.mjs.map} +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a promise that rejects with a `TimeoutError` after a specified delay.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} ms - The delay duration in milliseconds.
|
|
5
|
+
* @returns {Promise<void>} A promise that rejects with a `TimeoutError` after the specified delay.
|
|
6
|
+
* @throws {TimeoutError} Throws a `TimeoutError` after the specified delay.
|
|
7
|
+
*/
|
|
8
|
+
declare function timeout(ms: number): Promise<never>;
|
|
9
|
+
|
|
10
|
+
export { timeout };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a promise that rejects with a `TimeoutError` after a specified delay.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} ms - The delay duration in milliseconds.
|
|
5
|
+
* @returns {Promise<void>} A promise that rejects with a `TimeoutError` after the specified delay.
|
|
6
|
+
* @throws {TimeoutError} Throws a `TimeoutError` after the specified delay.
|
|
7
|
+
*/
|
|
8
|
+
declare function timeout(ms: number): Promise<never>;
|
|
9
|
+
|
|
10
|
+
export { timeout };
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
var __async = (__this, __arguments, generator) => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
var fulfilled = (value) => {
|
|
22
|
+
try {
|
|
23
|
+
step(generator.next(value));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
reject(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var rejected = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.throw(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/promise/timeout.ts
|
|
41
|
+
var timeout_exports = {};
|
|
42
|
+
__export(timeout_exports, {
|
|
43
|
+
timeout: () => timeout
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(timeout_exports);
|
|
46
|
+
|
|
47
|
+
// src/error/AbortError.ts
|
|
48
|
+
var AbortError = class extends Error {
|
|
49
|
+
constructor(message = "The operation was aborted") {
|
|
50
|
+
super(message);
|
|
51
|
+
this.name = "AbortError";
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// src/promise/delay.ts
|
|
56
|
+
function delay(ms, { signal } = {}) {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
const abortError = () => {
|
|
59
|
+
reject(new AbortError());
|
|
60
|
+
};
|
|
61
|
+
const abortHandler = () => {
|
|
62
|
+
clearTimeout(timeoutId);
|
|
63
|
+
abortError();
|
|
64
|
+
};
|
|
65
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
66
|
+
return abortError();
|
|
67
|
+
}
|
|
68
|
+
const timeoutId = setTimeout(resolve, ms);
|
|
69
|
+
signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/error/TimeoutError.ts
|
|
74
|
+
var TimeoutError = class extends Error {
|
|
75
|
+
constructor(message = "The operation was timed out") {
|
|
76
|
+
super(message);
|
|
77
|
+
this.name = "TimeoutError";
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/promise/timeout.ts
|
|
82
|
+
function timeout(ms) {
|
|
83
|
+
return __async(this, null, function* () {
|
|
84
|
+
yield delay(ms);
|
|
85
|
+
throw new TimeoutError();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
timeout
|
|
91
|
+
});
|
|
92
|
+
//# sourceMappingURL=timeout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/promise/timeout.ts","../../src/error/AbortError.ts","../../src/promise/delay.ts","../../src/error/TimeoutError.ts"],"sourcesContent":["import { delay } from './delay.ts';\nimport { TimeoutError } from '../error/TimeoutError.ts';\n\n/**\n * Returns a promise that rejects with a `TimeoutError` after a specified delay.\n *\n * @param {number} ms - The delay duration in milliseconds.\n * @returns {Promise<void>} A promise that rejects with a `TimeoutError` after the specified delay.\n * @throws {TimeoutError} Throws a `TimeoutError` after the specified delay.\n */\nexport async function timeout(ms: number): Promise<never> {\n await delay(ms);\n throw new TimeoutError();\n}\n","/**\n * An error class representing an aborted operation.\n * @augments Error\n */\nexport 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.ts';\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","/**\n * An error class representing an timeout operation.\n * @augments Error\n */\nexport class TimeoutError extends Error {\n constructor(message = 'The operation was timed out') {\n super(message);\n this.name = 'TimeoutError';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;AC6BO,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;;;ACrDO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YAAY,UAAU,+BAA+B;AACnD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;AHCA,SAAsB,QAAQ,IAA4B;AAAA;AACxD,UAAM,MAAM,EAAE;AACd,UAAM,IAAI,aAAa;AAAA,EACzB;AAAA;","names":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executes an async function and enforces a timeout.
|
|
3
|
+
*
|
|
4
|
+
* If the promise does not resolve within the specified time,
|
|
5
|
+
* the timeout will trigger and the returned promise will be rejected.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @template T
|
|
9
|
+
* @param {() => Promise<T>} run - A function that returns a promise to be executed.
|
|
10
|
+
* @param {number} ms - The timeout duration in milliseconds.
|
|
11
|
+
* @returns {Promise<T>} A promise that resolves with the result of the `run` function or rejects if the timeout is reached.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* try {
|
|
15
|
+
* await withTimeout(() => {}, 1000); // Timeout exception after 1 second
|
|
16
|
+
* } catch (error) {
|
|
17
|
+
* console.error(error); // Will log 'TimeoutError'
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
declare function withTimeout<T>(run: () => Promise<T>, ms: number): Promise<T>;
|
|
21
|
+
|
|
22
|
+
export { withTimeout };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executes an async function and enforces a timeout.
|
|
3
|
+
*
|
|
4
|
+
* If the promise does not resolve within the specified time,
|
|
5
|
+
* the timeout will trigger and the returned promise will be rejected.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @template T
|
|
9
|
+
* @param {() => Promise<T>} run - A function that returns a promise to be executed.
|
|
10
|
+
* @param {number} ms - The timeout duration in milliseconds.
|
|
11
|
+
* @returns {Promise<T>} A promise that resolves with the result of the `run` function or rejects if the timeout is reached.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* try {
|
|
15
|
+
* await withTimeout(() => {}, 1000); // Timeout exception after 1 second
|
|
16
|
+
* } catch (error) {
|
|
17
|
+
* console.error(error); // Will log 'TimeoutError'
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
declare function withTimeout<T>(run: () => Promise<T>, ms: number): Promise<T>;
|
|
21
|
+
|
|
22
|
+
export { withTimeout };
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
var __async = (__this, __arguments, generator) => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
var fulfilled = (value) => {
|
|
22
|
+
try {
|
|
23
|
+
step(generator.next(value));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
reject(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var rejected = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.throw(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/promise/withTimeout.ts
|
|
41
|
+
var withTimeout_exports = {};
|
|
42
|
+
__export(withTimeout_exports, {
|
|
43
|
+
withTimeout: () => withTimeout
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(withTimeout_exports);
|
|
46
|
+
|
|
47
|
+
// src/error/AbortError.ts
|
|
48
|
+
var AbortError = class extends Error {
|
|
49
|
+
constructor(message = "The operation was aborted") {
|
|
50
|
+
super(message);
|
|
51
|
+
this.name = "AbortError";
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// src/promise/delay.ts
|
|
56
|
+
function delay(ms, { signal } = {}) {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
const abortError = () => {
|
|
59
|
+
reject(new AbortError());
|
|
60
|
+
};
|
|
61
|
+
const abortHandler = () => {
|
|
62
|
+
clearTimeout(timeoutId);
|
|
63
|
+
abortError();
|
|
64
|
+
};
|
|
65
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
66
|
+
return abortError();
|
|
67
|
+
}
|
|
68
|
+
const timeoutId = setTimeout(resolve, ms);
|
|
69
|
+
signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/error/TimeoutError.ts
|
|
74
|
+
var TimeoutError = class extends Error {
|
|
75
|
+
constructor(message = "The operation was timed out") {
|
|
76
|
+
super(message);
|
|
77
|
+
this.name = "TimeoutError";
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/promise/timeout.ts
|
|
82
|
+
function timeout(ms) {
|
|
83
|
+
return __async(this, null, function* () {
|
|
84
|
+
yield delay(ms);
|
|
85
|
+
throw new TimeoutError();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/promise/withTimeout.ts
|
|
90
|
+
function withTimeout(run, ms) {
|
|
91
|
+
return __async(this, null, function* () {
|
|
92
|
+
return Promise.race([run(), timeout(ms)]);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
+
0 && (module.exports = {
|
|
97
|
+
withTimeout
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=withTimeout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/promise/withTimeout.ts","../../src/error/AbortError.ts","../../src/promise/delay.ts","../../src/error/TimeoutError.ts","../../src/promise/timeout.ts"],"sourcesContent":["import { timeout } from './timeout.ts';\n\n/**\n * Executes an async function and enforces a timeout. \n * \n * If the promise does not resolve within the specified time,\n * the timeout will trigger and the returned promise will be rejected.\n *\n *\n * @template T \n * @param {() => Promise<T>} run - A function that returns a promise to be executed.\n * @param {number} ms - The timeout duration in milliseconds.\n * @returns {Promise<T>} A promise that resolves with the result of the `run` function or rejects if the timeout is reached.\n *\n * @example\n * try {\n * await withTimeout(() => {}, 1000); // Timeout exception after 1 second\n * } catch (error) {\n * console.error(error); // Will log 'TimeoutError'\n * }\n */\nexport async function withTimeout<T>(run: () => Promise<T>, ms: number): Promise<T> {\n return Promise.race([run(), timeout(ms) as T]);\n}\n","/**\n * An error class representing an aborted operation.\n * @augments Error\n */\nexport 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.ts';\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","/**\n * An error class representing an timeout operation.\n * @augments Error\n */\nexport class TimeoutError extends Error {\n constructor(message = 'The operation was timed out') {\n super(message);\n this.name = 'TimeoutError';\n }\n}\n","import { delay } from './delay.ts';\nimport { TimeoutError } from '../error/TimeoutError.ts';\n\n/**\n * Returns a promise that rejects with a `TimeoutError` after a specified delay.\n *\n * @param {number} ms - The delay duration in milliseconds.\n * @returns {Promise<void>} A promise that rejects with a `TimeoutError` after the specified delay.\n * @throws {TimeoutError} Throws a `TimeoutError` after the specified delay.\n */\nexport async function timeout(ms: number): Promise<never> {\n await delay(ms);\n throw new TimeoutError();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;AC6BO,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;;;ACrDO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YAAY,UAAU,+BAA+B;AACnD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ACCA,SAAsB,QAAQ,IAA4B;AAAA;AACxD,UAAM,MAAM,EAAE;AACd,UAAM,IAAI,aAAa;AAAA,EACzB;AAAA;;;AJQA,SAAsB,YAAe,KAAuB,IAAwB;AAAA;AAClF,WAAO,QAAQ,KAAK,CAAC,IAAI,GAAG,QAAQ,EAAE,CAAM,CAAC;AAAA,EAC/C;AAAA;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withTimeout
|
|
3
|
+
} from "../chunk-XWPCDIFC.mjs";
|
|
4
|
+
import "../chunk-J3GE7DEU.mjs";
|
|
5
|
+
import "../chunk-O64NE2P4.mjs";
|
|
6
|
+
import "../chunk-DXB7EZUQ.mjs";
|
|
7
|
+
import "../chunk-KIOYQRMQ.mjs";
|
|
8
|
+
import "../chunk-424M7IR7.mjs";
|
|
9
|
+
export {
|
|
10
|
+
withTimeout
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=withTimeout.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/string/index.d.mts
CHANGED
|
@@ -3,6 +3,4 @@ export { snakeCase } from './snakeCase.mjs';
|
|
|
3
3
|
export { kebabCase } from './kebabCase.mjs';
|
|
4
4
|
export { lowerCase } from './lowerCase.mjs';
|
|
5
5
|
export { startCase } from './startCase.mjs';
|
|
6
|
-
export { startsWith } from './startsWith.mjs';
|
|
7
|
-
export { endsWith } from './endsWith.mjs';
|
|
8
6
|
export { capitalize } from './capitalize.mjs';
|
package/dist/string/index.d.ts
CHANGED
|
@@ -3,6 +3,4 @@ export { snakeCase } from './snakeCase.js';
|
|
|
3
3
|
export { kebabCase } from './kebabCase.js';
|
|
4
4
|
export { lowerCase } from './lowerCase.js';
|
|
5
5
|
export { startCase } from './startCase.js';
|
|
6
|
-
export { startsWith } from './startsWith.js';
|
|
7
|
-
export { endsWith } from './endsWith.js';
|
|
8
6
|
export { capitalize } from './capitalize.js';
|
package/dist/string/index.js
CHANGED
|
@@ -22,12 +22,10 @@ var string_exports = {};
|
|
|
22
22
|
__export(string_exports, {
|
|
23
23
|
camelCase: () => camelCase,
|
|
24
24
|
capitalize: () => capitalize,
|
|
25
|
-
endsWith: () => endsWith,
|
|
26
25
|
kebabCase: () => kebabCase,
|
|
27
26
|
lowerCase: () => lowerCase,
|
|
28
27
|
snakeCase: () => snakeCase,
|
|
29
|
-
startCase: () => startCase
|
|
30
|
-
startsWith: () => startsWith
|
|
28
|
+
startCase: () => startCase
|
|
31
29
|
});
|
|
32
30
|
module.exports = __toCommonJS(string_exports);
|
|
33
31
|
|
|
@@ -87,25 +85,13 @@ function startCase(str) {
|
|
|
87
85
|
}
|
|
88
86
|
return result;
|
|
89
87
|
}
|
|
90
|
-
|
|
91
|
-
// src/string/startsWith.ts
|
|
92
|
-
var startsWith = (str, target, position = 0) => {
|
|
93
|
-
return str.startsWith(target, position);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// src/string/endsWith.ts
|
|
97
|
-
var endsWith = (str, target, position = str.length) => {
|
|
98
|
-
return str.endsWith(target, position);
|
|
99
|
-
};
|
|
100
88
|
// Annotate the CommonJS export names for ESM import in node:
|
|
101
89
|
0 && (module.exports = {
|
|
102
90
|
camelCase,
|
|
103
91
|
capitalize,
|
|
104
|
-
endsWith,
|
|
105
92
|
kebabCase,
|
|
106
93
|
lowerCase,
|
|
107
94
|
snakeCase,
|
|
108
|
-
startCase
|
|
109
|
-
startsWith
|
|
95
|
+
startCase
|
|
110
96
|
});
|
|
111
97
|
//# sourceMappingURL=index.js.map
|
package/dist/string/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/string/index.ts","../../src/string/capitalize.ts","../../src/string/_internal/getWords.ts","../../src/string/camelCase.ts","../../src/string/snakeCase.ts","../../src/string/kebabCase.ts","../../src/string/lowerCase.ts","../../src/string/startCase.ts","../../src/string/startsWith.ts","../../src/string/endsWith.ts"],"sourcesContent":["export { camelCase } from './camelCase.ts';\nexport { snakeCase } from './snakeCase.ts';\nexport { kebabCase } from './kebabCase.ts';\nexport { lowerCase } from './lowerCase.ts';\nexport { startCase } from './startCase.ts';\nexport { startsWith } from './startsWith.ts';\nexport { endsWith } from './endsWith.ts';\nexport { capitalize } from './capitalize.ts';\n","/**\n * Converts the first character of string to upper case and the remaining to lower case.\n *\n * @template T - Literal type of the string.\n * @param {T} str - The string to be converted to uppercase.\n * @returns {Capitalize<T>} - The capitalized string.\n *\n * @example\n * const result = capitalize('fred') // returns 'Fred'\n * const result2 = capitalize('FRED') // returns 'Fred'\n */\n\nexport const capitalize = <T extends string>(str: T): Capitalize<T> => {\n return (str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()) as Capitalize<T>;\n};\n","/**\n * Regular expression pattern to split strings into words for various case conversions\n *\n * This pattern matchs sequences of characters in a string, considering the following case:\n * - Sequences of two or more uppercase letters followed by an uppercase letter and lowercase letters or digits (for acronyms)\n * - Sequences of one uppercase letter optionally followed by lowercase letters and digits\n * - Single uppercase letters\n * - Sequences of digis\n *\n * The resulting match can be used to convert camelCase, snake_case, kebab-case, and other mixed formats into\n * a consistent format like snake case.\n *\n * @example\n * const matches = 'camelCaseHTTPRequest'.match(CASE_SPLIT_PATTERN);\n * // matchs: ['camel', 'Case', 'HTTP', 'Request']\n */\nconst CASE_SPLIT_PATTERN = /[A-Z]?[a-z]+|[0-9]+|[A-Z]+(?![a-z])/g;\n\nexport function getWords(str: string): string[] {\n return Array.from(str.match(CASE_SPLIT_PATTERN) ?? []);\n}\n","import { capitalize } from \"./capitalize.ts\";\nimport { getWords } from \"./_internal/getWords.ts\";\n\n/**\n * Converts a string to camel case.\n *\n * camel case is the naming convention in which each word is written in lowercase and separated by an underscore (_) character.\n *\n * @param {string} str - The string that is to be changed to camel case.\n * @returns {string} - The converted string to camel case.\n *\n * @example\n * const convertedStr1 = camelCase('camelCase') // returns 'camelCase'\n * const convertedStr2 = camelCase('some whitespace') // returns 'someWhitespace'\n * const convertedStr3 = camelCase('hyphen-text') // returns 'hyphenText'\n * const convertedStr4 = camelCase('HTTPRequest') // returns 'httpRequest'\n */\n\nexport function camelCase(str: string): string {\n const words = getWords(str);\n\n if (words.length === 0) {\n return \"\";\n }\n\n const [first, ...rest] = words;\n\n return `${first.toLowerCase()}${rest.map((word) => capitalize(word)).join(\"\")\n }`;\n}\n","import { getWords } from './_internal/getWords.ts';\n\n/**\n * Converts a string to snake case.\n *\n * Snake case is the naming convention in which each word is written in lowercase and separated by an underscore (_) character.\n *\n * @param {string} str - The string that is to be changed to snake case.\n * @returns {string} - The converted string to snake case.\n *\n * @example\n * const convertedStr1 = snakeCase('camelCase') // returns 'camel_case'\n * const convertedStr2 = snakeCase('some whitespace') // returns 'some_whitespace'\n * const convertedStr3 = snakeCase('hyphen-text') // returns 'hyphen_text'\n * const convertedStr4 = snakeCase('HTTPRequest') // returns 'http_request'\n */\n\nexport const snakeCase = (str: string): string => {\n const words = getWords(str);\n return words.map(word => word.toLowerCase()).join('_');\n};\n","import { getWords } from './_internal/getWords.ts';\n\n/**\n * Converts a string to kebab case.\n *\n * Kebab case is the naming convention in which each word is written in lowercase and separated by a dash (-) character.\n *\n * @param {string} str - The string that is to be changed to kebab case.\n * @returns {string} - The converted string to kebab case.\n *\n * @example\n * const convertedStr1 = kebabCase('camelCase') // returns 'camel-case'\n * const convertedStr2 = kebabCase('some whitespace') // returns 'some-whitespace'\n * const convertedStr3 = kebabCase('hyphen-text') // returns 'hyphen-text'\n * const convertedStr4 = kebabCase('HTTPRequest') // returns 'http-request'\n */\n\nexport const kebabCase = (str: string): string => {\n const words = getWords(str);\n return words.map(word => word.toLowerCase()).join('-');\n};\n","import { getWords } from './_internal/getWords.ts';\n\n/**\n * Converts a string to lower case.\n *\n * Lower case is the naming convention in which each word is written in lowercase and separated by an space ( ) character.\n *\n * @param {string} str - The string that is to be changed to lower case.\n * @returns {string} - The converted string to lower case.\n *\n * @example\n * const convertedStr1 = lowerCase('camelCase') // returns 'camel case'\n * const convertedStr2 = lowerCase('some whitespace') // returns 'some whitespace'\n * const convertedStr3 = lowerCase('hyphen-text') // returns 'hyphen text'\n * const convertedStr4 = lowerCase('HTTPRequest') // returns 'http request'\n */\nexport const lowerCase = (str: string): string => {\n const words = getWords(str);\n return words.map(word => word.toLowerCase()).join(' ');\n};\n","import { getWords } from './_internal/getWords.ts';\n\n/**\n * Converts the first character of each word in a string to uppercase and the remaining characters to lowercase.\n *\n * Start case is the naming convention in which each word is written with an initial capital letter.\n * @param {string} str - The string to convert.\n * @returns {string} The converted string.\n *\n * @example\n * const result1 = startCase('hello world'); // result will be 'Hello World'\n * const result2 = startCase('HELLO WORLD'); // result will be 'Hello World'\n * const result3 = startCase('hello-world'); // result will be 'Hello World'\n * const result4 = startCase('hello_world'); // result will be 'Hello World'\n */\nexport function startCase(str: string): string {\n const words = getWords(str.trim());\n let result = '';\n for (const word of words) {\n if (result) {\n result += ' ';\n }\n if (word === word.toUpperCase()) {\n result += word;\n } else {\n result += word[0].toUpperCase() + word.slice(1).toLowerCase();\n }\n }\n return result;\n}\n","/**\n * Checks if a string contains another string at the beginning of the string.\n *\n * Checks if one string startsWith another string. Optional position parameter to start searching from a certain index.\n *\n * @param {string} str - The string that might contain the target string.\n * @param {string} target - The string to search for.\n * @param {number} position - An optional offset to start searching in the str string\n * @returns {boolean} - True if the str string starts with the target string.\n *\n * @example\n * const isPrefix = startsWith('fooBar', 'foo') // returns true\n * const isPrefix = startsWith('fooBar', 'bar') // returns false\n * const isPrefix = startsWith('fooBar', 'abc') // returns false\n * const isPrefix = startsWith('fooBar', 'Bar', 2) // returns true\n * const isPrefix = startsWith('fooBar', 'Bar', 5) // returns false\n */\nexport const startsWith = (str: string, target: string, position: number = 0): boolean => {\n return str.startsWith(target, position);\n};\n","/**\n * Checks if a string contains another string at the end of the string.\n *\n * Checks if one string endsWith another string. Optional position parameter to offset searching before a certain index.\n *\n * @param {string} str - The string that might contain the target string.\n * @param {string} target - The string to search for.\n * @param {number} position - An optional position from the start to search up to this index\n * @returns {boolean} - True if the str string ends with the target string.\n *\n * @example\n * const isPrefix = endsWith('fooBar', 'foo') // returns true\n * const isPrefix = endsWith('fooBar', 'bar') // returns false\n * const isPrefix = endsWith('fooBar', 'abc') // returns false\n * const isPrefix = endsWith('fooBar', 'foo', 3) // returns true\n * const isPrefix = endsWith('fooBar', 'abc', 5) // returns false\n */\nexport const endsWith = (str: string, target: string, position: number = str.length): boolean => {\n return str.endsWith(target, position);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYO,IAAM,aAAa,CAAmB,QAA0B;AACrE,SAAQ,IAAI,OAAO,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC,EAAE,YAAY;AACjE;;;ACEA,IAAM,qBAAqB;AAEpB,SAAS,SAAS,KAAuB;AAlBhD;AAmBE,SAAO,MAAM,MAAK,SAAI,MAAM,kBAAkB,MAA5B,YAAiC,CAAC,CAAC;AACvD;;;ACFO,SAAS,UAAU,KAAqB;AAC7C,QAAM,QAAQ,SAAS,GAAG;AAE1B,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO;AAAA,EACT;AAEA,QAAM,CAAC,OAAO,GAAG,IAAI,IAAI;AAEzB,SAAO,GAAG,MAAM,YAAY,CAAC,GAAG,KAAK,IAAI,CAAC,SAAS,WAAW,IAAI,CAAC,EAAE,KAAK,EAAE,CAC1E;AACJ;;;ACZO,IAAM,YAAY,CAAC,QAAwB;AAChD,QAAM,QAAQ,SAAS,GAAG;AAC1B,SAAO,MAAM,IAAI,UAAQ,KAAK,YAAY,CAAC,EAAE,KAAK,GAAG;AACvD;;;ACHO,IAAM,YAAY,CAAC,QAAwB;AAChD,QAAM,QAAQ,SAAS,GAAG;AAC1B,SAAO,MAAM,IAAI,UAAQ,KAAK,YAAY,CAAC,EAAE,KAAK,GAAG;AACvD;;;ACJO,IAAM,YAAY,CAAC,QAAwB;AAChD,QAAM,QAAQ,SAAS,GAAG;AAC1B,SAAO,MAAM,IAAI,UAAQ,KAAK,YAAY,CAAC,EAAE,KAAK,GAAG;AACvD;;;ACJO,SAAS,UAAU,KAAqB;AAC7C,QAAM,QAAQ,SAAS,IAAI,KAAK,CAAC;AACjC,MAAI,SAAS;AACb,aAAW,QAAQ,OAAO;AACxB,QAAI,QAAQ;AACV,gBAAU;AAAA,IACZ;AACA,QAAI,SAAS,KAAK,YAAY,GAAG;AAC/B,gBAAU;AAAA,IACZ,OAAO;AACL,gBAAU,KAAK,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC,EAAE,YAAY;AAAA,IAC9D;AAAA,EACF;AACA,SAAO;AACT;;;ACZO,IAAM,aAAa,CAAC,KAAa,QAAgB,WAAmB,MAAe;AACxF,SAAO,IAAI,WAAW,QAAQ,QAAQ;AACxC;;;ACFO,IAAM,WAAW,CAAC,KAAa,QAAgB,WAAmB,IAAI,WAAoB;AAC/F,SAAO,IAAI,SAAS,QAAQ,QAAQ;AACtC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/string/index.ts","../../src/string/capitalize.ts","../../src/string/_internal/getWords.ts","../../src/string/camelCase.ts","../../src/string/snakeCase.ts","../../src/string/kebabCase.ts","../../src/string/lowerCase.ts","../../src/string/startCase.ts"],"sourcesContent":["export { camelCase } from './camelCase.ts';\nexport { snakeCase } from './snakeCase.ts';\nexport { kebabCase } from './kebabCase.ts';\nexport { lowerCase } from './lowerCase.ts';\nexport { startCase } from './startCase.ts';\nexport { capitalize } from './capitalize.ts';\n","/**\n * Converts the first character of string to upper case and the remaining to lower case.\n *\n * @template T - Literal type of the string.\n * @param {T} str - The string to be converted to uppercase.\n * @returns {Capitalize<T>} - The capitalized string.\n *\n * @example\n * const result = capitalize('fred') // returns 'Fred'\n * const result2 = capitalize('FRED') // returns 'Fred'\n */\n\nexport const capitalize = <T extends string>(str: T): Capitalize<T> => {\n return (str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()) as Capitalize<T>;\n};\n","/**\n * Regular expression pattern to split strings into words for various case conversions\n *\n * This pattern matchs sequences of characters in a string, considering the following case:\n * - Sequences of two or more uppercase letters followed by an uppercase letter and lowercase letters or digits (for acronyms)\n * - Sequences of one uppercase letter optionally followed by lowercase letters and digits\n * - Single uppercase letters\n * - Sequences of digis\n *\n * The resulting match can be used to convert camelCase, snake_case, kebab-case, and other mixed formats into\n * a consistent format like snake case.\n *\n * @example\n * const matches = 'camelCaseHTTPRequest'.match(CASE_SPLIT_PATTERN);\n * // matchs: ['camel', 'Case', 'HTTP', 'Request']\n */\nconst CASE_SPLIT_PATTERN = /[A-Z]?[a-z]+|[0-9]+|[A-Z]+(?![a-z])/g;\n\nexport function getWords(str: string): string[] {\n return Array.from(str.match(CASE_SPLIT_PATTERN) ?? []);\n}\n","import { capitalize } from \"./capitalize.ts\";\nimport { getWords } from \"./_internal/getWords.ts\";\n\n/**\n * Converts a string to camel case.\n *\n * camel case is the naming convention in which each word is written in lowercase and separated by an underscore (_) character.\n *\n * @param {string} str - The string that is to be changed to camel case.\n * @returns {string} - The converted string to camel case.\n *\n * @example\n * const convertedStr1 = camelCase('camelCase') // returns 'camelCase'\n * const convertedStr2 = camelCase('some whitespace') // returns 'someWhitespace'\n * const convertedStr3 = camelCase('hyphen-text') // returns 'hyphenText'\n * const convertedStr4 = camelCase('HTTPRequest') // returns 'httpRequest'\n */\n\nexport function camelCase(str: string): string {\n const words = getWords(str);\n\n if (words.length === 0) {\n return \"\";\n }\n\n const [first, ...rest] = words;\n\n return `${first.toLowerCase()}${rest.map((word) => capitalize(word)).join(\"\")\n }`;\n}\n","import { getWords } from './_internal/getWords.ts';\n\n/**\n * Converts a string to snake case.\n *\n * Snake case is the naming convention in which each word is written in lowercase and separated by an underscore (_) character.\n *\n * @param {string} str - The string that is to be changed to snake case.\n * @returns {string} - The converted string to snake case.\n *\n * @example\n * const convertedStr1 = snakeCase('camelCase') // returns 'camel_case'\n * const convertedStr2 = snakeCase('some whitespace') // returns 'some_whitespace'\n * const convertedStr3 = snakeCase('hyphen-text') // returns 'hyphen_text'\n * const convertedStr4 = snakeCase('HTTPRequest') // returns 'http_request'\n */\n\nexport const snakeCase = (str: string): string => {\n const words = getWords(str);\n return words.map(word => word.toLowerCase()).join('_');\n};\n","import { getWords } from './_internal/getWords.ts';\n\n/**\n * Converts a string to kebab case.\n *\n * Kebab case is the naming convention in which each word is written in lowercase and separated by a dash (-) character.\n *\n * @param {string} str - The string that is to be changed to kebab case.\n * @returns {string} - The converted string to kebab case.\n *\n * @example\n * const convertedStr1 = kebabCase('camelCase') // returns 'camel-case'\n * const convertedStr2 = kebabCase('some whitespace') // returns 'some-whitespace'\n * const convertedStr3 = kebabCase('hyphen-text') // returns 'hyphen-text'\n * const convertedStr4 = kebabCase('HTTPRequest') // returns 'http-request'\n */\n\nexport const kebabCase = (str: string): string => {\n const words = getWords(str);\n return words.map(word => word.toLowerCase()).join('-');\n};\n","import { getWords } from './_internal/getWords.ts';\n\n/**\n * Converts a string to lower case.\n *\n * Lower case is the naming convention in which each word is written in lowercase and separated by an space ( ) character.\n *\n * @param {string} str - The string that is to be changed to lower case.\n * @returns {string} - The converted string to lower case.\n *\n * @example\n * const convertedStr1 = lowerCase('camelCase') // returns 'camel case'\n * const convertedStr2 = lowerCase('some whitespace') // returns 'some whitespace'\n * const convertedStr3 = lowerCase('hyphen-text') // returns 'hyphen text'\n * const convertedStr4 = lowerCase('HTTPRequest') // returns 'http request'\n */\nexport const lowerCase = (str: string): string => {\n const words = getWords(str);\n return words.map(word => word.toLowerCase()).join(' ');\n};\n","import { getWords } from './_internal/getWords.ts';\n\n/**\n * Converts the first character of each word in a string to uppercase and the remaining characters to lowercase.\n *\n * Start case is the naming convention in which each word is written with an initial capital letter.\n * @param {string} str - The string to convert.\n * @returns {string} The converted string.\n *\n * @example\n * const result1 = startCase('hello world'); // result will be 'Hello World'\n * const result2 = startCase('HELLO WORLD'); // result will be 'Hello World'\n * const result3 = startCase('hello-world'); // result will be 'Hello World'\n * const result4 = startCase('hello_world'); // result will be 'Hello World'\n */\nexport function startCase(str: string): string {\n const words = getWords(str.trim());\n let result = '';\n for (const word of words) {\n if (result) {\n result += ' ';\n }\n if (word === word.toUpperCase()) {\n result += word;\n } else {\n result += word[0].toUpperCase() + word.slice(1).toLowerCase();\n }\n }\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYO,IAAM,aAAa,CAAmB,QAA0B;AACrE,SAAQ,IAAI,OAAO,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC,EAAE,YAAY;AACjE;;;ACEA,IAAM,qBAAqB;AAEpB,SAAS,SAAS,KAAuB;AAlBhD;AAmBE,SAAO,MAAM,MAAK,SAAI,MAAM,kBAAkB,MAA5B,YAAiC,CAAC,CAAC;AACvD;;;ACFO,SAAS,UAAU,KAAqB;AAC7C,QAAM,QAAQ,SAAS,GAAG;AAE1B,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO;AAAA,EACT;AAEA,QAAM,CAAC,OAAO,GAAG,IAAI,IAAI;AAEzB,SAAO,GAAG,MAAM,YAAY,CAAC,GAAG,KAAK,IAAI,CAAC,SAAS,WAAW,IAAI,CAAC,EAAE,KAAK,EAAE,CAC1E;AACJ;;;ACZO,IAAM,YAAY,CAAC,QAAwB;AAChD,QAAM,QAAQ,SAAS,GAAG;AAC1B,SAAO,MAAM,IAAI,UAAQ,KAAK,YAAY,CAAC,EAAE,KAAK,GAAG;AACvD;;;ACHO,IAAM,YAAY,CAAC,QAAwB;AAChD,QAAM,QAAQ,SAAS,GAAG;AAC1B,SAAO,MAAM,IAAI,UAAQ,KAAK,YAAY,CAAC,EAAE,KAAK,GAAG;AACvD;;;ACJO,IAAM,YAAY,CAAC,QAAwB;AAChD,QAAM,QAAQ,SAAS,GAAG;AAC1B,SAAO,MAAM,IAAI,UAAQ,KAAK,YAAY,CAAC,EAAE,KAAK,GAAG;AACvD;;;ACJO,SAAS,UAAU,KAAqB;AAC7C,QAAM,QAAQ,SAAS,IAAI,KAAK,CAAC;AACjC,MAAI,SAAS;AACb,aAAW,QAAQ,OAAO;AACxB,QAAI,QAAQ;AACV,gBAAU;AAAA,IACZ;AACA,QAAI,SAAS,KAAK,YAAY,GAAG;AAC/B,gBAAU;AAAA,IACZ,OAAO;AACL,gBAAU,KAAK,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC,EAAE,YAAY;AAAA,IAC9D;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
package/dist/string/index.mjs
CHANGED
|
@@ -1,38 +1,30 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-XT74R35S.mjs";
|
|
2
|
+
import {
|
|
3
|
+
lowerCase
|
|
4
|
+
} from "../chunk-5IKVJGHO.mjs";
|
|
5
|
+
import {
|
|
6
|
+
snakeCase
|
|
7
|
+
} from "../chunk-F3WCQQET.mjs";
|
|
2
8
|
import {
|
|
3
9
|
startCase
|
|
4
10
|
} from "../chunk-QXTNZR7B.mjs";
|
|
5
|
-
import {
|
|
6
|
-
startsWith
|
|
7
|
-
} from "../chunk-SR5RPVRM.mjs";
|
|
8
11
|
import {
|
|
9
12
|
camelCase
|
|
10
13
|
} from "../chunk-Y5V7UAZZ.mjs";
|
|
11
14
|
import {
|
|
12
15
|
capitalize
|
|
13
16
|
} from "../chunk-U56ZOM7L.mjs";
|
|
14
|
-
import {
|
|
15
|
-
endsWith
|
|
16
|
-
} from "../chunk-ZFRI6VS4.mjs";
|
|
17
17
|
import {
|
|
18
18
|
kebabCase
|
|
19
19
|
} from "../chunk-EYYZQFOP.mjs";
|
|
20
|
-
import {
|
|
21
|
-
lowerCase
|
|
22
|
-
} from "../chunk-5IKVJGHO.mjs";
|
|
23
|
-
import {
|
|
24
|
-
snakeCase
|
|
25
|
-
} from "../chunk-F3WCQQET.mjs";
|
|
26
20
|
import "../chunk-WVQ7YVRK.mjs";
|
|
27
|
-
import "../chunk-
|
|
21
|
+
import "../chunk-424M7IR7.mjs";
|
|
28
22
|
export {
|
|
29
23
|
camelCase,
|
|
30
24
|
capitalize,
|
|
31
|
-
endsWith,
|
|
32
25
|
kebabCase,
|
|
33
26
|
lowerCase,
|
|
34
27
|
snakeCase,
|
|
35
|
-
startCase
|
|
36
|
-
startsWith
|
|
28
|
+
startCase
|
|
37
29
|
};
|
|
38
30
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
3
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
4
|
-
"version": "1.10.1-dev.
|
|
4
|
+
"version": "1.10.1-dev.252+b31b3a69",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|
package/dist/chunk-ARZ5BDR6.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-ARZ5BDR6.mjs.map
|
package/dist/chunk-FZEZH22H.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-FZEZH22H.mjs.map
|
package/dist/chunk-SR5RPVRM.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/string/startsWith.ts"],"sourcesContent":["/**\n * Checks if a string contains another string at the beginning of the string.\n *\n * Checks if one string startsWith another string. Optional position parameter to start searching from a certain index.\n *\n * @param {string} str - The string that might contain the target string.\n * @param {string} target - The string to search for.\n * @param {number} position - An optional offset to start searching in the str string\n * @returns {boolean} - True if the str string starts with the target string.\n *\n * @example\n * const isPrefix = startsWith('fooBar', 'foo') // returns true\n * const isPrefix = startsWith('fooBar', 'bar') // returns false\n * const isPrefix = startsWith('fooBar', 'abc') // returns false\n * const isPrefix = startsWith('fooBar', 'Bar', 2) // returns true\n * const isPrefix = startsWith('fooBar', 'Bar', 5) // returns false\n */\nexport const startsWith = (str: string, target: string, position: number = 0): boolean => {\n return str.startsWith(target, position);\n};\n"],"mappings":";AAiBO,IAAM,aAAa,CAAC,KAAa,QAAgB,WAAmB,MAAe;AACxF,SAAO,IAAI,WAAW,QAAQ,QAAQ;AACxC;","names":[]}
|
package/dist/chunk-YCTGSM4S.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-YCTGSM4S.mjs.map
|
package/dist/chunk-ZFRI6VS4.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/string/endsWith.ts"],"sourcesContent":["/**\n * Checks if a string contains another string at the end of the string.\n *\n * Checks if one string endsWith another string. Optional position parameter to offset searching before a certain index.\n *\n * @param {string} str - The string that might contain the target string.\n * @param {string} target - The string to search for.\n * @param {number} position - An optional position from the start to search up to this index\n * @returns {boolean} - True if the str string ends with the target string.\n *\n * @example\n * const isPrefix = endsWith('fooBar', 'foo') // returns true\n * const isPrefix = endsWith('fooBar', 'bar') // returns false\n * const isPrefix = endsWith('fooBar', 'abc') // returns false\n * const isPrefix = endsWith('fooBar', 'foo', 3) // returns true\n * const isPrefix = endsWith('fooBar', 'abc', 5) // returns false\n */\nexport const endsWith = (str: string, target: string, position: number = str.length): boolean => {\n return str.endsWith(target, position);\n};\n"],"mappings":";AAiBO,IAAM,WAAW,CAAC,KAAa,QAAgB,WAAmB,IAAI,WAAoB;AAC/F,SAAO,IAAI,SAAS,QAAQ,QAAQ;AACtC;","names":[]}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if a string contains another string at the end of the string.
|
|
3
|
-
*
|
|
4
|
-
* Checks if one string endsWith another string. Optional position parameter to offset searching before a certain index.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} str - The string that might contain the target string.
|
|
7
|
-
* @param {string} target - The string to search for.
|
|
8
|
-
* @param {number} position - An optional position from the start to search up to this index
|
|
9
|
-
* @returns {boolean} - True if the str string ends with the target string.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* const isPrefix = endsWith('fooBar', 'foo') // returns true
|
|
13
|
-
* const isPrefix = endsWith('fooBar', 'bar') // returns false
|
|
14
|
-
* const isPrefix = endsWith('fooBar', 'abc') // returns false
|
|
15
|
-
* const isPrefix = endsWith('fooBar', 'foo', 3) // returns true
|
|
16
|
-
* const isPrefix = endsWith('fooBar', 'abc', 5) // returns false
|
|
17
|
-
*/
|
|
18
|
-
declare const endsWith: (str: string, target: string, position?: number) => boolean;
|
|
19
|
-
|
|
20
|
-
export { endsWith };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if a string contains another string at the end of the string.
|
|
3
|
-
*
|
|
4
|
-
* Checks if one string endsWith another string. Optional position parameter to offset searching before a certain index.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} str - The string that might contain the target string.
|
|
7
|
-
* @param {string} target - The string to search for.
|
|
8
|
-
* @param {number} position - An optional position from the start to search up to this index
|
|
9
|
-
* @returns {boolean} - True if the str string ends with the target string.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* const isPrefix = endsWith('fooBar', 'foo') // returns true
|
|
13
|
-
* const isPrefix = endsWith('fooBar', 'bar') // returns false
|
|
14
|
-
* const isPrefix = endsWith('fooBar', 'abc') // returns false
|
|
15
|
-
* const isPrefix = endsWith('fooBar', 'foo', 3) // returns true
|
|
16
|
-
* const isPrefix = endsWith('fooBar', 'abc', 5) // returns false
|
|
17
|
-
*/
|
|
18
|
-
declare const endsWith: (str: string, target: string, position?: number) => boolean;
|
|
19
|
-
|
|
20
|
-
export { endsWith };
|