@stryke/helpers 0.9.35 → 0.9.36
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 +8 -0
- package/dist/arg-identity.cjs +17 -1
- package/dist/arg-identity.mjs +16 -1
- package/dist/arg-identity.mjs.map +1 -1
- package/dist/convert/src/to-string-key.cjs +15 -1
- package/dist/convert/src/to-string-key.mjs +14 -1
- package/dist/convert/src/to-string-key.mjs.map +1 -1
- package/dist/debounce.cjs +62 -1
- package/dist/debounce.mjs +61 -1
- package/dist/debounce.mjs.map +1 -1
- package/dist/deep-clone.cjs +113 -1
- package/dist/deep-clone.mjs +113 -1
- package/dist/deep-clone.mjs.map +1 -1
- package/dist/deep-merge.cjs +60 -1
- package/dist/deep-merge.mjs +60 -1
- package/dist/deep-merge.mjs.map +1 -1
- package/dist/delay.cjs +90 -1
- package/dist/delay.mjs +89 -1
- package/dist/delay.mjs.map +1 -1
- package/dist/errors.cjs +24 -1
- package/dist/errors.mjs +22 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/filter-empty.cjs +7 -1
- package/dist/filter-empty.mjs +7 -1
- package/dist/filter-empty.mjs.map +1 -1
- package/dist/flatten-object.cjs +48 -1
- package/dist/flatten-object.mjs +48 -1
- package/dist/flatten-object.mjs.map +1 -1
- package/dist/get-field.cjs +54 -1
- package/dist/get-field.mjs +54 -1
- package/dist/get-field.mjs.map +1 -1
- package/dist/get-ordered-by.cjs +54 -1
- package/dist/get-ordered-by.mjs +53 -1
- package/dist/get-ordered-by.mjs.map +1 -1
- package/dist/get-unique.cjs +37 -1
- package/dist/get-unique.mjs +35 -1
- package/dist/get-unique.mjs.map +1 -1
- package/dist/identity.cjs +21 -1
- package/dist/identity.mjs +20 -1
- package/dist/identity.mjs.map +1 -1
- package/dist/index.cjs +71 -1
- package/dist/index.mjs +33 -1
- package/dist/is-equal.cjs +87 -1
- package/dist/is-equal.mjs +87 -1
- package/dist/is-equal.mjs.map +1 -1
- package/dist/lru-cache.cjs +190 -1
- package/dist/lru-cache.mjs +189 -1
- package/dist/lru-cache.mjs.map +1 -1
- package/dist/match-sorter.cjs +264 -1
- package/dist/match-sorter.mjs +262 -1
- package/dist/match-sorter.mjs.map +1 -1
- package/dist/memoize.cjs +20 -1
- package/dist/memoize.mjs +19 -1
- package/dist/memoize.mjs.map +1 -1
- package/dist/mutex.cjs +80 -1
- package/dist/mutex.mjs +80 -1
- package/dist/mutex.mjs.map +1 -1
- package/dist/noop.cjs +24 -1
- package/dist/noop.mjs +22 -1
- package/dist/noop.mjs.map +1 -1
- package/dist/omit.cjs +30 -1
- package/dist/omit.mjs +29 -1
- package/dist/omit.mjs.map +1 -1
- package/dist/once.cjs +27 -1
- package/dist/once.mjs +25 -1
- package/dist/once.mjs.map +1 -1
- package/dist/pick.cjs +30 -1
- package/dist/pick.mjs +29 -1
- package/dist/pick.mjs.map +1 -1
- package/dist/remove-accents.cjs +416 -1
- package/dist/remove-accents.mjs +414 -1
- package/dist/remove-accents.mjs.map +1 -1
- package/dist/remove-empty-items.cjs +12 -1
- package/dist/remove-empty-items.mjs +11 -1
- package/dist/remove-empty-items.mjs.map +1 -1
- package/dist/semaphore.cjs +105 -1
- package/dist/semaphore.mjs +104 -1
- package/dist/semaphore.mjs.map +1 -1
- package/dist/set-field.cjs +30 -1
- package/dist/set-field.mjs +30 -1
- package/dist/set-field.mjs.map +1 -1
- package/dist/throttle.cjs +43 -1
- package/dist/throttle.mjs +42 -1
- package/dist/throttle.mjs.map +1 -1
- package/dist/timeout.cjs +18 -1
- package/dist/timeout.mjs +18 -1
- package/dist/timeout.mjs.map +1 -1
- package/dist/to-deep-key.cjs +54 -1
- package/dist/to-deep-key.mjs +53 -1
- package/dist/to-deep-key.mjs.map +1 -1
- package/dist/to-path.cjs +43 -1
- package/dist/to-path.mjs +42 -1
- package/dist/to-path.mjs.map +1 -1
- package/dist/type-checks/src/get-object-tag.cjs +15 -1
- package/dist/type-checks/src/get-object-tag.mjs +14 -1
- package/dist/type-checks/src/get-object-tag.mjs.map +1 -1
- package/dist/type-checks/src/is-deep-key.cjs +28 -1
- package/dist/type-checks/src/is-deep-key.mjs +27 -1
- package/dist/type-checks/src/is-deep-key.mjs.map +1 -1
- package/dist/type-checks/src/is-empty.cjs +20 -1
- package/dist/type-checks/src/is-empty.mjs +20 -1
- package/dist/type-checks/src/is-empty.mjs.map +1 -1
- package/dist/type-checks/src/is-function.cjs +25 -1
- package/dist/type-checks/src/is-function.mjs +25 -1
- package/dist/type-checks/src/is-function.mjs.map +1 -1
- package/dist/type-checks/src/is-mergeable-object.cjs +14 -1
- package/dist/type-checks/src/is-mergeable-object.mjs +14 -1
- package/dist/type-checks/src/is-mergeable-object.mjs.map +1 -1
- package/dist/type-checks/src/is-non-null-object.cjs +16 -1
- package/dist/type-checks/src/is-non-null-object.mjs +16 -1
- package/dist/type-checks/src/is-non-null-object.mjs.map +1 -1
- package/dist/type-checks/src/is-null.cjs +12 -1
- package/dist/type-checks/src/is-null.mjs +11 -1
- package/dist/type-checks/src/is-null.mjs.map +1 -1
- package/dist/type-checks/src/is-number.cjs +18 -1
- package/dist/type-checks/src/is-number.mjs +17 -1
- package/dist/type-checks/src/is-number.mjs.map +1 -1
- package/dist/type-checks/src/is-object-index.cjs +19 -1
- package/dist/type-checks/src/is-object-index.mjs +18 -1
- package/dist/type-checks/src/is-object-index.mjs.map +1 -1
- package/dist/type-checks/src/is-object.cjs +19 -1
- package/dist/type-checks/src/is-object.mjs +19 -1
- package/dist/type-checks/src/is-object.mjs.map +1 -1
- package/dist/type-checks/src/is-plain-object.cjs +63 -1
- package/dist/type-checks/src/is-plain-object.mjs +63 -1
- package/dist/type-checks/src/is-plain-object.mjs.map +1 -1
- package/dist/type-checks/src/is-primitive.cjs +12 -1
- package/dist/type-checks/src/is-primitive.mjs +11 -1
- package/dist/type-checks/src/is-primitive.mjs.map +1 -1
- package/dist/type-checks/src/is-react-element.cjs +8 -1
- package/dist/type-checks/src/is-react-element.mjs +7 -1
- package/dist/type-checks/src/is-react-element.mjs.map +1 -1
- package/dist/type-checks/src/is-set-string.cjs +20 -1
- package/dist/type-checks/src/is-set-string.mjs +20 -1
- package/dist/type-checks/src/is-set-string.mjs.map +1 -1
- package/dist/type-checks/src/is-set.cjs +19 -1
- package/dist/type-checks/src/is-set.mjs +19 -1
- package/dist/type-checks/src/is-set.mjs.map +1 -1
- package/dist/type-checks/src/is-string.cjs +12 -1
- package/dist/type-checks/src/is-string.mjs +11 -1
- package/dist/type-checks/src/is-string.mjs.map +1 -1
- package/dist/type-checks/src/is-typed-array.cjs +8 -1
- package/dist/type-checks/src/is-typed-array.mjs +7 -1
- package/dist/type-checks/src/is-typed-array.mjs.map +1 -1
- package/dist/type-checks/src/is-undefined.cjs +8 -1
- package/dist/type-checks/src/is-undefined.mjs +7 -1
- package/dist/type-checks/src/is-undefined.mjs.map +1 -1
- package/dist/type-checks/src/property-exists.cjs +30 -1
- package/dist/type-checks/src/property-exists.mjs +30 -1
- package/dist/type-checks/src/property-exists.mjs.map +1 -1
- package/dist/unflatten-object.cjs +38 -1
- package/dist/unflatten-object.mjs +38 -1
- package/dist/unflatten-object.mjs.map +1 -1
- package/dist/union.cjs +28 -1
- package/dist/union.mjs +28 -1
- package/dist/union.mjs.map +1 -1
- package/dist/with-timeout.cjs +28 -1
- package/dist/with-timeout.mjs +28 -1
- package/dist/with-timeout.mjs.map +1 -1
- package/package.json +2 -2
package/dist/memoize.mjs
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/memoize.ts
|
|
2
|
+
/**
|
|
3
|
+
* Memoizes a function based on its string identifier.
|
|
4
|
+
*
|
|
5
|
+
* @param fn - The function to memoize.
|
|
6
|
+
* @returns A memoized version of the input function.
|
|
7
|
+
*/
|
|
8
|
+
const memoizeOnId = (fn) => {
|
|
9
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
10
|
+
const results = {};
|
|
11
|
+
const memoizedFn = (id) => {
|
|
12
|
+
if (hasOwnProperty.call(results, id)) return results[id];
|
|
13
|
+
return results[id] = fn(id);
|
|
14
|
+
};
|
|
15
|
+
return memoizedFn;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { memoizeOnId };
|
|
2
20
|
//# sourceMappingURL=memoize.mjs.map
|
package/dist/memoize.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoize.mjs","names":["results: Record<string, T>"],"sources":["../src/memoize.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 * Memoizes a function based on its string identifier.\n *\n * @param fn - The function to memoize.\n * @returns A memoized version of the input function.\n */\nexport const memoizeOnId = <T>(fn: (id: string) => T) => {\n // eslint-disable-next-line ts/unbound-method\n const hasOwnProperty = Object.prototype.hasOwnProperty;\n const results: Record<string, T> = {};\n\n const memoizedFn = (id: string) => {\n if (hasOwnProperty.call(results, id)) {\n return results[id];\n }\n return (results[id] = fn(id));\n };\n\n return memoizedFn;\n};\n"],"mappings":"AAwBA,MAAa,
|
|
1
|
+
{"version":3,"file":"memoize.mjs","names":["results: Record<string, T>"],"sources":["../src/memoize.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 * Memoizes a function based on its string identifier.\n *\n * @param fn - The function to memoize.\n * @returns A memoized version of the input function.\n */\nexport const memoizeOnId = <T>(fn: (id: string) => T) => {\n // eslint-disable-next-line ts/unbound-method\n const hasOwnProperty = Object.prototype.hasOwnProperty;\n const results: Record<string, T> = {};\n\n const memoizedFn = (id: string) => {\n if (hasOwnProperty.call(results, id)) {\n return results[id];\n }\n return (results[id] = fn(id));\n };\n\n return memoizedFn;\n};\n"],"mappings":";;;;;;;AAwBA,MAAa,eAAkB,OAA0B;CAEvD,MAAM,iBAAiB,OAAO,UAAU;CACxC,MAAMA,UAA6B,EAAE;CAErC,MAAM,cAAc,OAAe;AACjC,MAAI,eAAe,KAAK,SAAS,GAAG,CAClC,QAAO,QAAQ;AAEjB,SAAQ,QAAQ,MAAM,GAAG,GAAG;;AAG9B,QAAO"}
|
package/dist/mutex.cjs
CHANGED
|
@@ -1 +1,80 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_semaphore = require('./semaphore.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/mutex.ts
|
|
4
|
+
/**
|
|
5
|
+
* A Mutex (mutual exclusion lock) for async functions.
|
|
6
|
+
* It allows only one async task to access a critical section at a time.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const mutex = new Mutex();
|
|
11
|
+
*
|
|
12
|
+
* async function criticalSection() {
|
|
13
|
+
* await mutex.acquire();
|
|
14
|
+
* try {
|
|
15
|
+
* // This code section cannot be executed simultaneously
|
|
16
|
+
* } finally {
|
|
17
|
+
* mutex.release();
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* criticalSection();
|
|
22
|
+
* criticalSection(); // This call will wait until the first call releases the mutex.
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
var Mutex = class {
|
|
26
|
+
semaphore = new require_semaphore.Semaphore(1);
|
|
27
|
+
/**
|
|
28
|
+
* Checks if the mutex is currently locked.
|
|
29
|
+
* @returns True if the mutex is locked, false otherwise.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const mutex = new Mutex();
|
|
33
|
+
* console.log(mutex.isLocked); // false
|
|
34
|
+
* await mutex.acquire();
|
|
35
|
+
* console.log(mutex.isLocked); // true
|
|
36
|
+
* mutex.release();
|
|
37
|
+
* console.log(mutex.isLocked); // false
|
|
38
|
+
*/
|
|
39
|
+
get isLocked() {
|
|
40
|
+
return this.semaphore.available === 0;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Acquires the mutex, blocking if necessary until it is available.
|
|
44
|
+
* @returns A promise that resolves when the mutex is acquired.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const mutex = new Mutex();
|
|
49
|
+
* await mutex.acquire();
|
|
50
|
+
* try {
|
|
51
|
+
* // This code section cannot be executed simultaneously
|
|
52
|
+
* } finally {
|
|
53
|
+
* mutex.release();
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
async acquire() {
|
|
58
|
+
return this.semaphore.acquire();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Releases the mutex, allowing another waiting task to proceed.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const mutex = new Mutex();
|
|
66
|
+
* await mutex.acquire();
|
|
67
|
+
* try {
|
|
68
|
+
* // This code section cannot be executed simultaneously
|
|
69
|
+
* } finally {
|
|
70
|
+
* mutex.release(); // Allows another waiting task to proceed.
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
release() {
|
|
75
|
+
this.semaphore.release();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
exports.Mutex = Mutex;
|
package/dist/mutex.mjs
CHANGED
|
@@ -1,2 +1,81 @@
|
|
|
1
|
-
import{Semaphore
|
|
1
|
+
import { Semaphore } from "./semaphore.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/mutex.ts
|
|
4
|
+
/**
|
|
5
|
+
* A Mutex (mutual exclusion lock) for async functions.
|
|
6
|
+
* It allows only one async task to access a critical section at a time.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const mutex = new Mutex();
|
|
11
|
+
*
|
|
12
|
+
* async function criticalSection() {
|
|
13
|
+
* await mutex.acquire();
|
|
14
|
+
* try {
|
|
15
|
+
* // This code section cannot be executed simultaneously
|
|
16
|
+
* } finally {
|
|
17
|
+
* mutex.release();
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* criticalSection();
|
|
22
|
+
* criticalSection(); // This call will wait until the first call releases the mutex.
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
var Mutex = class {
|
|
26
|
+
semaphore = new Semaphore(1);
|
|
27
|
+
/**
|
|
28
|
+
* Checks if the mutex is currently locked.
|
|
29
|
+
* @returns True if the mutex is locked, false otherwise.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const mutex = new Mutex();
|
|
33
|
+
* console.log(mutex.isLocked); // false
|
|
34
|
+
* await mutex.acquire();
|
|
35
|
+
* console.log(mutex.isLocked); // true
|
|
36
|
+
* mutex.release();
|
|
37
|
+
* console.log(mutex.isLocked); // false
|
|
38
|
+
*/
|
|
39
|
+
get isLocked() {
|
|
40
|
+
return this.semaphore.available === 0;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Acquires the mutex, blocking if necessary until it is available.
|
|
44
|
+
* @returns A promise that resolves when the mutex is acquired.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const mutex = new Mutex();
|
|
49
|
+
* await mutex.acquire();
|
|
50
|
+
* try {
|
|
51
|
+
* // This code section cannot be executed simultaneously
|
|
52
|
+
* } finally {
|
|
53
|
+
* mutex.release();
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
async acquire() {
|
|
58
|
+
return this.semaphore.acquire();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Releases the mutex, allowing another waiting task to proceed.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const mutex = new Mutex();
|
|
66
|
+
* await mutex.acquire();
|
|
67
|
+
* try {
|
|
68
|
+
* // This code section cannot be executed simultaneously
|
|
69
|
+
* } finally {
|
|
70
|
+
* mutex.release(); // Allows another waiting task to proceed.
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
release() {
|
|
75
|
+
this.semaphore.release();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
export { Mutex };
|
|
2
81
|
//# sourceMappingURL=mutex.mjs.map
|
package/dist/mutex.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutex.mjs","names":[],"sources":["../src/mutex.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 { Semaphore } from \"./semaphore\";\n\n/**\n * A Mutex (mutual exclusion lock) for async functions.\n * It allows only one async task to access a critical section at a time.\n *\n * @example\n * ```typescript\n * const mutex = new Mutex();\n *\n * async function criticalSection() {\n * await mutex.acquire();\n * try {\n * // This code section cannot be executed simultaneously\n * } finally {\n * mutex.release();\n * }\n * }\n *\n * criticalSection();\n * criticalSection(); // This call will wait until the first call releases the mutex.\n * ```\n */\nexport class Mutex {\n private semaphore = new Semaphore(1);\n\n /**\n * Checks if the mutex is currently locked.\n * @returns True if the mutex is locked, false otherwise.\n *\n * @example\n * const mutex = new Mutex();\n * console.log(mutex.isLocked); // false\n * await mutex.acquire();\n * console.log(mutex.isLocked); // true\n * mutex.release();\n * console.log(mutex.isLocked); // false\n */\n public get isLocked(): boolean {\n return this.semaphore.available === 0;\n }\n\n /**\n * Acquires the mutex, blocking if necessary until it is available.\n * @returns A promise that resolves when the mutex is acquired.\n *\n * @example\n * ```typescript\n * const mutex = new Mutex();\n * await mutex.acquire();\n * try {\n * // This code section cannot be executed simultaneously\n * } finally {\n * mutex.release();\n * }\n * ```\n */\n public async acquire(): Promise<void> {\n return this.semaphore.acquire();\n }\n\n /**\n * Releases the mutex, allowing another waiting task to proceed.\n *\n * @example\n * ```typescript\n * const mutex = new Mutex();\n * await mutex.acquire();\n * try {\n * // This code section cannot be executed simultaneously\n * } finally {\n * mutex.release(); // Allows another waiting task to proceed.\n * }\n * ```\n */\n public release(): void {\n this.semaphore.release();\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"mutex.mjs","names":[],"sources":["../src/mutex.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 { Semaphore } from \"./semaphore\";\n\n/**\n * A Mutex (mutual exclusion lock) for async functions.\n * It allows only one async task to access a critical section at a time.\n *\n * @example\n * ```typescript\n * const mutex = new Mutex();\n *\n * async function criticalSection() {\n * await mutex.acquire();\n * try {\n * // This code section cannot be executed simultaneously\n * } finally {\n * mutex.release();\n * }\n * }\n *\n * criticalSection();\n * criticalSection(); // This call will wait until the first call releases the mutex.\n * ```\n */\nexport class Mutex {\n private semaphore = new Semaphore(1);\n\n /**\n * Checks if the mutex is currently locked.\n * @returns True if the mutex is locked, false otherwise.\n *\n * @example\n * const mutex = new Mutex();\n * console.log(mutex.isLocked); // false\n * await mutex.acquire();\n * console.log(mutex.isLocked); // true\n * mutex.release();\n * console.log(mutex.isLocked); // false\n */\n public get isLocked(): boolean {\n return this.semaphore.available === 0;\n }\n\n /**\n * Acquires the mutex, blocking if necessary until it is available.\n * @returns A promise that resolves when the mutex is acquired.\n *\n * @example\n * ```typescript\n * const mutex = new Mutex();\n * await mutex.acquire();\n * try {\n * // This code section cannot be executed simultaneously\n * } finally {\n * mutex.release();\n * }\n * ```\n */\n public async acquire(): Promise<void> {\n return this.semaphore.acquire();\n }\n\n /**\n * Releases the mutex, allowing another waiting task to proceed.\n *\n * @example\n * ```typescript\n * const mutex = new Mutex();\n * await mutex.acquire();\n * try {\n * // This code section cannot be executed simultaneously\n * } finally {\n * mutex.release(); // Allows another waiting task to proceed.\n * }\n * ```\n */\n public release(): void {\n this.semaphore.release();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,QAAb,MAAmB;CACjB,AAAQ,YAAY,IAAI,UAAU,EAAE;;;;;;;;;;;;;CAcpC,IAAW,WAAoB;AAC7B,SAAO,KAAK,UAAU,cAAc;;;;;;;;;;;;;;;;;CAkBtC,MAAa,UAAyB;AACpC,SAAO,KAAK,UAAU,SAAS;;;;;;;;;;;;;;;;CAiBjC,AAAO,UAAgB;AACrB,OAAK,UAAU,SAAS"}
|
package/dist/noop.cjs
CHANGED
|
@@ -1 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/noop.ts
|
|
3
|
+
/**
|
|
4
|
+
* A no op, or no-op, function for no operation
|
|
5
|
+
*
|
|
6
|
+
* @remarks Please see {@link https://dev.to/praneshpsg239/noop-in-javascript-478h | this article} for more information.
|
|
7
|
+
*
|
|
8
|
+
* @param _params - An optional parameter passed to the function. It can be anything (but is not used in any way)
|
|
9
|
+
*/
|
|
10
|
+
const noop = (_params) => {};
|
|
11
|
+
/**
|
|
12
|
+
* An asynchronous no-operation function that does nothing.
|
|
13
|
+
* This can be used as a placeholder or default function.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* asyncNoop(); // Does nothing
|
|
17
|
+
*
|
|
18
|
+
* @returns This function returns a Promise that resolves to undefined.
|
|
19
|
+
*/
|
|
20
|
+
async function asyncNoop(_params) {}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.asyncNoop = asyncNoop;
|
|
24
|
+
exports.noop = noop;
|
package/dist/noop.mjs
CHANGED
|
@@ -1,2 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/noop.ts
|
|
2
|
+
/**
|
|
3
|
+
* A no op, or no-op, function for no operation
|
|
4
|
+
*
|
|
5
|
+
* @remarks Please see {@link https://dev.to/praneshpsg239/noop-in-javascript-478h | this article} for more information.
|
|
6
|
+
*
|
|
7
|
+
* @param _params - An optional parameter passed to the function. It can be anything (but is not used in any way)
|
|
8
|
+
*/
|
|
9
|
+
const noop = (_params) => {};
|
|
10
|
+
/**
|
|
11
|
+
* An asynchronous no-operation function that does nothing.
|
|
12
|
+
* This can be used as a placeholder or default function.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* asyncNoop(); // Does nothing
|
|
16
|
+
*
|
|
17
|
+
* @returns This function returns a Promise that resolves to undefined.
|
|
18
|
+
*/
|
|
19
|
+
async function asyncNoop(_params) {}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { asyncNoop, noop };
|
|
2
23
|
//# sourceMappingURL=noop.mjs.map
|
package/dist/noop.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noop.mjs","names":[],"sources":["../src/noop.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.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://stormsoftware.com/projects/stryke/docs\n Contact: https://stormsoftware.com/contact\n License: https://stormsoftware.com/projects/stryke/license\n\n ------------------------------------------------------------------- */\n\n/**\n * A no op, or no-op, function for no operation\n *\n * @remarks Please see {@link https://dev.to/praneshpsg239/noop-in-javascript-478h | this article} for more information.\n *\n * @param _params - An optional parameter passed to the function. It can be anything (but is not used in any way)\n */\nexport const noop = (_params?: unknown): void => {};\n\n/**\n * An asynchronous no-operation function that does nothing.\n * This can be used as a placeholder or default function.\n *\n * @example\n * asyncNoop(); // Does nothing\n *\n * @returns This function returns a Promise that resolves to undefined.\n */\nexport async function asyncNoop(_params?: unknown): Promise<void> {}\n"],"mappings":"AAwBA,MAAa,
|
|
1
|
+
{"version":3,"file":"noop.mjs","names":[],"sources":["../src/noop.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.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://stormsoftware.com/projects/stryke/docs\n Contact: https://stormsoftware.com/contact\n License: https://stormsoftware.com/projects/stryke/license\n\n ------------------------------------------------------------------- */\n\n/**\n * A no op, or no-op, function for no operation\n *\n * @remarks Please see {@link https://dev.to/praneshpsg239/noop-in-javascript-478h | this article} for more information.\n *\n * @param _params - An optional parameter passed to the function. It can be anything (but is not used in any way)\n */\nexport const noop = (_params?: unknown): void => {};\n\n/**\n * An asynchronous no-operation function that does nothing.\n * This can be used as a placeholder or default function.\n *\n * @example\n * asyncNoop(); // Does nothing\n *\n * @returns This function returns a Promise that resolves to undefined.\n */\nexport async function asyncNoop(_params?: unknown): Promise<void> {}\n"],"mappings":";;;;;;;;AAwBA,MAAa,QAAQ,YAA4B;;;;;;;;;;AAWjD,eAAsB,UAAU,SAAkC"}
|
package/dist/omit.cjs
CHANGED
|
@@ -1 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/omit.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new object with specified keys omitted.
|
|
5
|
+
*
|
|
6
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
7
|
+
* excludes the properties corresponding to the specified keys.
|
|
8
|
+
*
|
|
9
|
+
* @param obj - The object to omit keys from.
|
|
10
|
+
* @param keys - An array of keys to be omitted from the object.
|
|
11
|
+
* @returns A new object with the specified keys omitted.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
16
|
+
* const result = omit(obj, ['b', 'c']);
|
|
17
|
+
* // result will be { a: 1 }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
function omit(obj, keys) {
|
|
21
|
+
const result = { ...obj };
|
|
22
|
+
for (let i = 0; i < keys.length; i++) {
|
|
23
|
+
const key = keys[i];
|
|
24
|
+
if (key) delete result[key];
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.omit = omit;
|
package/dist/omit.mjs
CHANGED
|
@@ -1,2 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/omit.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new object with specified keys omitted.
|
|
4
|
+
*
|
|
5
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
6
|
+
* excludes the properties corresponding to the specified keys.
|
|
7
|
+
*
|
|
8
|
+
* @param obj - The object to omit keys from.
|
|
9
|
+
* @param keys - An array of keys to be omitted from the object.
|
|
10
|
+
* @returns A new object with the specified keys omitted.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
15
|
+
* const result = omit(obj, ['b', 'c']);
|
|
16
|
+
* // result will be { a: 1 }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
function omit(obj, keys) {
|
|
20
|
+
const result = { ...obj };
|
|
21
|
+
for (let i = 0; i < keys.length; i++) {
|
|
22
|
+
const key = keys[i];
|
|
23
|
+
if (key) delete result[key];
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { omit };
|
|
2
30
|
//# sourceMappingURL=omit.mjs.map
|
package/dist/omit.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"omit.mjs","names":[],"sources":["../src/omit.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software \n\n This code was released as part of a Storm Software project. The project\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/license.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software\n Documentation: https://stormsoftware.com/docs\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Creates a new object with specified keys omitted.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * excludes the properties corresponding to the specified keys.\n *\n * @param obj - The object to omit keys from.\n * @param keys - An array of keys to be omitted from the object.\n * @returns A new object with the specified keys omitted.\n *\n * @example\n * ```typescript\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = omit(obj, ['b', 'c']);\n * // result will be { a: 1 }\n * ```\n */\nexport function omit<T extends Record<string, any>, K extends keyof T>(\n obj: T,\n keys: readonly K[]\n): Omit<T, K> {\n const result = { ...obj };\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if (key) {\n delete result[key];\n }\n }\n\n return result as Omit<T, K>;\n}\n"],"mappings":"AAmCA,SAAgB,
|
|
1
|
+
{"version":3,"file":"omit.mjs","names":[],"sources":["../src/omit.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software \n\n This code was released as part of a Storm Software project. The project\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/license.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software\n Documentation: https://stormsoftware.com/docs\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Creates a new object with specified keys omitted.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * excludes the properties corresponding to the specified keys.\n *\n * @param obj - The object to omit keys from.\n * @param keys - An array of keys to be omitted from the object.\n * @returns A new object with the specified keys omitted.\n *\n * @example\n * ```typescript\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = omit(obj, ['b', 'c']);\n * // result will be { a: 1 }\n * ```\n */\nexport function omit<T extends Record<string, any>, K extends keyof T>(\n obj: T,\n keys: readonly K[]\n): Omit<T, K> {\n const result = { ...obj };\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if (key) {\n delete result[key];\n }\n }\n\n return result as Omit<T, K>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmCA,SAAgB,KACd,KACA,MACY;CACZ,MAAM,SAAS,EAAE,GAAG,KAAK;AAEzB,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,MAAM,KAAK;AACjB,MAAI,IACF,QAAO,OAAO;;AAIlB,QAAO"}
|
package/dist/once.cjs
CHANGED
|
@@ -1 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/once.ts
|
|
3
|
+
/** silence "error TS2322" but practically this is safer and more convenient than resorting to `any` in a random place */
|
|
4
|
+
function safeFunctionCast(fn) {
|
|
5
|
+
return fn;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Executes a function only once.
|
|
9
|
+
*
|
|
10
|
+
* @param fn - The function to be executed only once.
|
|
11
|
+
* @returns A function that, when called, will execute the original function only once.
|
|
12
|
+
*/
|
|
13
|
+
function once(fn) {
|
|
14
|
+
let result;
|
|
15
|
+
let called = false;
|
|
16
|
+
return safeFunctionCast(function(...args) {
|
|
17
|
+
if (!called) {
|
|
18
|
+
result = fn.apply(this, args);
|
|
19
|
+
called = true;
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.once = once;
|
|
27
|
+
exports.safeFunctionCast = safeFunctionCast;
|
package/dist/once.mjs
CHANGED
|
@@ -1,2 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/once.ts
|
|
2
|
+
/** silence "error TS2322" but practically this is safer and more convenient than resorting to `any` in a random place */
|
|
3
|
+
function safeFunctionCast(fn) {
|
|
4
|
+
return fn;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Executes a function only once.
|
|
8
|
+
*
|
|
9
|
+
* @param fn - The function to be executed only once.
|
|
10
|
+
* @returns A function that, when called, will execute the original function only once.
|
|
11
|
+
*/
|
|
12
|
+
function once(fn) {
|
|
13
|
+
let result;
|
|
14
|
+
let called = false;
|
|
15
|
+
return safeFunctionCast(function(...args) {
|
|
16
|
+
if (!called) {
|
|
17
|
+
result = fn.apply(this, args);
|
|
18
|
+
called = true;
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { once, safeFunctionCast };
|
|
2
26
|
//# sourceMappingURL=once.mjs.map
|
package/dist/once.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"once.mjs","names":["result: ReturnType<TFunc>"],"sources":["../src/once.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/** silence \"error TS2322\" but practically this is safer and more convenient than resorting to `any` in a random place */\nexport function safeFunctionCast<TFunc extends (...args: any[]) => any>(\n fn: (...args: Parameters<TFunc>) => ReturnType<TFunc>\n): TFunc {\n // @ts-expect-error\n // error TS2322: Type '(...args: Parameters<F>) => ReturnType<F>' is not assignable to type 'F'.\n // '(...args: Parameters<F>) => ReturnType<F>' is assignable to the constraint of type 'F', but 'F' could be instantiated with a different subtype of constraint '(...args: any[]) => any'.\n return fn;\n}\n\n/**\n * Executes a function only once.\n *\n * @param fn - The function to be executed only once.\n * @returns A function that, when called, will execute the original function only once.\n */\nexport function once<TFunc extends (...args: any[]) => any>(fn: TFunc): TFunc {\n let result: ReturnType<TFunc>;\n let called = false;\n\n // eslint-disable-next-line func-names\n return safeFunctionCast<TFunc>(function (this: unknown, ...args) {\n if (!called) {\n result = fn.apply(this, args);\n called = true;\n }\n return result;\n });\n}\n"],"mappings":"AAmBA,SAAgB,
|
|
1
|
+
{"version":3,"file":"once.mjs","names":["result: ReturnType<TFunc>"],"sources":["../src/once.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/** silence \"error TS2322\" but practically this is safer and more convenient than resorting to `any` in a random place */\nexport function safeFunctionCast<TFunc extends (...args: any[]) => any>(\n fn: (...args: Parameters<TFunc>) => ReturnType<TFunc>\n): TFunc {\n // @ts-expect-error\n // error TS2322: Type '(...args: Parameters<F>) => ReturnType<F>' is not assignable to type 'F'.\n // '(...args: Parameters<F>) => ReturnType<F>' is assignable to the constraint of type 'F', but 'F' could be instantiated with a different subtype of constraint '(...args: any[]) => any'.\n return fn;\n}\n\n/**\n * Executes a function only once.\n *\n * @param fn - The function to be executed only once.\n * @returns A function that, when called, will execute the original function only once.\n */\nexport function once<TFunc extends (...args: any[]) => any>(fn: TFunc): TFunc {\n let result: ReturnType<TFunc>;\n let called = false;\n\n // eslint-disable-next-line func-names\n return safeFunctionCast<TFunc>(function (this: unknown, ...args) {\n if (!called) {\n result = fn.apply(this, args);\n called = true;\n }\n return result;\n });\n}\n"],"mappings":";;AAmBA,SAAgB,iBACd,IACO;AAIP,QAAO;;;;;;;;AAST,SAAgB,KAA4C,IAAkB;CAC5E,IAAIA;CACJ,IAAI,SAAS;AAGb,QAAO,iBAAwB,SAAyB,GAAG,MAAM;AAC/D,MAAI,CAAC,QAAQ;AACX,YAAS,GAAG,MAAM,MAAM,KAAK;AAC7B,YAAS;;AAEX,SAAO;GACP"}
|
package/dist/pick.cjs
CHANGED
|
@@ -1 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/pick.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new object composed of the picked object properties.
|
|
5
|
+
*
|
|
6
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
7
|
+
* includes only the properties corresponding to the specified keys.
|
|
8
|
+
*
|
|
9
|
+
* @param obj - The object to pick keys from.
|
|
10
|
+
* @param keys - An array of keys to be picked from the object.
|
|
11
|
+
* @returns A new object with the specified keys picked.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
16
|
+
* const result = pick(obj, ['a', 'c']);
|
|
17
|
+
* // result will be { a: 1, c: 3 }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
function pick(obj, keys) {
|
|
21
|
+
const result = {};
|
|
22
|
+
for (let i = 0; i < keys.length; i++) {
|
|
23
|
+
const key = keys[i];
|
|
24
|
+
if (key && Object.hasOwn(obj, key)) result[key] = obj[key];
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.pick = pick;
|
package/dist/pick.mjs
CHANGED
|
@@ -1,2 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/pick.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new object composed of the picked object properties.
|
|
4
|
+
*
|
|
5
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
6
|
+
* includes only the properties corresponding to the specified keys.
|
|
7
|
+
*
|
|
8
|
+
* @param obj - The object to pick keys from.
|
|
9
|
+
* @param keys - An array of keys to be picked from the object.
|
|
10
|
+
* @returns A new object with the specified keys picked.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
15
|
+
* const result = pick(obj, ['a', 'c']);
|
|
16
|
+
* // result will be { a: 1, c: 3 }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
function pick(obj, keys) {
|
|
20
|
+
const result = {};
|
|
21
|
+
for (let i = 0; i < keys.length; i++) {
|
|
22
|
+
const key = keys[i];
|
|
23
|
+
if (key && Object.hasOwn(obj, key)) result[key] = obj[key];
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { pick };
|
|
2
30
|
//# sourceMappingURL=pick.mjs.map
|
package/dist/pick.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pick.mjs","names":[],"sources":["../src/pick.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software \n\n This code was released as part of a Storm Software project. The project\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/license.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software\n Documentation: https://stormsoftware.com/docs\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Creates a new object composed of the picked object properties.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * includes only the properties corresponding to the specified keys.\n *\n * @param obj - The object to pick keys from.\n * @param keys - An array of keys to be picked from the object.\n * @returns A new object with the specified keys picked.\n *\n * @example\n * ```typescript\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = pick(obj, ['a', 'c']);\n * // result will be { a: 1, c: 3 }\n * ```\n */\nexport function pick<T extends Record<string, any>, K extends keyof T>(\n obj: T,\n keys: readonly K[]\n): Pick<T, K> {\n const result = {} as Pick<T, K>;\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n\n if (key && Object.hasOwn(obj, key)) {\n result[key] = obj[key];\n }\n }\n\n return result;\n}\n"],"mappings":"AAmCA,SAAgB,
|
|
1
|
+
{"version":3,"file":"pick.mjs","names":[],"sources":["../src/pick.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software \n\n This code was released as part of a Storm Software project. The project\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/license.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software\n Documentation: https://stormsoftware.com/docs\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Creates a new object composed of the picked object properties.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * includes only the properties corresponding to the specified keys.\n *\n * @param obj - The object to pick keys from.\n * @param keys - An array of keys to be picked from the object.\n * @returns A new object with the specified keys picked.\n *\n * @example\n * ```typescript\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = pick(obj, ['a', 'c']);\n * // result will be { a: 1, c: 3 }\n * ```\n */\nexport function pick<T extends Record<string, any>, K extends keyof T>(\n obj: T,\n keys: readonly K[]\n): Pick<T, K> {\n const result = {} as Pick<T, K>;\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n\n if (key && Object.hasOwn(obj, key)) {\n result[key] = obj[key];\n }\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmCA,SAAgB,KACd,KACA,MACY;CACZ,MAAM,SAAS,EAAE;AAEjB,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,MAAM,KAAK;AAEjB,MAAI,OAAO,OAAO,OAAO,KAAK,IAAI,CAChC,QAAO,OAAO,IAAI;;AAItB,QAAO"}
|