@stryke/helpers 0.10.5 → 0.10.7
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 +24 -0
- package/README.md +1 -1
- package/dist/arg-identity.d.cts.map +1 -1
- package/dist/arg-identity.d.mts.map +1 -1
- package/dist/arg-identity.mjs.map +1 -1
- package/dist/convert/src/index.cjs +4 -0
- package/dist/convert/src/index.mjs +6 -0
- package/dist/convert/src/parse-type-definition.cjs +1 -0
- package/dist/convert/src/parse-type-definition.mjs +3 -0
- package/dist/convert/src/string-to-utf8-array.cjs +5 -0
- package/dist/convert/src/string-to-utf8-array.mjs +6 -0
- package/dist/convert/src/string-to-utf8-array.mjs.map +1 -0
- package/dist/convert/src/utf8-array-to-string.cjs +5 -0
- package/dist/convert/src/utf8-array-to-string.mjs +6 -0
- package/dist/convert/src/utf8-array-to-string.mjs.map +1 -0
- package/dist/debounce.cjs +5 -4
- package/dist/debounce.d.cts +4 -6
- package/dist/debounce.d.cts.map +1 -1
- package/dist/debounce.d.mts +4 -6
- package/dist/debounce.d.mts.map +1 -1
- package/dist/debounce.mjs +5 -4
- package/dist/debounce.mjs.map +1 -1
- package/dist/deep-clone.cjs +2 -1
- package/dist/deep-clone.d.cts.map +1 -1
- package/dist/deep-clone.d.mts.map +1 -1
- package/dist/deep-clone.mjs +2 -1
- package/dist/deep-clone.mjs.map +1 -1
- package/dist/delay.cjs +2 -1
- package/dist/delay.d.cts +1 -3
- package/dist/delay.d.cts.map +1 -1
- package/dist/delay.d.mts +1 -3
- package/dist/delay.d.mts.map +1 -1
- package/dist/delay.mjs +2 -1
- package/dist/delay.mjs.map +1 -1
- package/dist/filter-empty.d.cts.map +1 -1
- package/dist/filter-empty.d.mts.map +1 -1
- package/dist/filter-empty.mjs.map +1 -1
- package/dist/flatten-object.cjs +2 -1
- package/dist/flatten-object.d.cts.map +1 -1
- package/dist/flatten-object.d.mts.map +1 -1
- package/dist/flatten-object.mjs +2 -1
- package/dist/flatten-object.mjs.map +1 -1
- package/dist/get-field.cjs +14 -7
- package/dist/get-field.d.cts +123 -125
- package/dist/get-field.d.cts.map +1 -1
- package/dist/get-field.d.mts +123 -125
- package/dist/get-field.d.mts.map +1 -1
- package/dist/get-field.mjs +14 -7
- package/dist/get-field.mjs.map +1 -1
- package/dist/get-ordered-by.d.cts.map +1 -1
- package/dist/get-ordered-by.d.mts.map +1 -1
- package/dist/get-ordered-by.mjs.map +1 -1
- package/dist/identity.d.cts.map +1 -1
- package/dist/identity.d.mts.map +1 -1
- package/dist/identity.mjs.map +1 -1
- package/dist/is-equal.d.cts.map +1 -1
- package/dist/is-equal.d.mts.map +1 -1
- package/dist/is-equal.mjs.map +1 -1
- package/dist/match-sorter.cjs +2 -2
- package/dist/match-sorter.mjs +2 -2
- package/dist/match-sorter.mjs.map +1 -1
- package/dist/noop.d.cts.map +1 -1
- package/dist/noop.d.mts.map +1 -1
- package/dist/noop.mjs.map +1 -1
- package/dist/omit.mjs.map +1 -1
- package/dist/pick.mjs.map +1 -1
- package/dist/remove-accents.cjs +1 -3
- package/dist/remove-accents.d.cts.map +1 -1
- package/dist/remove-accents.d.mts.map +1 -1
- package/dist/remove-accents.mjs +1 -3
- package/dist/remove-accents.mjs.map +1 -1
- package/dist/remove-empty-items.d.cts.map +1 -1
- package/dist/remove-empty-items.d.mts.map +1 -1
- package/dist/remove-empty-items.mjs.map +1 -1
- package/dist/semaphore.cjs +10 -10
- package/dist/semaphore.d.cts +10 -10
- package/dist/semaphore.d.cts.map +1 -1
- package/dist/semaphore.d.mts +10 -10
- package/dist/semaphore.d.mts.map +1 -1
- package/dist/semaphore.mjs +10 -10
- package/dist/semaphore.mjs.map +1 -1
- package/dist/set-field.cjs +1 -1
- package/dist/set-field.d.cts.map +1 -1
- package/dist/set-field.d.mts.map +1 -1
- package/dist/set-field.mjs +1 -1
- package/dist/set-field.mjs.map +1 -1
- package/dist/throttle.d.cts.map +1 -1
- package/dist/throttle.d.mts.map +1 -1
- package/dist/throttle.mjs.map +1 -1
- package/dist/timeout.d.cts.map +1 -1
- package/dist/timeout.d.mts.map +1 -1
- package/dist/timeout.mjs.map +1 -1
- package/dist/to-deep-key.d.cts.map +1 -1
- package/dist/to-deep-key.d.mts.map +1 -1
- package/dist/to-deep-key.mjs.map +1 -1
- package/dist/type-checks/src/index.cjs +21 -0
- package/dist/type-checks/src/index.mjs +23 -0
- package/dist/type-checks/src/is-buffer.cjs +13 -0
- package/dist/type-checks/src/is-buffer.mjs +14 -0
- package/dist/type-checks/src/is-buffer.mjs.map +1 -0
- package/dist/type-checks/src/is-collection.cjs +1 -0
- package/dist/type-checks/src/is-collection.mjs +3 -0
- package/dist/type-checks/src/is-deep-key.cjs +6 -0
- package/dist/type-checks/src/is-deep-key.mjs +6 -0
- package/dist/type-checks/src/is-deep-key.mjs.map +1 -1
- package/dist/type-checks/src/is-function.cjs +3 -1
- package/dist/type-checks/src/is-function.mjs +1 -1
- package/dist/type-checks/src/is-object-index.cjs +6 -0
- package/dist/type-checks/src/is-object-index.mjs +6 -0
- package/dist/type-checks/src/is-object-index.mjs.map +1 -1
- package/dist/type-checks/src/is-plain-object.cjs +3 -2
- package/dist/type-checks/src/is-plain-object.mjs +3 -3
- package/dist/type-checks/src/is-plain-object.mjs.map +1 -1
- package/dist/type-checks/src/is-set-string.cjs +1 -1
- package/dist/type-checks/src/is-set-string.mjs +1 -1
- package/dist/type-checks/src/property-exists.cjs +1 -0
- package/dist/type-checks/src/property-exists.mjs +1 -1
- package/dist/type-checks/src/type-detect.cjs +15 -0
- package/dist/type-checks/src/type-detect.mjs +17 -0
- package/dist/type-checks/src/type-detect.mjs.map +1 -0
- package/dist/types/src/object.d.cts +1 -1
- package/dist/types/src/object.d.mts +1 -1
- package/dist/unflatten-object.cjs +1 -1
- package/dist/unflatten-object.d.cts +1 -1
- package/dist/unflatten-object.d.cts.map +1 -1
- package/dist/unflatten-object.d.mts +1 -1
- package/dist/unflatten-object.d.mts.map +1 -1
- package/dist/unflatten-object.mjs +1 -1
- package/dist/unflatten-object.mjs.map +1 -1
- package/dist/union.d.cts.map +1 -1
- package/dist/union.d.mts.map +1 -1
- package/dist/union.mjs.map +1 -1
- package/dist/with-timeout.d.cts.map +1 -1
- package/dist/with-timeout.d.mts.map +1 -1
- package/dist/with-timeout.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog for Stryke - Helpers
|
|
4
4
|
|
|
5
|
+
## [0.10.7](https://github.com/storm-software/stryke/releases/tag/helpers%400.10.7) (03/23/2026)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- **monorepo:** Update all repository projects to resolve linting failures ([e9fb597b](https://github.com/storm-software/stryke/commit/e9fb597b))
|
|
10
|
+
|
|
11
|
+
### Updated Dependencies
|
|
12
|
+
|
|
13
|
+
- Updated **type-checks** to **v0.6.0**
|
|
14
|
+
- Updated **convert** to **v0.6.57**
|
|
15
|
+
- Updated **types** to **v0.11.2**
|
|
16
|
+
|
|
17
|
+
## [0.10.6](https://github.com/storm-software/stryke/releases/tag/helpers%400.10.6) (03/16/2026)
|
|
18
|
+
|
|
19
|
+
### Miscellaneous
|
|
20
|
+
|
|
21
|
+
- **monorepo:** Added `README.md` workspace files ([515dc333](https://github.com/storm-software/stryke/commit/515dc333))
|
|
22
|
+
|
|
23
|
+
### Updated Dependencies
|
|
24
|
+
|
|
25
|
+
- Updated **type-checks** to **v0.5.41**
|
|
26
|
+
- Updated **convert** to **v0.6.56**
|
|
27
|
+
- Updated **types** to **v0.11.1**
|
|
28
|
+
|
|
5
29
|
## [0.10.5](https://github.com/storm-software/stryke/releases/tag/helpers%400.10.5) (03/16/2026)
|
|
6
30
|
|
|
7
31
|
### Updated Dependencies
|
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ This package is part of Storm Software's **🌩️ Stryke** monorepo. Stryke pac
|
|
|
28
28
|
|
|
29
29
|
<h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
|
|
30
30
|
|
|
31
|
-
[](https://github.com/storm-software/stryke) [](http://commitizen.github.io/cz-cli/)  
|
|
32
32
|
|
|
33
33
|
> [!IMPORTANT] Important
|
|
34
34
|
> This repository, and the apps, libraries, and tools contained within, is still in it's initial development phase. As a result, bugs and issues are expected with it's usage. When the main development phase completes, a proper release will be performed, the packages will be available through NPM (and other distributions), and this message will be removed. However, in the meantime, please feel free to report any issues you may come across.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arg-identity.d.cts","names":[],"sources":["../src/arg-identity.ts"],"sourcesContent":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"arg-identity.d.cts","names":[],"sources":["../src/arg-identity.ts"],"sourcesContent":[],"mappings":";;AA2BA;;;;;;;;iBAAgB,WAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arg-identity.d.mts","names":[],"sources":["../src/arg-identity.ts"],"sourcesContent":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"arg-identity.d.mts","names":[],"sources":["../src/arg-identity.ts"],"sourcesContent":[],"mappings":";;AA2BA;;;;;;;;iBAAgB,WAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arg-identity.mjs","names":[],"sources":["../src/arg-identity.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0
|
|
1
|
+
{"version":3,"file":"arg-identity.mjs","names":[],"sources":["../src/arg-identity.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * This method returns the first argument provided to it.\n *\n * @remarks\n * For more info, please see {@link https://lodash.com/docs/4.17.15#identity | the original Lodash documentation}.\n *\n * @param value - The value to return.\n * @returns The value provided.\n */\nexport function argIdentity(value: any) {\n return value;\n}\n"],"mappings":";;;;;;;;;;AA2BA,SAAgB,YAAY,OAAY;AACtC,QAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require('../../type-checks/src/index.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-to-utf8-array.mjs","names":[],"sources":["../../../../convert/src/string-to-utf8-array.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nconst encoder = new TextEncoder();\n\n/**\n * Convert a string to a utf-8 array\n *\n * @param input - The string to convert\n * @returns The converted utf-8 array\n */\nexport function stringToUtf8Array(input: string): Uint8Array {\n return encoder.encode(input);\n}\n"],"mappings":";AAkBA,MAAM,UAAU,IAAI,aAAa"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utf8-array-to-string.mjs","names":[],"sources":["../../../../convert/src/utf8-array-to-string.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nconst decoder = new TextDecoder();\n\n/**\n * Convert a utf-8 array to string\n *\n * @param input - Utf-8 Array\n * @returns The converted string\n */\nexport function utf8ArrayToString(\n input: NodeJS.ArrayBufferView | ArrayBuffer\n): string {\n return decoder.decode(input);\n}\n"],"mappings":";AAkBA,MAAM,UAAU,IAAI,aAAa"}
|
package/dist/debounce.cjs
CHANGED
|
@@ -30,13 +30,14 @@
|
|
|
30
30
|
* controller.abort();
|
|
31
31
|
* ```
|
|
32
32
|
*
|
|
33
|
-
* @param func - The function to debounce
|
|
34
|
-
* @param debounceMs - The number of milliseconds to delay
|
|
35
|
-
* @param options -
|
|
33
|
+
* @param func - The function to debounce
|
|
34
|
+
* @param debounceMs - The number of milliseconds to delay
|
|
35
|
+
* @param options - Optional configuration for the debounced function, including an AbortSignal to cancel the debounce
|
|
36
36
|
* @returns A new debounced function with a `cancel` method.
|
|
37
37
|
*/
|
|
38
|
-
function debounce(func, debounceMs,
|
|
38
|
+
function debounce(func, debounceMs, options = {}) {
|
|
39
39
|
let timeoutId = null;
|
|
40
|
+
const { signal } = options;
|
|
40
41
|
const debounced = ((...args) => {
|
|
41
42
|
if (timeoutId !== null) clearTimeout(timeoutId);
|
|
42
43
|
if (signal?.aborted) return;
|
package/dist/debounce.d.cts
CHANGED
|
@@ -32,14 +32,12 @@ interface DebounceOptions {
|
|
|
32
32
|
* controller.abort();
|
|
33
33
|
* ```
|
|
34
34
|
*
|
|
35
|
-
* @param func - The function to debounce
|
|
36
|
-
* @param debounceMs - The number of milliseconds to delay
|
|
37
|
-
* @param options -
|
|
35
|
+
* @param func - The function to debounce
|
|
36
|
+
* @param debounceMs - The number of milliseconds to delay
|
|
37
|
+
* @param options - Optional configuration for the debounced function, including an AbortSignal to cancel the debounce
|
|
38
38
|
* @returns A new debounced function with a `cancel` method.
|
|
39
39
|
*/
|
|
40
|
-
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, {
|
|
41
|
-
signal
|
|
42
|
-
}?: DebounceOptions): F & {
|
|
40
|
+
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, options?: DebounceOptions): F & {
|
|
43
41
|
cancel: () => void;
|
|
44
42
|
};
|
|
45
43
|
//#endregion
|
package/dist/debounce.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.d.cts","names":[],"sources":["../src/debounce.ts"],"sourcesContent":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"debounce.d.cts","names":[],"sources":["../src/debounce.ts"],"sourcesContent":[],"mappings":";UAkBiB,eAAA;EAAA,MAAA,CAAA,EACN,WADqB;AAuChC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,mDACR,iCAEG,kBACR"}
|
package/dist/debounce.d.mts
CHANGED
|
@@ -32,14 +32,12 @@ interface DebounceOptions {
|
|
|
32
32
|
* controller.abort();
|
|
33
33
|
* ```
|
|
34
34
|
*
|
|
35
|
-
* @param func - The function to debounce
|
|
36
|
-
* @param debounceMs - The number of milliseconds to delay
|
|
37
|
-
* @param options -
|
|
35
|
+
* @param func - The function to debounce
|
|
36
|
+
* @param debounceMs - The number of milliseconds to delay
|
|
37
|
+
* @param options - Optional configuration for the debounced function, including an AbortSignal to cancel the debounce
|
|
38
38
|
* @returns A new debounced function with a `cancel` method.
|
|
39
39
|
*/
|
|
40
|
-
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, {
|
|
41
|
-
signal
|
|
42
|
-
}?: DebounceOptions): F & {
|
|
40
|
+
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, options?: DebounceOptions): F & {
|
|
43
41
|
cancel: () => void;
|
|
44
42
|
};
|
|
45
43
|
//#endregion
|
package/dist/debounce.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.d.mts","names":[],"sources":["../src/debounce.ts"],"sourcesContent":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"debounce.d.mts","names":[],"sources":["../src/debounce.ts"],"sourcesContent":[],"mappings":";UAkBiB,eAAA;EAAA,MAAA,CAAA,EACN,WADqB;AAuChC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,mDACR,iCAEG,kBACR"}
|
package/dist/debounce.mjs
CHANGED
|
@@ -29,13 +29,14 @@
|
|
|
29
29
|
* controller.abort();
|
|
30
30
|
* ```
|
|
31
31
|
*
|
|
32
|
-
* @param func - The function to debounce
|
|
33
|
-
* @param debounceMs - The number of milliseconds to delay
|
|
34
|
-
* @param options -
|
|
32
|
+
* @param func - The function to debounce
|
|
33
|
+
* @param debounceMs - The number of milliseconds to delay
|
|
34
|
+
* @param options - Optional configuration for the debounced function, including an AbortSignal to cancel the debounce
|
|
35
35
|
* @returns A new debounced function with a `cancel` method.
|
|
36
36
|
*/
|
|
37
|
-
function debounce(func, debounceMs,
|
|
37
|
+
function debounce(func, debounceMs, options = {}) {
|
|
38
38
|
let timeoutId = null;
|
|
39
|
+
const { signal } = options;
|
|
39
40
|
const debounced = ((...args) => {
|
|
40
41
|
if (timeoutId !== null) clearTimeout(timeoutId);
|
|
41
42
|
if (signal?.aborted) return;
|
package/dist/debounce.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.mjs","names":["timeoutId: ReturnType<typeof setTimeout> | null"],"sources":["../src/debounce.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0
|
|
1
|
+
{"version":3,"file":"debounce.mjs","names":["timeoutId: ReturnType<typeof setTimeout> | null"],"sources":["../src/debounce.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nexport interface DebounceOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds\n * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`\n * method to cancel any pending execution.\n *\n * @example\n * ```typescript\n * const debouncedFunction = debounce(() => {\n * console.log('Function executed');\n * }, 1000);\n *\n * // Will log 'Function executed' after 1 second if not called again in that time\n * debouncedFunction();\n *\n * // Will not log anything as the previous call is canceled\n * debouncedFunction.cancel();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const signal = controller.signal;\n * const debouncedWithSignal = debounce(() => {\n * console.log('Function executed');\n * }, 1000, { signal });\n *\n * debouncedWithSignal();\n *\n * // Will cancel the debounced function call\n * controller.abort();\n * ```\n *\n * @param func - The function to debounce\n * @param debounceMs - The number of milliseconds to delay\n * @param options - Optional configuration for the debounced function, including an AbortSignal to cancel the debounce\n * @returns A new debounced function with a `cancel` method.\n */\nexport function debounce<F extends (...args: any[]) => void>(\n func: F,\n debounceMs: number,\n options: DebounceOptions = {}\n): F & { cancel: () => void } {\n let timeoutId: ReturnType<typeof setTimeout> | null = null;\n const { signal } = options;\n\n const debounced = ((...args: Parameters<F>) => {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n }\n\n if (signal?.aborted) {\n return;\n }\n\n timeoutId = setTimeout(() => {\n func(...args);\n timeoutId = null;\n }, debounceMs);\n }) as F & { cancel: () => void };\n\n const onAbort = () => {\n debounced.cancel();\n };\n\n debounced.cancel = () => {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n };\n\n signal?.addEventListener(\"abort\", onAbort, { once: true });\n\n return debounced;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,SAAgB,SACd,MACA,YACA,UAA2B,EAAE,EACD;CAC5B,IAAIA,YAAkD;CACtD,MAAM,EAAE,WAAW;CAEnB,MAAM,cAAc,GAAG,SAAwB;AAC7C,MAAI,cAAc,KAChB,cAAa,UAAU;AAGzB,MAAI,QAAQ,QACV;AAGF,cAAY,iBAAiB;AAC3B,QAAK,GAAG,KAAK;AACb,eAAY;KACX,WAAW;;CAGhB,MAAM,gBAAgB;AACpB,YAAU,QAAQ;;AAGpB,WAAU,eAAe;AACvB,MAAI,cAAc,MAAM;AACtB,gBAAa,UAAU;AACvB,eAAY;;;AAIhB,SAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,MAAM,CAAC;AAE1D,QAAO"}
|
package/dist/deep-clone.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_is_primitive = require('./type-checks/src/is-primitive.cjs');
|
|
2
2
|
const require_is_typed_array = require('./type-checks/src/is-typed-array.cjs');
|
|
3
|
+
require('./type-checks/src/index.cjs');
|
|
3
4
|
|
|
4
5
|
//#region src/deep-clone.ts
|
|
5
6
|
/**
|
|
@@ -66,7 +67,7 @@ function deepClone(obj) {
|
|
|
66
67
|
}
|
|
67
68
|
if (require_is_typed_array.isTypedArray(obj)) {
|
|
68
69
|
const result = new (Object.getPrototypeOf(obj)).constructor(obj.length);
|
|
69
|
-
for (const [i,
|
|
70
|
+
for (const [i, element] of obj.entries()) result[i] = deepClone(element);
|
|
70
71
|
return result;
|
|
71
72
|
}
|
|
72
73
|
if (obj instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && obj instanceof SharedArrayBuffer) return [...obj];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep-clone.d.cts","names":[],"sources":["../src/deep-clone.ts"],"sourcesContent":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"deep-clone.d.cts","names":[],"sources":["../src/deep-clone.ts"],"sourcesContent":[],"mappings":";KAoBY,cACV,MAAM,GAAG,aAAa,mBAAmB,IAAI,aAAa;AAD5D,KAGK,KAHO,CAAA,CAAA,EAAA,CAAQ,CAAA,GAGD,CAHC,SAGS,CAHT,GAAA,CAGc,CAHd,SAGwB,CAHxB,GAAA,IAAA,GAAA,KAAA,CAAA,GAAA,KAAA;KAKf,YAJG,CAAA,CAAA,CAAA,GAIe,CAJf,SAAA,CAAA,KAAA,CAAA,GAAA,KAAA,GAMJ,OANI,CAMI,CANJ,CAAA,SAAA,OAAA,GAAA,MAAA,GAAA,MAAA,GAAA,MAAA,GAOF,OAPE,CAOM,CAPN,CAAA,GAQF,CARE,UAAA,CAAA,GAAA,IAAA,EAAA,GAAA,EAAA,EAAA,GAAA,GAAA,IAAA,KAAA,GAUA,CAVA,SAAA,MAAA,GAWE,cAXF,CAWiB,CAXjB,CAAA,GAYE,OAZF,CAYU,CAZV,CAAA;KAcH,cAdmB,CAAA,UAAA,MAAA,CAAA,GAcgB,CAdhB,SAAA,CAAA,KAAA,EAAA,CAAA,EAAA,GAepB,OAfoB,CAeZ,CAfY,CAAA,SAAA,IAAA,GAgBlB,aAhBkB,CAgBJ,CAhBI,CAAA,GAiBlB,YAjBkB,CAiBL,CAjBK,CAAA,EAAA,GAkBpB,CAlBoB,SAkBV,GAlBU,CAAA,KAAA,EAAA,CAAA,GAmBlB,GAnBkB,CAmBd,YAnBc,CAmBD,CAnBC,CAAA,CAAA,GAoBlB,CApBkB,SAoBR,GApBQ,CAAA,KAAA,EAAA,EAAA,KAAA,EAAA,CAAA,GAqBhB,GArBgB,CAqBZ,YArBY,CAqBC,CArBD,CAAA,EAqBK,YArBL,CAqBkB,CArBlB,CAAA,CAAA,GAsBhB,CAt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A,EAAA,GAAA;EAAb,MAAA,EAAA,MAAA;CAAY,CAAA,GAAA,CA2DI,CA3DJ,CAAA,SAAA,CAEtD,KAAA,CAAc,GAAA,KAAA,GA6Df,CA7De,SAAA,SAAA,GAAA,EAAA,GAAA,MAAA,SA8DE,CA9DF,CAAA,QAAA,CAAA,GAAA,KAAA,GAAA,IAAA,GAAA,KAAA;KAmEd,OAnEwB,CAAA,QAAA,CAAA,GAoE3B,SApE2B,CAoEjB,QApEiB,EAAA,OAAA,CAAA,SAAA,IAAA,GAAA,OAAA,GAsEvB,SAtEuB,CAsEb,QAtEa,EAAA,MAAA,CAAA,SAAA,IAAA,GAAA,MAAA,GAwErB,SAxEqB,CAwEX,QAxEW,EAAA,MAAA,CAAA,SAAA,IAAA,GAAA,MAAA,GA0EnB,QA1EmB;KA4ExB,SA5E6B,CAAA,QAAA,EAAA,UA4EC,gBA5ED,CAAA,GAAA,CAAA,CAAA,GA4E0B,QA5E1B,SA4E2C,CA5E3C,GA6E9B,CA7E8B,SA6EpB,gBA7EoB,CAAA,KAAA,UAAA,CAAA,GA8E5B,QA9E4B,SAAA,SAAA,GAAA,KAAA,GAAA,IAAA,GAAA,KAAA,GAAA,KAAA;UAoFxB,gBApFkC,CAAA,CAAA,CAAA,CAAA;EAAC,OAAA,EAAA,GAAA,GAqF5B,CArF4B;AAAA;;;;;;;;;;;;;AAU5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBD,iBAqGA,SArGA,CAAA,CAAA,CAAA,CAAA,GAAA,EAqGkB,CArGlB,CAAA,EAqGsB,QArGtB,CAqG+B,CArG/B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep-clone.d.mts","names":[],"sources":["../src/deep-clone.ts"],"sourcesContent":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"deep-clone.d.mts","names":[],"sources":["../src/deep-clone.ts"],"sourcesContent":[],"mappings":";KAoBY,cACV,MAAM,GAAG,aAAa,mBA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,GAAA,IAAA,GAAA,KAAA;KAmEd,OAnEwB,CAAA,QAAA,CAAA,GAoE3B,SApE2B,CAoEjB,QApEiB,EAAA,OAAA,CAAA,SAAA,IAAA,GAAA,OAAA,GAsEvB,SAtEuB,CAsEb,QAtEa,EAAA,MAAA,CAAA,SAAA,IAAA,GAAA,MAAA,GAwErB,SAxEqB,CAwEX,QAxEW,EAAA,MAAA,CAAA,SAAA,IAAA,GAAA,MAAA,GA0EnB,QA1EmB;KA4ExB,SA5E6B,CAAA,QAAA,EAAA,UA4EC,gBA5ED,CAAA,GAAA,CAAA,CAAA,GA4E0B,QA5E1B,SA4E2C,CA5E3C,GA6E9B,CA7E8B,SA6EpB,gBA7EoB,CAAA,KAAA,UAAA,CAAA,GA8E5B,QA9E4B,SAAA,SAAA,GAAA,KAAA,GAAA,IAAA,GAAA,KAAA,GAAA,KAAA;UAoFxB,gBApFkC,CAAA,CAAA,CAAA,CAAA;EAAC,OAAA,EAAA,GAAA,GAqF5B,CArF4B;AAAA;;;;;;;;;;;;;AAU5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBD,iBAqGA,SArGA,CAAA,CAAA,CAAA,CAAA,GAAA,EAqGkB,CArGlB,CAAA,EAqGsB,QArGtB,CAqG+B,CArG/B,CAAA"}
|
package/dist/deep-clone.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isPrimitive } from "./type-checks/src/is-primitive.mjs";
|
|
2
2
|
import { isTypedArray } from "./type-checks/src/is-typed-array.mjs";
|
|
3
|
+
import "./type-checks/src/index.mjs";
|
|
3
4
|
|
|
4
5
|
//#region src/deep-clone.ts
|
|
5
6
|
/**
|
|
@@ -66,7 +67,7 @@ function deepClone(obj) {
|
|
|
66
67
|
}
|
|
67
68
|
if (isTypedArray(obj)) {
|
|
68
69
|
const result = new (Object.getPrototypeOf(obj)).constructor(obj.length);
|
|
69
|
-
for (const [i,
|
|
70
|
+
for (const [i, element] of obj.entries()) result[i] = deepClone(element);
|
|
70
71
|
return result;
|
|
71
72
|
}
|
|
72
73
|
if (obj instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && obj instanceof SharedArrayBuffer) return [...obj];
|
package/dist/deep-clone.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep-clone.mjs","names":[],"sources":["../src/deep-clone.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isPrimitive
|
|
1
|
+
{"version":3,"file":"deep-clone.mjs","names":[],"sources":["../src/deep-clone.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isPrimitive, isTypedArray } from \"@stryke/type-checks\";\n\nexport type Resolved<T> =\n Equal<T, ResolvedMain<T>> extends true ? T : ResolvedMain<T>;\n\ntype Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;\n\ntype ResolvedMain<T> = T extends [never]\n ? never // (special trick for jsonable | null) type\n : ValueOf<T> extends boolean | number | bigint | string\n ? ValueOf<T>\n : T extends (...args: any[]) => any\n ? never\n : T extends object\n ? ResolvedObject<T>\n : ValueOf<T>;\n\ntype ResolvedObject<T extends object> = T extends (infer U)[]\n ? IsTuple<T> extends true\n ? ResolvedTuple<T>\n : ResolvedMain<U>[]\n : T extends Set<infer U>\n ? Set<ResolvedMain<U>>\n : T extends Map<infer K, infer V>\n ? Map<ResolvedMain<K>, ResolvedMain<V>>\n : T extends WeakSet<any> | WeakMap<any, any>\n ? never\n : T extends\n | Date\n | Uint8Array\n | Uint8ClampedArray\n | Uint16Array\n | Uint32Array\n | BigUint64Array\n | Int8Array\n | Int16Array\n | Int32Array\n | BigInt64Array\n | Float32Array\n | Float64Array\n | ArrayBuffer\n | SharedArrayBuffer\n | DataView\n | Blob\n | File\n ? T\n : {\n [P in keyof T]: ResolvedMain<T[P]>;\n };\n\ntype ResolvedTuple<T extends readonly any[]> = T extends []\n ? []\n : T extends [infer F]\n ? [ResolvedMain<F>]\n : T extends [infer F, ...infer Rest extends readonly any[]]\n ? [ResolvedMain<F>, ...ResolvedTuple<Rest>]\n : T extends [(infer F)?]\n ? [ResolvedMain<F>?]\n : T extends [(infer F)?, ...infer Rest extends readonly any[]]\n ? [ResolvedMain<F>?, ...ResolvedTuple<Rest>]\n : [];\n\ntype IsTuple<T extends readonly any[] | { length: number }> = [T] extends [\n never\n]\n ? false\n : T extends readonly any[]\n ? number extends T[\"length\"]\n ? false\n : true\n : false;\n\ntype ValueOf<Instance> =\n IsValueOf<Instance, boolean> extends true\n ? boolean\n : IsValueOf<Instance, number> extends true\n ? number\n : IsValueOf<Instance, string> extends true\n ? string\n : Instance;\n\ntype IsValueOf<Instance, O extends ValueOfInterface<any>> = Instance extends O\n ? O extends ValueOfInterface<infer Primitive>\n ? Instance extends Primitive\n ? false\n : true // not Primitive, but Object\n : false // cannot be\n : false;\n\ninterface ValueOfInterface<T> {\n valueOf: () => T;\n}\n\n/**\n * Creates a deep clone of the given object.\n *\n * @remarks\n * This function creates a deep clone of the given object, including nested objects and arrays. The resulting output will be of type `Resolved<T>`, which is a type that resolves to the most specific type possible for the given input type `T`. **If you are just looking for a way to copy an object deeply, use {@link deepCopy} instead.**\n *\n * @example\n * ```typescript\n * // Clone a primitive values\n * const num = 29;\n * const clonedNum = clone(num);\n * console.log(clonedNum); // 29\n * console.log(clonedNum === num) ; // true\n *\n * // Clone an array\n * const arr = [1, 2, 3];\n * const clonedArr = clone(arr);\n * console.log(clonedArr); // [1, 2, 3]\n * console.log(clonedArr === arr); // false\n *\n * // Clone an array with nested objects\n * const arr = [1, { a: 1 }, [1, 2, 3]];\n * const clonedArr = clone(arr);\n * arr[1].a = 2;\n * console.log(arr); // [2, { a: 2 }, [1, 2, 3]]\n * console.log(clonedArr); // [1, { a: 1 }, [1, 2, 3]]\n * console.log(clonedArr === arr); // false\n *\n * // Clone an object\n * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };\n * const clonedObj = clone(obj);\n * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }\n * console.log(clonedObj === obj); // false\n *\n *\n * // Clone an object with nested objects\n * const obj = { a: 1, b: { c: 1 } };\n * const clonedObj = clone(obj);\n * obj.b.c = 2;\n * console.log(obj); // { a: 1, b: { c: 2 } }\n * console.log(clonedObj); // { a: 1, b: { c: 1 } }\n * console.log(clonedObj === obj); // false\n * ```\n *\n * @param obj - The object to clone.\n * @returns A deep clone of the given object.\n */\nexport function deepClone<T>(obj: T): Resolved<T> {\n if (isPrimitive(obj)) {\n return obj as Resolved<T>;\n }\n\n if (Array.isArray(obj)) {\n return obj.map(item => deepClone(item)) as Resolved<T>;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as Resolved<T>;\n }\n\n if (obj instanceof RegExp) {\n return new RegExp(obj.source, obj.flags) as Resolved<T>;\n }\n\n if (obj instanceof Map) {\n const result = new Map();\n for (const [key, value] of obj.entries()) {\n result.set(key, deepClone(value));\n }\n return result as Resolved<T>;\n }\n\n if (obj instanceof Set) {\n const result = new Set();\n for (const value of obj.values()) {\n result.add(deepClone(value));\n }\n return result as Resolved<T>;\n }\n\n if (isTypedArray(obj)) {\n // eslint-disable-next-line ts/no-unsafe-call\n const result = new (Object.getPrototypeOf(obj).constructor)(obj.length);\n\n for (const [i, element] of obj.entries()) {\n result[i] = deepClone(element);\n }\n return result as Resolved<T>;\n }\n\n if (\n obj instanceof ArrayBuffer ||\n (typeof SharedArrayBuffer !== \"undefined\" &&\n obj instanceof SharedArrayBuffer)\n ) {\n return [...(obj as any)] as Resolved<T>;\n }\n\n if (obj instanceof DataView) {\n const result = new DataView([...(obj.buffer as any)] as any);\n cloneDeepHelper(obj, result);\n return result as Resolved<T>;\n }\n\n // For legacy NodeJS support\n if (typeof File !== \"undefined\" && obj instanceof File) {\n const result = new File([obj], obj.name, { type: obj.type });\n cloneDeepHelper(obj, result);\n return result as Resolved<T>;\n }\n\n if (obj instanceof Blob) {\n const result = new Blob([obj], { type: obj.type });\n cloneDeepHelper(obj, result);\n return result as Resolved<T>;\n }\n\n if (obj instanceof Error) {\n const result = new (obj.constructor as new () => Error)();\n result.message = obj.message;\n result.name = obj.name;\n result.stack = obj.stack;\n result.cause = obj.cause;\n cloneDeepHelper(obj, result);\n return result as Resolved<T>;\n }\n\n if (typeof obj === \"object\" && obj !== null) {\n const result = {};\n cloneDeepHelper(obj, result);\n return result as Resolved<T>;\n }\n\n return obj as Resolved<T>;\n}\n\nfunction cloneDeepHelper(obj: any, clonedObj: any): void {\n const keys = Object.keys(obj);\n\n for (const key of keys) {\n const descriptor = Object.getOwnPropertyDescriptor(obj, key);\n\n if (descriptor?.writable || descriptor?.set) {\n clonedObj[key] = deepClone(obj[key]);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8JA,SAAgB,UAAa,KAAqB;AAChD,KAAI,YAAY,IAAI,CAClB,QAAO;AAGT,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,KAAI,SAAQ,UAAU,KAAK,CAAC;AAGzC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AI;AACrB,SAAO,OAAO,IAAI;AAClB,SAAO,QAAQ,IAAI;AACnB,SAAO,QAAQ,IAAI;AACnB,kBAAgB,KAAK,OAAO;AAC5B,SAAO;;AAGT,KAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM;EAC3C,MAAM,SAAS,EAAE;AACjB,kBAAgB,KAAK,OAAO;AAC5B,SAAO;;AAGT,QAAO;;AAGT,SAAS,gBAAgB,KAAU,WAAsB;CACvD,MAAM,OAAO,OAAO,KAAK,IAAI;AAE7B,MAAK,MAAM,OAAO,MAAM;EACtB,MAAM,aAAa,OAAO,yBAAyB,KAAK,IAAI;AAE5D,MAAI,YAAY,YAAY,YAAY,IACtC,WAAU,OAAO,UAAU,IAAI,KAAK"}
|
package/dist/delay.cjs
CHANGED
|
@@ -34,7 +34,8 @@ const require_errors = require('./errors.cjs');
|
|
|
34
34
|
* @param options - The options object.
|
|
35
35
|
* @returns A Promise that resolves after the specified delay.
|
|
36
36
|
*/
|
|
37
|
-
async function delay(ms,
|
|
37
|
+
async function delay(ms, options = {}) {
|
|
38
|
+
const { signal } = options;
|
|
38
39
|
return new Promise((resolve, reject) => {
|
|
39
40
|
const abortError = () => {
|
|
40
41
|
reject(new require_errors.AbortError());
|
package/dist/delay.d.cts
CHANGED
|
@@ -35,9 +35,7 @@ interface DelayOptions {
|
|
|
35
35
|
* @param options - The options object.
|
|
36
36
|
* @returns A Promise that resolves after the specified delay.
|
|
37
37
|
*/
|
|
38
|
-
declare function delay(ms: number,
|
|
39
|
-
signal
|
|
40
|
-
}?: DelayOptions): Promise<void>;
|
|
38
|
+
declare function delay(ms: number, options?: DelayOptions): Promise<void>;
|
|
41
39
|
/**
|
|
42
40
|
* Delays the execution of code for a specified number of milliseconds.
|
|
43
41
|
*
|
package/dist/delay.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delay.d.cts","names":[],"sources":["../src/delay.ts"],"sourcesContent":[],"mappings":";UAoBU,YAAA;EAAA,MAAA,CAAA,EACC,WADW;AAqCtB
|
|
1
|
+
{"version":3,"file":"delay.d.cts","names":[],"sources":["../src/delay.ts"],"sourcesContent":[],"mappings":";UAoBU,YAAA;EAAA,MAAA,CAAA,EACC,WADW;AAqCtB;AA6DA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA7DsB,KAAA,uBAEX,eACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0DmB,KAAA,uBAA4B,eAAe"}
|
package/dist/delay.d.mts
CHANGED
|
@@ -35,9 +35,7 @@ interface DelayOptions {
|
|
|
35
35
|
* @param options - The options object.
|
|
36
36
|
* @returns A Promise that resolves after the specified delay.
|
|
37
37
|
*/
|
|
38
|
-
declare function delay(ms: number,
|
|
39
|
-
signal
|
|
40
|
-
}?: DelayOptions): Promise<void>;
|
|
38
|
+
declare function delay(ms: number, options?: DelayOptions): Promise<void>;
|
|
41
39
|
/**
|
|
42
40
|
* Delays the execution of code for a specified number of milliseconds.
|
|
43
41
|
*
|
package/dist/delay.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delay.d.mts","names":[],"sources":["../src/delay.ts"],"sourcesContent":[],"mappings":";UAoBU,YAAA;EAAA,MAAA,CAAA,EACC,WADW;AAqCtB
|
|
1
|
+
{"version":3,"file":"delay.d.mts","names":[],"sources":["../src/delay.ts"],"sourcesContent":[],"mappings":";UAoBU,YAAA;EAAA,MAAA,CAAA,EACC,WADW;AAqCtB;AA6DA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA7DsB,KAAA,uBAEX,eACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0DmB,KAAA,uBAA4B,eAAe"}
|
package/dist/delay.mjs
CHANGED
|
@@ -34,7 +34,8 @@ import { AbortError } from "./errors.mjs";
|
|
|
34
34
|
* @param options - The options object.
|
|
35
35
|
* @returns A Promise that resolves after the specified delay.
|
|
36
36
|
*/
|
|
37
|
-
async function delay(ms,
|
|
37
|
+
async function delay(ms, options = {}) {
|
|
38
|
+
const { signal } = options;
|
|
38
39
|
return new Promise((resolve, reject) => {
|
|
39
40
|
const abortError = () => {
|
|
40
41
|
reject(new AbortError());
|
package/dist/delay.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delay.mjs","names":[],"sources":["../src/delay.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { AbortError } from \"./errors\";\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 * @example\n * ```typescript\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 * ```\n *\n * @param ms - The number of milliseconds to delay.\n * @param options - The options object.\n * @returns A Promise that resolves after the specified delay.\n */\nexport async function delay(\n ms: number,\n
|
|
1
|
+
{"version":3,"file":"delay.mjs","names":[],"sources":["../src/delay.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { AbortError } from \"./errors\";\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 * @example\n * ```typescript\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 * ```\n *\n * @param ms - The number of milliseconds to delay.\n * @param options - The options object.\n * @returns A Promise that resolves after the specified delay.\n */\nexport async function delay(\n ms: number,\n options: DelayOptions = {}\n): Promise<void> {\n const { signal } = options;\n\n return new Promise((resolve, reject) => {\n const abortError = () => {\n reject(new AbortError());\n };\n\n const abortHandler = () => {\n // eslint-disable-next-line ts/no-use-before-define\n clearTimeout(timeoutId);\n abortError();\n };\n\n if (signal?.aborted) {\n // eslint-disable-next-line no-promise-executor-return\n return abortError();\n }\n\n const timeoutId = setTimeout(resolve, ms);\n\n signal?.addEventListener(\"abort\", abortHandler, { once: true });\n });\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 * @example\n * ```typescript\n * async function foo() {\n * console.log('Start');\n * await sleep(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 sleep(100, { signal });\n * } catch (error) {\n * console.error(error); // Will log 'AbortError'\n * }\n * }\n * ```\n *\n * @param ms - The number of milliseconds to sleep.\n * @param options - The options object.\n * @returns A Promise that resolves after the specified sleep.\n */\nexport async function sleep(ms: number, options?: DelayOptions): Promise<void> {\n return delay(ms, options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,eAAsB,MACpB,IACA,UAAwB,EAAE,EACX;CACf,MAAM,EAAE,WAAW;AAEnB,QAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,mBAAmB;AACvB,UAAO,IAAI,YAAY,CAAC;;EAG1B,MAAM,qBAAqB;AAEzB,gBAAa,UAAU;AACvB,eAAY;;AAGd,MAAI,QAAQ,QAEV,QAAO,YAAY;EAGrB,MAAM,YAAY,WAAW,SAAS,GAAG;AAEzC,UAAQ,iBAAiB,SAAS,cAAc,EAAE,MAAM,MAAM,CAAC;GAC/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCJ,eAAsB,MAAM,IAAY,SAAuC;AAC7E,QAAO,MAAM,IAAI,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter-empty.d.cts","names":[],"sources":["../src/filter-empty.ts"],"sourcesContent":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"filter-empty.d.cts","names":[],"sources":["../src/filter-empty.ts"],"sourcesContent":[],"mappings":";cAoBa,2BAA2B,4BAA+B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter-empty.d.mts","names":[],"sources":["../src/filter-empty.ts"],"sourcesContent":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"filter-empty.d.mts","names":[],"sources":["../src/filter-empty.ts"],"sourcesContent":[],"mappings":";cAoBa,2BAA2B,4BAA+B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter-empty.mjs","names":[],"sources":["../src/filter-empty.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0
|
|
1
|
+
{"version":3,"file":"filter-empty.mjs","names":[],"sources":["../src/filter-empty.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isEmpty } from \"@stryke/type-checks/is-empty\";\n\nexport const filterEmpty = <T>(values: (T | null | undefined)[] = []): T[] =>\n values.filter(value => !isEmpty(value)) as T[];\n"],"mappings":";;;AAoBA,MAAa,eAAkB,SAAmC,EAAE,KAClE,OAAO,QAAO,UAAS,CAAC,QAAQ,MAAM,CAAC"}
|
package/dist/flatten-object.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_is_plain_object = require('./type-checks/src/is-plain-object.cjs');
|
|
2
|
+
require('./type-checks/src/index.cjs');
|
|
2
3
|
|
|
3
4
|
//#region src/flatten-object.ts
|
|
4
5
|
/**
|
|
@@ -38,7 +39,7 @@ function flattenObjectImpl(object, prefix = "") {
|
|
|
38
39
|
const value = object[key];
|
|
39
40
|
const prefixedKey = prefix ? `${prefix}.${key}` : key;
|
|
40
41
|
if (require_is_plain_object.isPlainObject(value) && Object.keys(value).length > 0) Object.assign(result, flattenObjectImpl(value, prefixedKey));
|
|
41
|
-
else if (Array.isArray(value)) for (const [index,
|
|
42
|
+
else if (Array.isArray(value)) for (const [index, element] of value.entries()) result[`${prefixedKey}.${index}`] = element;
|
|
42
43
|
else result[prefixedKey] = value;
|
|
43
44
|
}
|
|
44
45
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatten-object.d.cts","names":[],"sources":["../src/flatten-object.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"flatten-object.d.cts","names":[],"sources":["../src/flatten-object.ts"],"sourcesContent":[],"mappings":";;;;;;AAgDA;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,8BACE,sBAAsB,uDAE3B,QAAQ,WAAW,UAAU,SAAS,qBAClC,QAAQ,WAAW,UAAU,SAAS,iBAC7C,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatten-object.d.mts","names":[],"sources":["../src/flatten-object.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"flatten-object.d.mts","names":[],"sources":["../src/flatten-object.ts"],"sourcesContent":[],"mappings":";;;;;;AAgDA;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,8BACE,sBAAsB,uDAE3B,QAAQ,WAAW,UAAU,SAAS,qBAClC,QAAQ,WAAW,UAAU,SAAS,iBAC7C,UAAU"}
|
package/dist/flatten-object.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isPlainObject } from "./type-checks/src/is-plain-object.mjs";
|
|
2
|
+
import "./type-checks/src/index.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/flatten-object.ts
|
|
4
5
|
/**
|
|
@@ -38,7 +39,7 @@ function flattenObjectImpl(object, prefix = "") {
|
|
|
38
39
|
const value = object[key];
|
|
39
40
|
const prefixedKey = prefix ? `${prefix}.${key}` : key;
|
|
40
41
|
if (isPlainObject(value) && Object.keys(value).length > 0) Object.assign(result, flattenObjectImpl(value, prefixedKey));
|
|
41
|
-
else if (Array.isArray(value)) for (const [index,
|
|
42
|
+
else if (Array.isArray(value)) for (const [index, element] of value.entries()) result[`${prefixedKey}.${index}`] = element;
|
|
42
43
|
else result[prefixedKey] = value;
|
|
43
44
|
}
|
|
44
45
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatten-object.mjs","names":[],"sources":["../src/flatten-object.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0
|
|
1
|
+
{"version":3,"file":"flatten-object.mjs","names":[],"sources":["../src/flatten-object.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isPlainObject } from \"@stryke/type-checks\";\nimport type { DeepKey, DeepValue } from \"@stryke/types\";\n\n/**\n * Flattens a nested object into a single level object with dot-separated keys.\n *\n * @example\n * ```typescript\n * const nestedObject = {\n * a: {\n * b: {\n * c: 1\n * }\n * },\n * d: [2, 3]\n * };\n *\n * const flattened = flattenObject(nestedObject);\n * console.log(flattened);\n * // Output:\n * // {\n * // 'a.b.c': 1,\n * // 'd.0': 2,\n * // 'd.1': 3\n * // }\n * ```\n *\n * @param object - The object to flatten.\n * @returns - The flattened object.\n */\nexport function flattenObject<\n TObject extends Record<string, any> = Record<string, any>,\n TDeepKeyObject extends {\n [TKey in DeepKey<TObject>]: DeepValue<TObject, TKey>;\n } = { [TKey in DeepKey<TObject>]: DeepValue<TObject, TKey> }\n>(object: TObject): TDeepKeyObject {\n return flattenObjectImpl<TObject, TDeepKeyObject>(object);\n}\n\nfunction flattenObjectImpl<\n TObject extends Record<string, any> = Record<string, any>,\n TDeepKeyObject extends {\n [TKey in DeepKey<TObject>]: DeepValue<TObject, TKey>;\n } = { [TKey in DeepKey<TObject>]: DeepValue<TObject, TKey> }\n>(object: TObject, prefix = \"\"): TDeepKeyObject {\n const result = {} as TDeepKeyObject;\n const keys = Object.keys(object);\n\n for (const key of keys) {\n const value = (object as any)[key];\n\n const prefixedKey = prefix ? `${prefix}.${key}` : key;\n\n if (isPlainObject(value) && Object.keys(value).length > 0) {\n Object.assign(\n result,\n flattenObjectImpl<typeof value>(value, prefixedKey)\n );\n } else if (Array.isArray(value)) {\n for (const [index, element] of value.entries()) {\n (result as any)[`${prefixedKey}.${index}` as DeepKey<TObject>] =\n element;\n }\n } else {\n (result as any)[prefixedKey as DeepKey<TObject>] = value;\n }\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,cAKd,QAAiC;AACjC,QAAO,kBAA2C,OAAO;;AAG3D,SAAS,kBAKP,QAAiB,SAAS,IAAoB;CAC9C,MAAM,SAAS,EAAE;CACjB,MAAM,OAAO,OAAO,KAAK,OAAO;AAEhC,MAAK,MAAM,OAAO,MAAM;EACtB,MAAM,QAAS,OAAe;EAE9B,MAAM,cAAc,SAAS,GAAG,OAAO,GAAG,QAAQ;AAElD,MAAI,cAAc,MAAM,IAAI,OAAO,KAAK,MAAM,CAAC,SAAS,EACtD,QAAO,OACL,QACA,kBAAgC,OAAO,YAAY,CACpD;WACQ,MAAM,QAAQ,MAAM,CAC7B,MAAK,MAAM,CAAC,OAAO,YAAY,MAAM,SAAS,CAC5C,CAAC,OAAe,GAAG,YAAY,GAAG,WAChC;MAGJ,CAAC,OAAe,eAAmC;;AAIvD,QAAO"}
|
package/dist/get-field.cjs
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
const require_is_number = require('./type-checks/src/is-number.cjs');
|
|
2
|
-
const require_to_string_key = require('./convert/src/to-string-key.cjs');
|
|
3
2
|
const require_is_deep_key = require('./type-checks/src/is-deep-key.cjs');
|
|
3
|
+
require('./type-checks/src/index.cjs');
|
|
4
|
+
const require_to_string_key = require('./convert/src/to-string-key.cjs');
|
|
5
|
+
require('./convert/src/index.cjs');
|
|
4
6
|
const require_to_path = require('./to-path.cjs');
|
|
5
7
|
|
|
6
8
|
//#region src/get-field.ts
|
|
7
9
|
/**
|
|
8
10
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
9
11
|
*
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @returns
|
|
12
|
+
* @param object - The object to query.
|
|
13
|
+
* @param path - The path of the property to get.
|
|
14
|
+
* @param defaultValue - The value returned if the resolved value is undefined.
|
|
15
|
+
* @returns The resolved value.
|
|
14
16
|
*/
|
|
15
17
|
function getField(object, path, defaultValue) {
|
|
16
18
|
if (object === null) return defaultValue;
|
|
@@ -30,6 +32,11 @@ function getField(object, path, defaultValue) {
|
|
|
30
32
|
if (result === void 0) return defaultValue;
|
|
31
33
|
return result;
|
|
32
34
|
}
|
|
35
|
+
case "bigint":
|
|
36
|
+
case "boolean":
|
|
37
|
+
case "undefined":
|
|
38
|
+
case "object":
|
|
39
|
+
case "function":
|
|
33
40
|
default: {
|
|
34
41
|
if (Array.isArray(path)) return getWithPath(object, path, defaultValue);
|
|
35
42
|
path = Object.is(path?.valueOf(), -0) ? "-0" : String(path);
|
|
@@ -42,9 +49,9 @@ function getField(object, path, defaultValue) {
|
|
|
42
49
|
function getWithPath(object, path, defaultValue) {
|
|
43
50
|
if (path.length === 0) return defaultValue;
|
|
44
51
|
let current = object;
|
|
45
|
-
for (const
|
|
52
|
+
for (const element of path) {
|
|
46
53
|
if (current === null) return defaultValue;
|
|
47
|
-
current = current[
|
|
54
|
+
current = current[element];
|
|
48
55
|
}
|
|
49
56
|
if (current === void 0) return defaultValue;
|
|
50
57
|
return current;
|