@stryke/helpers 0.10.24 → 0.10.26
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 +22 -2
- package/README.md +8 -8
- package/dist/arg-identity.mjs.map +1 -1
- package/dist/deep-clone.mjs.map +1 -1
- package/dist/deep-merge.mjs.map +1 -1
- package/dist/filter-empty.mjs.map +1 -1
- package/dist/flatten-object.mjs.map +1 -1
- package/dist/get-field.mjs.map +1 -1
- package/dist/get-ordered-by.mjs.map +1 -1
- package/dist/get-unique.mjs.map +1 -1
- package/dist/identity.mjs.map +1 -1
- package/dist/is-equal.mjs.map +1 -1
- package/dist/lru-cache.mjs.map +1 -1
- package/dist/match-sorter.mjs.map +1 -1
- package/dist/memoize.mjs.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.mjs.map +1 -1
- package/dist/remove-empty-items.mjs.map +1 -1
- package/dist/set-field.mjs.map +1 -1
- package/dist/to-deep-key.mjs.map +1 -1
- package/dist/to-path.mjs.map +1 -1
- package/dist/unflatten-object.mjs.map +1 -1
- package/dist/union.mjs.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
|
-

|
|
1
|
+

|
|
2
2
|
|
|
3
3
|
# Changelog for Stryke - Helpers
|
|
4
4
|
|
|
5
|
+
## [0.10.25](https://github.com/storm-software/stryke/releases/tag/helpers%400.10.25) (06/15/2026)
|
|
6
|
+
|
|
7
|
+
### Miscellaneous
|
|
8
|
+
|
|
9
|
+
- **monorepo:** Update asset references to the newly created `media` folder ([a3563a88](https://github.com/storm-software/stryke/commit/a3563a88))
|
|
10
|
+
|
|
11
|
+
### Updated Dependencies
|
|
12
|
+
|
|
13
|
+
- Updated **convert** to **v0.7.16**
|
|
14
|
+
- Updated **type-checks** to **v0.6.18**
|
|
15
|
+
- Updated **types** to **v0.12.13**
|
|
16
|
+
|
|
17
|
+
## [0.10.24](https://github.com/storm-software/stryke/releases/tag/helpers%400.10.24) (06/03/2026)
|
|
18
|
+
|
|
19
|
+
### Updated Dependencies
|
|
20
|
+
|
|
21
|
+
- Updated **convert** to **v0.7.15**
|
|
22
|
+
- Updated **type-checks** to **v0.6.17**
|
|
23
|
+
- Updated **types** to **v0.12.12**
|
|
24
|
+
|
|
5
25
|
## [0.10.23](https://github.com/storm-software/stryke/releases/tag/helpers%400.10.23) (06/01/2026)
|
|
6
26
|
|
|
7
27
|
### Bug Fixes
|
|
@@ -453,7 +473,7 @@
|
|
|
453
473
|
- Updated **convert** to **v0.6.27**
|
|
454
474
|
- Updated **types** to **v0.10.26**
|
|
455
475
|
|
|
456
|
-

|
|
476
|
+

|
|
457
477
|
|
|
458
478
|
# Changelog for Stryke - Helpers
|
|
459
479
|
|
package/README.md
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
<div align="center">
|
|
7
7
|
<picture>
|
|
8
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://public.storm-cdn.com/storm-software/banner-1280x640-dark.gif">
|
|
9
|
-
<source media="(prefers-color-scheme: light)" srcset="https://public.storm-cdn.com/storm-software/banner-1280x640-light.gif">
|
|
10
|
-
<img src="https://public.storm-cdn.com/storm-software/banner-1280x640-dark.gif" width="100%" alt="Storm Software" />
|
|
8
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://public.storm-cdn.com/storm-software/media/banner-1280x640-dark.gif">
|
|
9
|
+
<source media="(prefers-color-scheme: light)" srcset="https://public.storm-cdn.com/storm-software/media/banner-1280x640-light.gif">
|
|
10
|
+
<img src="https://public.storm-cdn.com/storm-software/media/banner-1280x640-dark.gif" width="100%" alt="Storm Software" />
|
|
11
11
|
</picture>
|
|
12
12
|
</div>
|
|
13
13
|
<br />
|
|
@@ -280,9 +280,9 @@ specification. Contributions of any kind welcome!
|
|
|
280
280
|
|
|
281
281
|
<div align="center">
|
|
282
282
|
<picture>
|
|
283
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://public.storm-cdn.com/storm-software/banner-1280x320-dark.webp">
|
|
284
|
-
<source media="(prefers-color-scheme: light)" srcset="https://public.storm-cdn.com/storm-software/banner-1280x320-light.webp">
|
|
285
|
-
<img src="https://public.storm-cdn.com/storm-software/banner-1280x320-dark.webp" width="100%" alt="Storm Software" />
|
|
283
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://public.storm-cdn.com/storm-software/media/banner-1280x320-dark.webp">
|
|
284
|
+
<source media="(prefers-color-scheme: light)" srcset="https://public.storm-cdn.com/storm-software/media/banner-1280x320-light.webp">
|
|
285
|
+
<img src="https://public.storm-cdn.com/storm-software/media/banner-1280x320-dark.webp" width="100%" alt="Storm Software" />
|
|
286
286
|
</picture>
|
|
287
287
|
</div>
|
|
288
288
|
<br />
|
|
@@ -314,9 +314,9 @@ generation of development tools, please reach out on our
|
|
|
314
314
|
|
|
315
315
|
<br />
|
|
316
316
|
|
|
317
|
-
<div align="center"><a href="https://stormsoftware.com" target="_blank"><img src="https://public.storm-cdn.com/
|
|
317
|
+
<div align="center"><a href="https://stormsoftware.com" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://public.storm-cdn.com/storm-software/icons/circle-dark.webp"><source media="(prefers-color-scheme: light)" srcset="https://public.storm-cdn.com/storm-software/icons/circle-light.webp"><img src="https://public.storm-cdn.com/storm-software/icons/circle-dark.webp" width="200px" alt="Storm Software" /></picture></a></div>
|
|
318
318
|
<br />
|
|
319
|
-
<div align="center"><a href="https://stormsoftware.com" target="_blank"><img src="https://public.storm-cdn.com/visit-us-
|
|
319
|
+
<div align="center"><a href="https://stormsoftware.com" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://public.storm-cdn.com/misc/text/visit-us-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://public.storm-cdn.com/misc/text/visit-us-light.png"><img src="https://public.storm-cdn.com/misc/text/visit-us-dark.png" height="90px" alt="Visit us at stormsoftware.com" /></picture></a></div>
|
|
320
320
|
|
|
321
321
|
<br />
|
|
322
322
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arg-identity.mjs","names":[],"sources":["../src/arg-identity.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
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"}
|
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
|
|
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,KAAI,eAAe,KACjB,QAAO,IAAI,KAAK,IAAI,SAAS,CAAC;AAGhC,KAAI,eAAe,OACjB,QAAO,IAAI,OAAO,IAAI,QAAQ,IAAI,MAAM;AAG1C,KAAI,eAAe,KAAK;EACtB,MAAM,yBAAS,IAAI,KAAK;AACxB,OAAK,MAAM,CAAC,KAAK,UAAU,IAAI,SAAS,CACtC,QAAO,IAAI,KAAK,UAAU,MAAM,CAAC;AAEnC,SAAO;;AAGT,KAAI,eAAe,KAAK;EACtB,MAAM,yBAAS,IAAI,KAAK;AACxB,OAAK,MAAM,SAAS,IAAI,QAAQ,CAC9B,QAAO,IAAI,UAAU,MAAM,CAAC;AAE9B,SAAO;;AAGT,KAAI,aAAa,IAAI,EAAE;EAErB,MAAM,SAAS,KAAK,OAAO,eAAe,IAAI,EAAC,YAAa,IAAI,OAAO;AAEvE,OAAK,MAAM,CAAC,GAAG,YAAY,IAAI,SAAS,CACtC,QAAO,KAAK,UAAU,QAAQ;AAEhC,SAAO;;AAGT,KACE,eAAe,eACd,OAAO,sBAAsB,eAC5B,eAAe,kBAEjB,QAAO,CAAC,GAAI,IAAY;AAG1B,KAAI,eAAe,UAAU;EAC3B,MAAM,SAAS,IAAI,SAAS,CAAC,GAAI,IAAI,OAAe,CAAQ;AAC5D,kBAAgB,KAAK,OAAO;AAC5B,SAAO;;AAIT,KAAI,OAAO,SAAS,eAAe,eAAe,MAAM;EACtD,MAAM,SAAS,IAAI,KAAK,CAAC,IAAI,EAAE,IAAI,MAAM,EAAE,MAAM,IAAI,MAAM,CAAC;AAC5D,kBAAgB,KAAK,OAAO;AAC5B,SAAO;;AAGT,KAAI,eAAe,MAAM;EACvB,MAAM,SAAS,IAAI,KAAK,CAAC,IAAI,EAAE,EAAE,MAAM,IAAI,MAAM,CAAC;AAClD,kBAAgB,KAAK,OAAO;AAC5B,SAAO;;AAGT,KAAI,eAAe,OAAO;EACxB,MAAM,SAAS,IAAK,IAAI,aAAiC;AACzD,SAAO,UAAU,IAAI;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/deep-merge.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep-merge.mjs","names":[],"sources":["../src/deep-merge.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"deep-merge.mjs","names":[],"sources":["../src/deep-merge.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 { isFunction } from \"@stryke/type-checks/is-function\";\nimport { isMergeableObject } from \"@stryke/type-checks/is-mergeable-object\";\nimport { propertyUnsafe } from \"@stryke/type-checks/property-exists\";\n\nconst emptyTarget = (val: any) => {\n return Array.isArray(val) ? [] : {};\n};\n\nconst cloneUnlessOtherwiseSpecified = (\n value: any,\n options: {\n clone?: boolean;\n isMergeableObject: (value: any) => boolean;\n }\n) => {\n return options.clone !== false && options.isMergeableObject(value)\n ? deepMerge(emptyTarget(value), value, options)\n : value;\n};\n\nconst defaultArrayMerge = (target: any[], source: any[], options?: any) => {\n return [...target, ...source].map(element => {\n return cloneUnlessOtherwiseSpecified(element, options);\n });\n};\n\nconst getMergeFunction = (\n key: string,\n options: {\n customMerge?: (key: string) => any;\n }\n) => {\n if (!options.customMerge) {\n return deepMerge;\n }\n const customMerge = options.customMerge(key);\n\n return isFunction(customMerge) ? customMerge : deepMerge;\n};\n\nconst getKeys = (target: Record<string, any>) => {\n return [\n ...Object.keys(target),\n ...((Object.getOwnPropertySymbols\n ? Object.getOwnPropertySymbols(target).filter(symbol => {\n return Object.propertyIsEnumerable.call(target, symbol);\n })\n : []) as unknown as string[])\n ];\n};\n\nconst mergeObject = (\n target: Record<string, any>,\n source: Record<string, any>,\n options: {\n clone?: boolean;\n customMerge?: (key: string) => any;\n isMergeableObject: (value: any) => boolean;\n cloneUnlessOtherwiseSpecified?: (\n value: any,\n options: {\n clone: boolean;\n isMergeableObject: (value: any) => boolean;\n }\n ) => any;\n }\n) => {\n const destination: Record<string, any> = {};\n if (options.isMergeableObject(target)) {\n for (const key of getKeys(target)) {\n destination[key] = cloneUnlessOtherwiseSpecified(target[key], options);\n }\n }\n for (const key of getKeys(source)) {\n destination[key] =\n propertyUnsafe(target, key) && options.isMergeableObject(source[key])\n ? getMergeFunction(key, options)(target[key], source[key], options)\n : cloneUnlessOtherwiseSpecified(source[key], options);\n }\n return destination;\n};\n\nexport interface DeepMergeOptions {\n clone?: boolean;\n customMerge?: (key: string) => any;\n isMergeableObject: (value: any) => boolean;\n cloneUnlessOtherwiseSpecified: (\n value: any,\n options: {\n clone?: boolean;\n isMergeableObject: (value: any) => boolean;\n }\n ) => any;\n arrayMerge: (target: any[], source: any[], options: any) => any;\n}\n\n/**\n * Deep merge two objects\n *\n * @param target - The target object\n * @param source - The source object\n * @param options - The options object\n * @returns The merged object\n */\nexport function deepMerge<X = any | any[], Y = any | any[], Z = X & Y>(\n target: X,\n source: Y,\n options?: Partial<DeepMergeOptions>\n): Z {\n if (!target || !source) {\n return (target || source) as Z;\n }\n\n const opts = (options ?? {}) as DeepMergeOptions;\n opts.arrayMerge ??= defaultArrayMerge;\n opts.isMergeableObject ??= isMergeableObject;\n // cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge()\n // implementations can use it. The caller may not replace it.\n opts.cloneUnlessOtherwiseSpecified ??= cloneUnlessOtherwiseSpecified;\n\n const sourceIsArray = Array.isArray(source);\n const targetIsArray = Array.isArray(target);\n const sourceAndTargetTypesMatch = sourceIsArray === targetIsArray;\n\n if (!sourceAndTargetTypesMatch) {\n return cloneUnlessOtherwiseSpecified(source, opts);\n }\n if (sourceIsArray) {\n return opts.arrayMerge(target as any[], source, opts);\n }\n return mergeObject(target, source, opts) as Z;\n}\n\ndeepMerge.all = function deepMergeAll(array: any[], options?: any) {\n if (!Array.isArray(array)) {\n throw new TypeError(\"first argument should be an array\");\n }\n\n return array.reduce((prev, next) => {\n return deepMerge(prev, next, options);\n }, {});\n};\n"],"mappings":";;;;;AAsBA,MAAM,eAAe,QAAa;AAChC,QAAO,MAAM,QAAQ,IAAI,GAAG,EAAE,GAAG,EAAE;;AAGrC,MAAM,iCACJ,OACA,YAIG;AACH,QAAO,QAAQ,UAAU,SAAS,QAAQ,kBAAkB,MAAM,GAC9D,UAAU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AAEpD,KAAI,cACF,QAAO,KAAK,WAAW,QAAiB,QAAQ,KAAK;AAEvD,QAAO,YAAY,QAAQ,QAAQ,KAAK;;AAG1C,UAAU,MAAM,SAAS,aAAa,OAAc,SAAe;AACjE,KAAI,CAAC,MAAM,QAAQ,MAAM,CACvB,OAAM,IAAI,UAAU,oCAAoC;AAG1D,QAAO,MAAM,QAAQ,MAAM,SAAS;AAClC,SAAO,UAAU,MAAM,MAAM,QAAQ;IACpC,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter-empty.mjs","names":[],"sources":["../src/filter-empty.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatten-object.mjs","names":[],"sources":["../src/flatten-object.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
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.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-field.mjs","names":[],"sources":["../src/get-field.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 { toStringKey } from \"@stryke/convert\";\nimport { isDeepKey, isNumber } from \"@stryke/type-checks\";\nimport { toPath } from \"./to-path\";\n\n/**\n * See the definition of `@types/lodash`.\n */\ntype GetIndexedField<T, K> = K extends keyof T\n ? T[K]\n : K extends `${number}`\n ? \"length\" extends keyof T\n ? number extends T[\"length\"]\n ? number extends keyof T\n ? T[number]\n : undefined\n : undefined\n : undefined\n : undefined;\n\ntype FieldWithPossiblyUndefined<T, Key> =\n | GetField<Exclude<T, undefined>, Key>\n | Extract<T, undefined>;\n\ntype IndexedFieldWithPossiblyUndefined<T, Key> =\n | GetIndexedField<Exclude<T, undefined>, Key>\n | Extract<T, undefined>;\n\nexport type GetField<T, P> = P extends `${infer Left}.${infer Right}`\n ? Left extends keyof Exclude<T, undefined>\n ?\n | FieldWithPossiblyUndefined<Exclude<T, undefined>[Left], Right>\n | Extract<T, undefined>\n : Left extends `${infer FieldKey}[${infer IndexKey}]`\n ? FieldKey extends keyof T\n ? FieldWithPossiblyUndefined<\n IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey>,\n Right\n >\n : undefined\n : undefined\n : P extends keyof T\n ? T[P]\n : P extends `${infer FieldKey}[${infer IndexKey}]`\n ? FieldKey extends keyof T\n ? IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey>\n : undefined\n : IndexedFieldWithPossiblyUndefined<T, P>;\n\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K - The type of the key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value.\n */\nexport function getField<T extends object, K extends keyof T>(\n object: T,\n path: K | readonly [K]\n): T[K];\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K - The type of the key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value or undefined.\n */\nexport function getField<T extends object, K extends keyof T>(\n object: T | null | undefined,\n path: K | readonly [K]\n): T[K] | undefined;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K - The type of the key in the object.\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<T extends object, K extends keyof T, D>(\n object: T | null | undefined,\n path: K | readonly [K],\n defaultValue: D\n): Exclude<T[K], undefined> | D;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1]\n>(object: T, path: readonly [K1, K2]): T[K1][K2];\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value or undefined.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1]\n>(object: T | null | undefined, path: readonly [K1, K2]): T[K1][K2] | undefined;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n D\n>(\n object: T | null | undefined,\n path: readonly [K1, K2],\n defaultValue: D\n): Exclude<T[K1][K2], undefined> | D;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2]\n>(object: T, path: readonly [K1, K2, K3]): T[K1][K2][K3];\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value or undefined.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2]\n>(\n object: T | null | undefined,\n path: readonly [K1, K2, K3]\n): T[K1][K2][K3] | undefined;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2],\n D\n>(\n object: T | null | undefined,\n path: readonly [K1, K2, K3],\n defaultValue: D\n): Exclude<T[K1][K2][K3], undefined> | D;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n * @typeParam K4 - The type of the fourth key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2],\n K4 extends keyof T[K1][K2][K3]\n>(object: T, path: readonly [K1, K2, K3, K4]): T[K1][K2][K3][K4];\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n * @typeParam K4 - The type of the fourth key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value or undefined.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2],\n K4 extends keyof T[K1][K2][K3]\n>(\n object: T | null | undefined,\n path: readonly [K1, K2, K3, K4]\n): T[K1][K2][K3][K4] | undefined;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n * @typeParam K4 - The type of the fourth key in the object.\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2],\n K4 extends keyof T[K1][K2][K3],\n D\n>(\n object: T | null | undefined,\n path: readonly [K1, K2, K3, K4],\n defaultValue: D\n): Exclude<T[K1][K2][K3][K4], undefined> | D;\n/**\n * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value.\n */\nexport function getField<T>(object: Record<number, T>, path: number): T;\n/**\n * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value or undefined.\n */\nexport function getField<T>(\n object: Record<number, T> | null | undefined,\n path: number\n): T | undefined;\n/**\n * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the value.\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<T, D>(\n object: Record<number, T> | null | undefined,\n path: number,\n defaultValue: D\n): T | D;\n/**\n * Retrieves the value at a given path from a null or undefined object, returning the default value.\n *\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The default value.\n */\nexport function getField<D>(\n object: null | undefined,\n path: PropertyKey,\n defaultValue: D\n): D;\n\n/**\n * Retrieves the value at a given path from a null or undefined object, returning undefined.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n */\nexport function getField(\n object: null | undefined,\n path: PropertyKey\n): undefined;\n\n/**\n * Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam P - The type of the path.\n *\n * @param data - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value, or any if path is a general string.\n */\nexport function getField<T, P extends string>(\n data: T,\n path: P\n): string extends P ? any : GetField<T, P>;\n/**\n * Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam P - The type of the path.\n * @typeParam D - The type of the default value.\n *\n * @param data - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<T, P extends string, D = GetField<T, P>>(\n data: T,\n path: P,\n defaultValue: D\n): Exclude<GetField<T, P>, null | undefined> | D;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value.\n */\nexport function getField(\n object: unknown,\n path: PropertyKey | readonly PropertyKey[],\n defaultValue?: unknown\n): any;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value.\n */\nexport function getField(\n object: any,\n path: PropertyKey | readonly PropertyKey[],\n defaultValue?: any\n): any {\n if (object === null) {\n return defaultValue;\n }\n\n switch (typeof path) {\n case \"string\": {\n const result = object[path];\n\n if (result === undefined) {\n if (isDeepKey(path)) {\n return getField(object, toPath(path), defaultValue);\n }\n return defaultValue;\n }\n\n return result;\n }\n case \"number\":\n case \"symbol\": {\n if (isNumber(path)) {\n path = toStringKey(path);\n }\n\n const result = Array.isArray(path)\n ? undefined\n : object[path as PropertyKey];\n if (result === undefined) {\n return defaultValue;\n }\n\n return result;\n }\n case \"bigint\":\n case \"boolean\":\n case \"undefined\":\n case \"object\":\n case \"function\":\n default: {\n if (Array.isArray(path)) {\n return getWithPath(object, path, defaultValue);\n }\n\n path = Object.is(path?.valueOf(), -0) ? \"-0\" : String(path);\n\n const result = object[path];\n\n if (result === undefined) {\n return defaultValue;\n }\n\n return result;\n }\n }\n}\n\nfunction getWithPath(\n object: any,\n path: readonly PropertyKey[],\n defaultValue?: any\n): any {\n if (path.length === 0) {\n return defaultValue;\n }\n\n let current = object;\n\n for (const element of path) {\n if (current === null) {\n return defaultValue;\n }\n\n current = current[element];\n }\n\n if (current === undefined) {\n return defaultValue;\n }\n\n return current;\n}\n"],"mappings":";;;;;;;;;;;;;AAkaA,SAAgB,SACd,QACA,MACA,cACK;AACL,KAAI,WAAW,KACb,QAAO;AAGT,SAAQ,OAAO,MAAf;EACE,KAAK,UAAU;GACb,MAAM,SAAS,OAAO;AAEtB,OAAI,WAAW,QAAW;AACxB,QAAI,UAAU,KAAK,CACjB,QAAO,SAAS,QAAQ,OAAO,KAAK,EAAE,aAAa;AAErD,WAAO;;AAGT,UAAO;;EAET,KAAK;EACL,KAAK,UAAU;AACb,OAAI,SAAS,KAAK,CAChB,QAAO,YAAY,KAAK;GAG1B,MAAM,SAAS,MAAM,QAAQ,KAAK,GAC9B,SACA,OAAO;AACX,OAAI,WAAW,OACb,QAAO;AAGT,UAAO;;EAOT,SAAS;AACP,OAAI,MAAM,QAAQ,KAAK,CACrB,QAAO,YAAY,QAAQ,MAAM,aAAa;AAGhD,UAAO,OAAO,GAAG,MAAM,SAAS,EAAE,GAAG,GAAG,OAAO,OAAO,KAAK;GAE3D,MAAM,SAAS,OAAO;AAEtB,OAAI,WAAW,OACb,QAAO;AAGT,UAAO;;;;AAKb,SAAS,YACP,QACA,MACA,cACK;AACL,KAAI,KAAK,WAAW,EAClB,QAAO;CAGT,IAAI,UAAU;AAEd,MAAK,MAAM,WAAW,MAAM;AAC1B,MAAI,YAAY,KACd,QAAO;AAGT,YAAU,QAAQ;;AAGpB,KAAI,YAAY,OACd,QAAO;AAGT,QAAO"}
|
|
1
|
+
{"version":3,"file":"get-field.mjs","names":[],"sources":["../src/get-field.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 { toStringKey } from \"@stryke/convert\";\nimport { isDeepKey, isNumber } from \"@stryke/type-checks\";\nimport { toPath } from \"./to-path\";\n\n/**\n * See the definition of `@types/lodash`.\n */\ntype GetIndexedField<T, K> = K extends keyof T\n ? T[K]\n : K extends `${number}`\n ? \"length\" extends keyof T\n ? number extends T[\"length\"]\n ? number extends keyof T\n ? T[number]\n : undefined\n : undefined\n : undefined\n : undefined;\n\ntype FieldWithPossiblyUndefined<T, Key> =\n | GetField<Exclude<T, undefined>, Key>\n | Extract<T, undefined>;\n\ntype IndexedFieldWithPossiblyUndefined<T, Key> =\n | GetIndexedField<Exclude<T, undefined>, Key>\n | Extract<T, undefined>;\n\nexport type GetField<T, P> = P extends `${infer Left}.${infer Right}`\n ? Left extends keyof Exclude<T, undefined>\n ?\n | FieldWithPossiblyUndefined<Exclude<T, undefined>[Left], Right>\n | Extract<T, undefined>\n : Left extends `${infer FieldKey}[${infer IndexKey}]`\n ? FieldKey extends keyof T\n ? FieldWithPossiblyUndefined<\n IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey>,\n Right\n >\n : undefined\n : undefined\n : P extends keyof T\n ? T[P]\n : P extends `${infer FieldKey}[${infer IndexKey}]`\n ? FieldKey extends keyof T\n ? IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey>\n : undefined\n : IndexedFieldWithPossiblyUndefined<T, P>;\n\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K - The type of the key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value.\n */\nexport function getField<T extends object, K extends keyof T>(\n object: T,\n path: K | readonly [K]\n): T[K];\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K - The type of the key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value or undefined.\n */\nexport function getField<T extends object, K extends keyof T>(\n object: T | null | undefined,\n path: K | readonly [K]\n): T[K] | undefined;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K - The type of the key in the object.\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<T extends object, K extends keyof T, D>(\n object: T | null | undefined,\n path: K | readonly [K],\n defaultValue: D\n): Exclude<T[K], undefined> | D;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1]\n>(object: T, path: readonly [K1, K2]): T[K1][K2];\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value or undefined.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1]\n>(object: T | null | undefined, path: readonly [K1, K2]): T[K1][K2] | undefined;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n D\n>(\n object: T | null | undefined,\n path: readonly [K1, K2],\n defaultValue: D\n): Exclude<T[K1][K2], undefined> | D;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2]\n>(object: T, path: readonly [K1, K2, K3]): T[K1][K2][K3];\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value or undefined.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2]\n>(\n object: T | null | undefined,\n path: readonly [K1, K2, K3]\n): T[K1][K2][K3] | undefined;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2],\n D\n>(\n object: T | null | undefined,\n path: readonly [K1, K2, K3],\n defaultValue: D\n): Exclude<T[K1][K2][K3], undefined> | D;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n * @typeParam K4 - The type of the fourth key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2],\n K4 extends keyof T[K1][K2][K3]\n>(object: T, path: readonly [K1, K2, K3, K4]): T[K1][K2][K3][K4];\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n * @typeParam K4 - The type of the fourth key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value or undefined.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2],\n K4 extends keyof T[K1][K2][K3]\n>(\n object: T | null | undefined,\n path: readonly [K1, K2, K3, K4]\n): T[K1][K2][K3][K4] | undefined;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n * @typeParam K4 - The type of the fourth key in the object.\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2],\n K4 extends keyof T[K1][K2][K3],\n D\n>(\n object: T | null | undefined,\n path: readonly [K1, K2, K3, K4],\n defaultValue: D\n): Exclude<T[K1][K2][K3][K4], undefined> | D;\n/**\n * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value.\n */\nexport function getField<T>(object: Record<number, T>, path: number): T;\n/**\n * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value or undefined.\n */\nexport function getField<T>(\n object: Record<number, T> | null | undefined,\n path: number\n): T | undefined;\n/**\n * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the value.\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<T, D>(\n object: Record<number, T> | null | undefined,\n path: number,\n defaultValue: D\n): T | D;\n/**\n * Retrieves the value at a given path from a null or undefined object, returning the default value.\n *\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The default value.\n */\nexport function getField<D>(\n object: null | undefined,\n path: PropertyKey,\n defaultValue: D\n): D;\n\n/**\n * Retrieves the value at a given path from a null or undefined object, returning undefined.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n */\nexport function getField(\n object: null | undefined,\n path: PropertyKey\n): undefined;\n\n/**\n * Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam P - The type of the path.\n *\n * @param data - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value, or any if path is a general string.\n */\nexport function getField<T, P extends string>(\n data: T,\n path: P\n): string extends P ? any : GetField<T, P>;\n/**\n * Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam P - The type of the path.\n * @typeParam D - The type of the default value.\n *\n * @param data - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<T, P extends string, D = GetField<T, P>>(\n data: T,\n path: P,\n defaultValue: D\n): Exclude<GetField<T, P>, null | undefined> | D;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value.\n */\nexport function getField(\n object: unknown,\n path: PropertyKey | readonly PropertyKey[],\n defaultValue?: unknown\n): any;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value.\n */\nexport function getField(\n object: any,\n path: PropertyKey | readonly PropertyKey[],\n defaultValue?: any\n): any {\n if (object === null) {\n return defaultValue;\n }\n\n switch (typeof path) {\n case \"string\": {\n const result = object[path];\n\n if (result === undefined) {\n if (isDeepKey(path)) {\n return getField(object, toPath(path), defaultValue);\n }\n return defaultValue;\n }\n\n return result;\n }\n case \"number\":\n case \"symbol\": {\n if (isNumber(path)) {\n path = toStringKey(path);\n }\n\n const result = Array.isArray(path)\n ? undefined\n : object[path as PropertyKey];\n if (result === undefined) {\n return defaultValue;\n }\n\n return result;\n }\n case \"bigint\":\n case \"boolean\":\n case \"undefined\":\n case \"object\":\n case \"function\":\n default: {\n if (Array.isArray(path)) {\n return getWithPath(object, path, defaultValue);\n }\n\n path = Object.is(path?.valueOf(), -0) ? \"-0\" : String(path);\n\n const result = object[path];\n\n if (result === undefined) {\n return defaultValue;\n }\n\n return result;\n }\n }\n}\n\nfunction getWithPath(\n object: any,\n path: readonly PropertyKey[],\n defaultValue?: any\n): any {\n if (path.length === 0) {\n return defaultValue;\n }\n\n let current = object;\n\n for (const element of path) {\n if (current === null) {\n return defaultValue;\n }\n\n current = current[element];\n }\n\n if (current === undefined) {\n return defaultValue;\n }\n\n return current;\n}\n"],"mappings":";;;;;;;;;;;;;AAkaA,SAAgB,SACd,QACA,MACA,cACK;AACL,KAAI,WAAW,KACb,QAAO;AAGT,SAAQ,OAAO,MAAf;EACE,KAAK,UAAU;GACb,MAAM,SAAS,OAAO;AAEtB,OAAI,WAAW,QAAW;AACxB,QAAI,UAAU,KAAK,CACjB,QAAO,SAAS,QAAQ,OAAO,KAAK,EAAE,aAAa;AAErD,WAAO;;AAGT,UAAO;;EAET,KAAK;EACL,KAAK,UAAU;AACb,OAAI,SAAS,KAAK,CAChB,QAAO,YAAY,KAAK;GAG1B,MAAM,SAAS,MAAM,QAAQ,KAAK,GAC9B,SACA,OAAO;AACX,OAAI,WAAW,OACb,QAAO;AAGT,UAAO;;EAOT,SAAS;AACP,OAAI,MAAM,QAAQ,KAAK,CACrB,QAAO,YAAY,QAAQ,MAAM,aAAa;AAGhD,UAAO,OAAO,GAAG,MAAM,SAAS,EAAE,GAAG,GAAG,OAAO,OAAO,KAAK;GAE3D,MAAM,SAAS,OAAO;AAEtB,OAAI,WAAW,OACb,QAAO;AAGT,UAAO;;;;AAKb,SAAS,YACP,QACA,MACA,cACK;AACL,KAAI,KAAK,WAAW,EAClB,QAAO;CAGT,IAAI,UAAU;AAEd,MAAK,MAAM,WAAW,MAAM;AAC1B,MAAI,YAAY,KACd,QAAO;AAGT,YAAU,QAAQ;;AAGpB,KAAI,YAAY,OACd,QAAO;AAGT,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-ordered-by.mjs","names":[],"sources":["../src/get-ordered-by.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"get-ordered-by.mjs","names":[],"sources":["../src/get-ordered-by.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\ntype Order = \"asc\" | \"desc\";\n\n/**\n * Sorts an array of objects based on multiple properties and their corresponding order directions.\n *\n * @remarks\n * This function takes an array of objects, an array of keys to sort by, and an array of order directions.\n * It returns the sorted array, ordering by each key according to its corresponding direction\n * ('asc' for ascending or 'desc' for descending). If values for a key are equal,\n * it moves to the next key to determine the order.\n *\n * @example\n * ```typescript\n * // Sort an array of objects by 'user' in ascending order and 'age' in descending order.\n * const users = [\n * { user: 'fred', age: 48 },\n * { user: 'barney', age: 34 },\n * { user: 'fred', age: 40 },\n * { user: 'barney', age: 36 },\n * ];\n * const result = orderBy(users, ['user', 'age'], ['asc', 'desc']);\n * // result will be:\n * // [\n * // { user: 'barney', age: 36 },\n * // { user: 'barney', age: 34 },\n * // { user: 'fred', age: 48 },\n * // { user: 'fred', age: 40 },\n * // ]\n * ```\n *\n * @param collection - The array of objects to be sorted.\n * @param keys - An array of keys (properties) by which to sort.\n * @param orders - An array of order directions ('asc' for ascending or 'desc' for descending).\n * @returns The sorted array.\n */\nexport function getOrderedBy<T>(\n collection: T[],\n keys: (keyof T)[],\n orders: Order[]\n): T[] {\n const compareValues = (a: T[keyof T], b: T[keyof T], order: Order) => {\n if (a < b) {\n return order === \"asc\" ? -1 : 1;\n }\n if (a > b) {\n return order === \"asc\" ? 1 : -1;\n }\n return 0;\n };\n\n const effectiveOrders = keys.map(\n (_, index) => orders[index] ?? orders.at(-1)\n );\n\n return [...collection].sort((a, b) => {\n for (const [i, key] of keys.entries()) {\n const order = effectiveOrders[i];\n const result = compareValues(a[key], b[key], order!);\n if (result !== 0) {\n return result;\n }\n }\n return 0;\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,SAAgB,aACd,YACA,MACA,QACK;CACL,MAAM,iBAAiB,GAAe,GAAe,UAAiB;AACpE,MAAI,IAAI,EACN,QAAO,UAAU,QAAQ,KAAK;AAEhC,MAAI,IAAI,EACN,QAAO,UAAU,QAAQ,IAAI;AAE/B,SAAO;;CAGT,MAAM,kBAAkB,KAAK,KAC1B,GAAG,UAAU,OAAO,UAAU,OAAO,GAAG,GAAG,CAC7C;AAED,QAAO,CAAC,GAAG,WAAW,CAAC,MAAM,GAAG,MAAM;AACpC,OAAK,MAAM,CAAC,GAAG,QAAQ,KAAK,SAAS,EAAE;GACrC,MAAM,QAAQ,gBAAgB;GAC9B,MAAM,SAAS,cAAc,EAAE,MAAM,EAAE,MAAM,MAAO;AACpD,OAAI,WAAW,EACb,QAAO;;AAGX,SAAO;GACP"}
|
package/dist/get-unique.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-unique.mjs","names":[],"sources":["../src/get-unique.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"get-unique.mjs","names":[],"sources":["../src/get-unique.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 * Returns an array of unique values from the given array.\n *\n * @param arr - The array to get unique values from.\n * @returns An array of unique values.\n */\nexport const getUnique = <T = any>(arr: T[]): T[] => {\n return [...new Set(arr)];\n};\n\n/**\n * Returns a new array containing only the unique elements from the original array,\n * based on the values returned by the mapper function.\n *\n * @example\n * ```ts\n * uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor);\n * // [1.2, 2.1, 3.2, 5.7, 7.19]\n * ```\n *\n * @param arr - The array to process.\n * @param mapper - The function used to convert the array elements.\n * @returns A new array containing only the unique elements from the original array, based on the values returned by the mapper function.\n */\nexport function getUniqueBy<T, U>(\n arr: readonly T[],\n mapper: (item: T) => U = item => item as unknown as U\n): T[] {\n const map = new Map<U, T>();\n\n for (const item of arr) {\n const key = mapper(item);\n\n if (!map.has(key)) {\n map.set(key, item);\n }\n }\n\n return [...map.values()];\n}\n"],"mappings":";;;;;;;AAwBA,MAAa,aAAsB,QAAkB;AACnD,QAAO,CAAC,GAAG,IAAI,IAAI,IAAI,CAAC;;;;;;;;;;;;;;;;AAiB1B,SAAgB,YACd,KACA,UAAyB,SAAQ,MAC5B;CACL,MAAM,sBAAM,IAAI,KAAW;AAE3B,MAAK,MAAM,QAAQ,KAAK;EACtB,MAAM,MAAM,OAAO,KAAK;AAExB,MAAI,CAAC,IAAI,IAAI,IAAI,CACf,KAAI,IAAI,KAAK,KAAK;;AAItB,QAAO,CAAC,GAAG,IAAI,QAAQ,CAAC"}
|
package/dist/identity.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.mjs","names":[],"sources":["../src/identity.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"identity.mjs","names":[],"sources":["../src/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 * Returns the input value unchanged.\n *\n * @example\n * ```ts\n * identity(5); // Returns 5\n * identity('hello'); // Returns 'hello'\n * identity({ key: 'value' }); // Returns { key: 'value' }\n * ```\n *\n * @param x - The value to be returned.\n * @returns The input value.\n */\nexport function identity<T>(x: T): T {\n return x;\n}\n"],"mappings":";;;;;;;;;;;;;;AA+BA,SAAgB,SAAY,GAAS;AACnC,QAAO"}
|
package/dist/is-equal.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-equal.mjs","names":[],"sources":["../src/is-equal.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"is-equal.mjs","names":[],"sources":["../src/is-equal.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 { isSet } from \"@stryke/type-checks/is-set\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\n\nconst hasMap = typeof Map === \"function\";\nconst hasSet = typeof Set === \"function\";\nconst hasArrayBuffer =\n typeof ArrayBuffer === \"function\" && ArrayBuffer.isView !== undefined;\n\nfunction equal(a: any, b: any) {\n if (a === b) {\n return true;\n }\n\n if (a && b && typeof a === \"object\" && typeof b === \"object\") {\n if (a.constructor !== b.constructor) {\n return false;\n }\n\n let length;\n if (Array.isArray(a)) {\n length = a.length;\n\n if (length != b.length) return false;\n for (let i = length; i-- !== 0; ) if (!equal(a[i], b[i])) return false;\n return true;\n }\n\n let it;\n if (hasMap && a instanceof Map && b instanceof Map) {\n if (a.size !== b.size) return false;\n it = a.entries();\n let i;\n while (!(i = it.next()).done) if (!b.has(i.value[0])) return false;\n it = a.entries();\n while (!(i = it.next()).done) {\n if (!equal(i.value[1], b.get(i.value[0]))) return false;\n }\n return true;\n }\n\n if (hasSet && a instanceof Set && b instanceof Set) {\n if (a.size !== b.size) return false;\n it = a.entries();\n let i;\n while (!(i = it.next()).done) if (!b.has(i.value[0])) return false;\n return true;\n }\n\n if (\n Array.isArray(a) &&\n Array.isArray(b) &&\n hasArrayBuffer &&\n ArrayBuffer.isView(a) &&\n ArrayBuffer.isView(b)\n ) {\n length = a.length;\n\n if (length != b.length) return false;\n for (let i = length; i-- !== 0; ) if (a[i] !== b[i]) return false;\n return true;\n }\n\n if (a.constructor === RegExp) {\n return a.source === b.source && a.flags === b.flags;\n }\n\n if (\n a.valueOf !== Object.prototype.valueOf &&\n typeof a.valueOf === \"function\" &&\n typeof b.valueOf === \"function\"\n ) {\n // eslint-disable-next-line ts/no-unsafe-call\n return a.valueOf() === b.valueOf();\n }\n if (\n a.toString !== Object.prototype.toString &&\n typeof a.toString === \"function\" &&\n typeof b.toString === \"function\"\n ) {\n // eslint-disable-next-line ts/no-unsafe-call\n return a.toString() === b.toString();\n }\n\n const keys = Object.keys(a);\n length = keys.length;\n if (length !== Object.keys(b).length) {\n return false;\n }\n\n for (let i = length; i-- !== 0; ) {\n if (\n !isSet(i) ||\n !isSetString(keys[i]) ||\n !Object.prototype.hasOwnProperty.call(b, keys[i] as any)\n ) {\n return false;\n }\n }\n\n for (let i = length; i-- !== 0; ) {\n if (\n Array.isArray(keys) &&\n (keys[i] === \"_owner\" || keys[i] === \"__v\" || keys[i] === \"__o\") &&\n a.$$typeof\n ) {\n continue;\n }\n\n if (\n !isSet(i) ||\n !isSetString(keys[i]) ||\n !equal(a[keys[i] as any], b[keys[i] as any])\n ) {\n return false;\n }\n }\n\n return true;\n }\n\n // eslint-disable-next-line no-self-compare\n return a !== a && b !== b;\n}\n\n/**\n * Checks if two values are equal, including support for `Date`, `RegExp`, and deep object comparison.\n *\n * @example\n * ```ts\n * isEqual(1, 1); // true\n * isEqual({ a: 1 }, { a: 1 }); // true\n * isEqual(/abc/g, /abc/g); // true\n * isEqual(new Date('2020-01-01'), new Date('2020-01-01')); // true\n * isEqual([1, 2, 3], [1, 2, 3]); // true\n * isEqual({ a: 1, b: { c: 2 } }, { a: 1, b: { c: 2 } }); // true\n * ```\n *\n * @param a - The first value to compare.\n * @param b - The second value to compare.\n * @returns `true` if the values are equal, otherwise `false`.\n */\nexport function isEqual(a: any, b: any): boolean {\n try {\n return equal(a, b);\n } catch (error) {\n if (/stack|recursion/i.test((error as any)?.message || \"\")) {\n // eslint-disable-next-line no-console\n console.warn(\"isEqual cannot handle circular refs\");\n\n return false;\n }\n\n throw error;\n }\n}\n"],"mappings":";;;;AAqBA,MAAM,SAAS,OAAO,QAAQ;AAC9B,MAAM,SAAS,OAAO,QAAQ;AAC9B,MAAM,iBACJ,OAAO,gBAAgB,cAAc,YAAY,WAAW;AAE9D,SAAS,MAAM,GAAQ,GAAQ;AAC7B,KAAI,MAAM,EACR,QAAO;AAGT,KAAI,KAAK,KAAK,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU;AAC5D,MAAI,EAAE,gBAAgB,EAAE,YACtB,QAAO;EAGT,IAAI;AACJ,MAAI,MAAM,QAAQ,EAAE,EAAE;AACpB,YAAS,EAAE;AAEX,OAAI,UAAU,EAAE,OAAQ,QAAO;AAC/B,QAAK,IAAI,IAAI,QAAQ,QAAQ,GAAK,KAAI,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,CAAE,QAAO;AACjE,UAAO;;EAGT,IAAI;AACJ,MAAI,UAAU,aAAa,OAAO,aAAa,KAAK;AAClD,OAAI,EAAE,SAAS,EAAE,KAAM,QAAO;AAC9B,QAAK,EAAE,SAAS;GAChB,IAAI;AACJ,UAAO,EAAE,IA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AQ,QAAQ,GAC3B,KACE,CAAC,MAAM,EAAE,IACT,CAAC,YAAY,KAAK,GAAG,IACrB,CAAC,OAAO,UAAU,eAAe,KAAK,GAAG,KAAK,GAAU,CAExD,QAAO;AAIX,OAAK,IAAI,IAAI,QAAQ,QAAQ,IAAK;AAChC,OACE,MAAM,QAAQ,KAAK,KAClB,KAAK,OAAO,YAAY,KAAK,OAAO,SAAS,KAAK,OAAO,UAC1D,EAAE,SAEF;AAGF,OACE,CAAC,MAAM,EAAE,IACT,CAAC,YAAY,KAAK,GAAG,IACrB,CAAC,MAAM,EAAE,KAAK,KAAY,EAAE,KAAK,IAAW,CAE5C,QAAO;;AAIX,SAAO;;AAIT,QAAO,MAAM,KAAK,MAAM;;;;;;;;;;;;;;;;;;;AAoB1B,SAAgB,QAAQ,GAAQ,GAAiB;AAC/C,KAAI;AACF,SAAO,MAAM,GAAG,EAAE;UACX,OAAO;AACd,MAAI,mBAAmB,KAAM,OAAe,WAAW,GAAG,EAAE;AAE1D,WAAQ,KAAK,sCAAsC;AAEnD,UAAO;;AAGT,QAAM"}
|
package/dist/lru-cache.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lru-cache.mjs","names":[],"sources":["../src/lru-cache.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\nclass LRUNode<T> {\n public readonly key: string;\n\n public data: T;\n\n public size: number;\n\n public prev: LRUNode<T> | SentinelNode<T> | null = null;\n\n public next: LRUNode<T> | SentinelNode<T> | null = null;\n\n constructor(key: string, data: T, size: number) {\n this.key = key;\n this.data = data;\n this.size = size;\n }\n}\n\n/**\n * Sentinel node used for head/tail boundaries.\n * These nodes don't contain actual cache data but simplify list operations.\n */\nclass SentinelNode<T> {\n public prev: LRUNode<T> | SentinelNode<T> | null = null;\n\n public next: LRUNode<T> | SentinelNode<T> | null = null;\n}\n\n/**\n * LRU (Least Recently Used) Cache implementation using a doubly-linked list\n * and hash map for O(1) operations.\n *\n * Algorithm:\n * - Uses a doubly-linked list to maintain access order (most recent at head)\n * - Hash map provides O(1) key-to-node lookup\n * - Sentinel head/tail nodes simplify edge case handling\n * - Size-based eviction supports custom size calculation functions\n *\n * Data Structure Layout:\n * HEAD \\<-\\> [most recent] \\<-\\> ... \\<-\\> [least recent] \\<-\\> TAIL\n *\n * Operations:\n * - get(): Move accessed node to head (mark as most recent)\n * - set(): Add new node at head, evict from tail if over capacity\n * - Eviction: Remove least recent node (tail.prev) when size exceeds limit\n */\nexport class LRUCache<T> {\n private readonly cache: Map<string, LRUNode<T>> = new Map();\n\n private readonly head: SentinelNode<T>;\n\n private readonly tail: SentinelNode<T>;\n\n private totalSize: number = 0;\n\n private readonly maxSize: number;\n\n private readonly calculateSize: ((value: T) => number) | undefined;\n\n constructor(maxSize: number, calculateSize?: (value: T) => number) {\n this.maxSize = maxSize;\n this.calculateSize = calculateSize;\n\n // Create sentinel nodes to simplify doubly-linked list operations\n // HEAD <-> TAIL (empty list)\n this.head = new SentinelNode<T>();\n this.tail = new SentinelNode<T>();\n this.head.next = this.tail;\n this.tail.prev = this.head;\n }\n\n /**\n * Adds a node immediately after the head (marks as most recently used). Used when inserting new items or when an item is accessed. **PRECONDITION:** node must be disconnected (prev/next should be null)\n *\n * @param node - The node to add after the head.\n */\n private addToHead(node: LRUNode<T>): void {\n node.prev = this.head;\n node.next = this.head.next;\n // head.next is always non-null (points to tail or another node)\n this.head.next!.prev = node;\n this.head.next = node;\n }\n\n /**\n * Removes a node from its current position in the doubly-linked list. Updates the prev/next pointers of adjacent nodes to maintain list integrity. **PRECONDITION:** node must be connected (prev/next are non-null)\n *\n * @param node - The node to remove from the list.\n */\n private removeNode(node: LRUNode<T>): void {\n // Connected nodes always have non-null prev/next\n node.prev!.next = node.next;\n node.next!.prev = node.prev;\n }\n\n /**\n * Moves an existing node to the head position (marks as most recently used). This is the core LRU operation - accessed items become most recent.\n *\n * @param node - The node to move to the head.\n */\n private moveToHead(node: LRUNode<T>): void {\n this.removeNode(node);\n this.addToHead(node);\n }\n\n /**\n * Removes and returns the least recently used node (the one before tail). This is called during eviction when the cache exceeds capacity. **PRECONDITION:** cache is not empty (ensured by caller)\n *\n * @returns The removed least recently used node.\n */\n private removeTail(): LRUNode<T> {\n const lastNode = this.tail.prev as LRUNode<T>;\n // tail.prev is always non-null and always LRUNode when cache is not empty\n this.removeNode(lastNode);\n return lastNode;\n }\n\n /**\n * Sets a key-value pair in the cache.\n * If the key exists, updates the value and moves to head.\n * If new, adds at head and evicts from tail if necessary.\n *\n * Time Complexity:\n * - O(1) for uniform item sizes\n * - O(k) where k is the number of items evicted (can be O(N) for variable sizes)\n *\n * @param key - The key to set.\n * @param value - The value to set.\n */\n public set(key: string, value: T): void {\n const size = this.calculateSize?.(value) ?? 1;\n if (size > this.maxSize) {\n // console.warn(\"Single item size exceeds maxSize\");\n return;\n }\n\n const existing = this.cache.get(key);\n if (existing) {\n // Update existing node: adjust size and move to head (most recent)\n existing.data = value;\n this.totalSize = this.totalSize - existing.size + size;\n existing.size = size;\n this.moveToHead(existing);\n } else {\n // Add new node at head (most recent position)\n const newNode = new LRUNode(key, value, size);\n this.cache.set(key, newNode);\n this.addToHead(newNode);\n this.totalSize += size;\n }\n\n // Evict least recently used items until under capacity\n while (this.totalSize > this.maxSize && this.cache.size > 0) {\n const tail = this.removeTail();\n this.cache.delete(tail.key);\n this.totalSize -= tail.size;\n }\n }\n\n /**\n * Checks if a key exists in the cache.\n * This is a pure query operation - does NOT update LRU order.\n *\n * Time Complexity: O(1)\n */\n public has(key: string): boolean {\n return this.cache.has(key);\n }\n\n /**\n * Retrieves a value by key and marks it as most recently used.\n * Moving to head maintains the LRU property for future evictions.\n *\n * Time Complexity: O(1)\n */\n public get(key: string): T | undefined {\n const node = this.cache.get(key);\n if (!node) return undefined;\n\n // Mark as most recently used by moving to head\n this.moveToHead(node);\n\n return node.data;\n }\n\n /**\n * Returns an iterator over the cache entries. The order is outputted in the\n * order of most recently used to least recently used.\n */\n public *[Symbol.iterator](): IterableIterator<[string, T]> {\n let current = this.head.next;\n while (current && current !== this.tail) {\n // Between head and tail, current is always LRUNode\n const node = current as LRUNode<T>;\n yield [node.key, node.data];\n current = current.next;\n }\n }\n\n /**\n * Removes a specific key from the cache.\n * Updates both the hash map and doubly-linked list.\n *\n * Time Complexity: O(1)\n */\n public remove(key: string): void {\n const node = this.cache.get(key);\n if (!node) return;\n\n this.removeNode(node);\n this.cache.delete(key);\n this.totalSize -= node.size;\n }\n\n /**\n * Returns the number of items in the cache.\n */\n public get size(): number {\n return this.cache.size;\n }\n\n /**\n * Returns the current total size of all cached items.\n * This uses the custom size calculation if provided.\n */\n public get currentSize(): number {\n return this.totalSize;\n }\n}\n"],"mappings":";AAkBA,IAAM,UAAN,MAAiB;CACf,AAAgB;CAEhB,AAAO;CAEP,AAAO;CAEP,AAAO,OAA4C;CAEnD,AAAO,OAA4C;CAEnD,YAAY,KAAa,MAAS,MAAc;AAC9C,OAAK,MAAM;AACX,OAAK,OAAO;AACZ,OAAK,OAAO;;;;;;;AAQhB,IAAM,eAAN,MAAsB;CACpB,AAAO,OAA4C;CAEnD,AAAO,OAA4C;;;;;;;;;;;;;;;;;;;;AAqBrD,IAAa,WAAb,MAAyB;CACvB,AAAiB,wBAAiC,IAAI,KAAK;CAE3D,AAAiB;CAEjB,AAAiB;CAEjB,AAAQ,YAAoB;CAE5B,AAAiB;CAEjB,AAAiB;CAEjB,YAAY,SAAiB,eAAsC;AACjE,OAAK,UAAU;AACf,OAAK,gBAAgB;AAIrB,OAA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AM,OAAO,KAAK,MAAM,IAAI,IAAI;AAChC,MAAI,CAAC,KAAM,QAAO;AAGlB,OAAK,WAAW,KAAK;AAErB,SAAO,KAAK;;;;;;CAOd,EAAS,OAAO,YAA2C;EACzD,IAAI,UAAU,KAAK,KAAK;AACxB,SAAO,WAAW,YAAY,KAAK,MAAM;GAEvC,MAAM,OAAO;AACb,SAAM,CAAC,KAAK,KAAK,KAAK,KAAK;AAC3B,aAAU,QAAQ;;;;;;;;;CAUtB,AAAO,OAAO,KAAmB;EAC/B,MAAM,OAAO,KAAK,MAAM,IAAI,IAAI;AAChC,MAAI,CAAC,KAAM;AAEX,OAAK,WAAW,KAAK;AACrB,OAAK,MAAM,OAAO,IAAI;AACtB,OAAK,aAAa,KAAK;;;;;CAMzB,IAAW,OAAe;AACxB,SAAO,KAAK,MAAM;;;;;;CAOpB,IAAW,cAAsB;AAC/B,SAAO,KAAK"}
|
|
1
|
+
{"version":3,"file":"lru-cache.mjs","names":[],"sources":["../src/lru-cache.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\nclass LRUNode<T> {\n public readonly key: string;\n\n public data: T;\n\n public size: number;\n\n public prev: LRUNode<T> | SentinelNode<T> | null = null;\n\n public next: LRUNode<T> | SentinelNode<T> | null = null;\n\n constructor(key: string, data: T, size: number) {\n this.key = key;\n this.data = data;\n this.size = size;\n }\n}\n\n/**\n * Sentinel node used for head/tail boundaries.\n * These nodes don't contain actual cache data but simplify list operations.\n */\nclass SentinelNode<T> {\n public prev: LRUNode<T> | SentinelNode<T> | null = null;\n\n public next: LRUNode<T> | SentinelNode<T> | null = null;\n}\n\n/**\n * LRU (Least Recently Used) Cache implementation using a doubly-linked list\n * and hash map for O(1) operations.\n *\n * Algorithm:\n * - Uses a doubly-linked list to maintain access order (most recent at head)\n * - Hash map provides O(1) key-to-node lookup\n * - Sentinel head/tail nodes simplify edge case handling\n * - Size-based eviction supports custom size calculation functions\n *\n * Data Structure Layout:\n * HEAD \\<-\\> [most recent] \\<-\\> ... \\<-\\> [least recent] \\<-\\> TAIL\n *\n * Operations:\n * - get(): Move accessed node to head (mark as most recent)\n * - set(): Add new node at head, evict from tail if over capacity\n * - Eviction: Remove least recent node (tail.prev) when size exceeds limit\n */\nexport class LRUCache<T> {\n private readonly cache: Map<string, LRUNode<T>> = new Map();\n\n private readonly head: SentinelNode<T>;\n\n private readonly tail: SentinelNode<T>;\n\n private totalSize: number = 0;\n\n private readonly maxSize: number;\n\n private readonly calculateSize: ((value: T) => number) | undefined;\n\n constructor(maxSize: number, calculateSize?: (value: T) => number) {\n this.maxSize = maxSize;\n this.calculateSize = calculateSize;\n\n // Create sentinel nodes to simplify doubly-linked list operations\n // HEAD <-> TAIL (empty list)\n this.head = new SentinelNode<T>();\n this.tail = new SentinelNode<T>();\n this.head.next = this.tail;\n this.tail.prev = this.head;\n }\n\n /**\n * Adds a node immediately after the head (marks as most recently used). Used when inserting new items or when an item is accessed. **PRECONDITION:** node must be disconnected (prev/next should be null)\n *\n * @param node - The node to add after the head.\n */\n private addToHead(node: LRUNode<T>): void {\n node.prev = this.head;\n node.next = this.head.next;\n // head.next is always non-null (points to tail or another node)\n this.head.next!.prev = node;\n this.head.next = node;\n }\n\n /**\n * Removes a node from its current position in the doubly-linked list. Updates the prev/next pointers of adjacent nodes to maintain list integrity. **PRECONDITION:** node must be connected (prev/next are non-null)\n *\n * @param node - The node to remove from the list.\n */\n private removeNode(node: LRUNode<T>): void {\n // Connected nodes always have non-null prev/next\n node.prev!.next = node.next;\n node.next!.prev = node.prev;\n }\n\n /**\n * Moves an existing node to the head position (marks as most recently used). This is the core LRU operation - accessed items become most recent.\n *\n * @param node - The node to move to the head.\n */\n private moveToHead(node: LRUNode<T>): void {\n this.removeNode(node);\n this.addToHead(node);\n }\n\n /**\n * Removes and returns the least recently used node (the one before tail). This is called during eviction when the cache exceeds capacity. **PRECONDITION:** cache is not empty (ensured by caller)\n *\n * @returns The removed least recently used node.\n */\n private removeTail(): LRUNode<T> {\n const lastNode = this.tail.prev as LRUNode<T>;\n // tail.prev is always non-null and always LRUNode when cache is not empty\n this.removeNode(lastNode);\n return lastNode;\n }\n\n /**\n * Sets a key-value pair in the cache.\n * If the key exists, updates the value and moves to head.\n * If new, adds at head and evicts from tail if necessary.\n *\n * Time Complexity:\n * - O(1) for uniform item sizes\n * - O(k) where k is the number of items evicted (can be O(N) for variable sizes)\n *\n * @param key - The key to set.\n * @param value - The value to set.\n */\n public set(key: string, value: T): void {\n const size = this.calculateSize?.(value) ?? 1;\n if (size > this.maxSize) {\n // console.warn(\"Single item size exceeds maxSize\");\n return;\n }\n\n const existing = this.cache.get(key);\n if (existing) {\n // Update existing node: adjust size and move to head (most recent)\n existing.data = value;\n this.totalSize = this.totalSize - existing.size + size;\n existing.size = size;\n this.moveToHead(existing);\n } else {\n // Add new node at head (most recent position)\n const newNode = new LRUNode(key, value, size);\n this.cache.set(key, newNode);\n this.addToHead(newNode);\n this.totalSize += size;\n }\n\n // Evict least recently used items until under capacity\n while (this.totalSize > this.maxSize && this.cache.size > 0) {\n const tail = this.removeTail();\n this.cache.delete(tail.key);\n this.totalSize -= tail.size;\n }\n }\n\n /**\n * Checks if a key exists in the cache.\n * This is a pure query operation - does NOT update LRU order.\n *\n * Time Complexity: O(1)\n */\n public has(key: string): boolean {\n return this.cache.has(key);\n }\n\n /**\n * Retrieves a value by key and marks it as most recently used.\n * Moving to head maintains the LRU property for future evictions.\n *\n * Time Complexity: O(1)\n */\n public get(key: string): T | undefined {\n const node = this.cache.get(key);\n if (!node) return undefined;\n\n // Mark as most recently used by moving to head\n this.moveToHead(node);\n\n return node.data;\n }\n\n /**\n * Returns an iterator over the cache entries. The order is outputted in the\n * order of most recently used to least recently used.\n */\n public *[Symbol.iterator](): IterableIterator<[string, T]> {\n let current = this.head.next;\n while (current && current !== this.tail) {\n // Between head and tail, current is always LRUNode\n const node = current as LRUNode<T>;\n yield [node.key, node.data];\n current = current.next;\n }\n }\n\n /**\n * Removes a specific key from the cache.\n * Updates both the hash map and doubly-linked list.\n *\n * Time Complexity: O(1)\n */\n public remove(key: string): void {\n const node = this.cache.get(key);\n if (!node) return;\n\n this.removeNode(node);\n this.cache.delete(key);\n this.totalSize -= node.size;\n }\n\n /**\n * Returns the number of items in the cache.\n */\n public get size(): number {\n return this.cache.size;\n }\n\n /**\n * Returns the current total size of all cached items.\n * This uses the custom size calculation if provided.\n */\n public get currentSize(): number {\n return this.totalSize;\n }\n}\n"],"mappings":";AAkBA,IAAM,UAAN,MAAiB;CACf,AAAgB;CAEhB,AAAO;CAEP,AAAO;CAEP,AAAO,OAA4C;CAEnD,AAAO,OAA4C;CAEnD,YAAY,KAAa,MAAS,MAAc;AAC9C,OAAK,MAAM;AACX,OAAK,OAAO;AACZ,OAAK,OAAO;;;;;;;AAQhB,IAAM,eAAN,MAAsB;CACpB,AAAO,OAA4C;CAEnD,AAAO,OAA4C;;;;;;;;;;;;;;;;;;;;AAqBrD,IAAa,WAAb,MAAyB;CACvB,AAAiB,wBAAiC,IAAI,KAAK;CAE3D,AAAiB;CAEjB,AAAiB;CAEjB,AAAQ,YAAoB;CAE5B,AAAiB;CAEjB,AAAiB;CAEjB,YAAY,SAAiB,eAAsC;AACjE,OAAK,UAAU;AACf,OAAK,gBAAgB;AAIrB,OAAK,OAAO,IAAI,cAAiB;AACjC,OAAK,OAAO,IAAI,cAAiB;AACjC,OAAK,KAAK,OAAO,KAAK;AACtB,OAAK,KAAK,OAAO,KAAK;;;;;;;CAQxB,AAAQ,UAAU,MAAwB;AACxC,OAAK,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K,KAAK;AACxB,SAAO,WAAW,YAAY,KAAK,MAAM;GAEvC,MAAM,OAAO;AACb,SAAM,CAAC,KAAK,KAAK,KAAK,KAAK;AAC3B,aAAU,QAAQ;;;;;;;;;CAUtB,AAAO,OAAO,KAAmB;EAC/B,MAAM,OAAO,KAAK,MAAM,IAAI,IAAI;AAChC,MAAI,CAAC,KAAM;AAEX,OAAK,WAAW,KAAK;AACrB,OAAK,MAAM,OAAO,IAAI;AACtB,OAAK,aAAa,KAAK;;;;;CAMzB,IAAW,OAAe;AACxB,SAAO,KAAK,MAAM;;;;;;CAOpB,IAAW,cAAsB;AAC/B,SAAO,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match-sorter.mjs","names":[],"sources":["../src/match-sorter.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 { removeAccents } from \"./remove-accents\";\n\n/**\n * Forked from match-sorter by Kent C. Dodds\n */\n\ninterface KeyAttributes {\n threshold?: Ranking;\n maxRanking: Ranking;\n minRanking: Ranking;\n}\ninterface RankingInfo {\n rankedValue: string;\n rank: Ranking;\n keyIndex: number;\n keyThreshold: Ranking | undefined;\n}\n\ninterface ValueGetterKey<ItemType> {\n (item: ItemType): string | Array<string>;\n}\ninterface IndexedItem<ItemType> {\n item: ItemType;\n index: number;\n}\ninterface RankedItem<ItemType> extends RankingInfo, IndexedItem<ItemType> {}\n\ninterface BaseSorter<ItemType> {\n (a: RankedItem<ItemType>, b: RankedItem<ItemType>): number;\n}\n\ninterface Sorter<ItemType> {\n (matchItems: Array<RankedItem<ItemType>>): Array<RankedItem<ItemType>>;\n}\n\ninterface KeyAttributesOptions<ItemType> {\n key?: string | ValueGetterKey<ItemType>;\n threshold?: Ranking;\n maxRanking?: Ranking;\n minRanking?: Ranking;\n}\n\ntype KeyOption<ItemType> =\n | KeyAttributesOptions<ItemType>\n | ValueGetterKey<ItemType>\n | string;\n\ninterface MatchSorterOptions<ItemType = unknown> {\n keys?: ReadonlyArray<KeyOption<ItemType>>;\n threshold?: Ranking;\n baseSort?: BaseSorter<ItemType>;\n keepDiacritics?: boolean;\n sorter?: Sorter<ItemType>;\n}\ntype IndexableByString = Record<string, unknown>;\n\nconst rankings = {\n CASE_SENSITIVE_EQUAL: 7,\n EQUAL: 6,\n STARTS_WITH: 5,\n WORD_STARTS_WITH: 4,\n CONTAINS: 3,\n ACRONYM: 2,\n MATCHES: 1,\n NO_MATCH: 0\n} as const;\n\ntype Ranking = (typeof rankings)[keyof typeof rankings];\n\nconst defaultBaseSortFn: BaseSorter<unknown> = (a, b) =>\n String(a.rankedValue).localeCompare(String(b.rankedValue));\n\n/**\n * Takes an array of items and a value and returns a new array with the items that match the given value\n * @param items - the items to sort\n * @param value - the value to use for ranking\n * @param options - Some options to configure the sorter\n * @returns - the new sorted array\n */\nfunction matchSorter<ItemType = string>(\n items: ReadonlyArray<ItemType>,\n value: string,\n options: MatchSorterOptions<ItemType> = {}\n): Array<ItemType> {\n const {\n keys,\n threshold = rankings.MATCHES,\n baseSort = defaultBaseSortFn,\n sorter = matchedItems =>\n matchedItems.sort((a, b) => sortRankedValues(a, b, baseSort))\n } = options;\n const matchedItems = items.reduce(\n (ret: Array<RankedItem<ItemType>>, item: ItemType, index: number) =>\n reduceItemsToRanked(ret, item, index),\n []\n );\n\n return sorter(matchedItems).map(({ item }) => item);\n\n function reduceItemsToRanked(\n matches: Array<RankedItem<ItemType>>,\n item: ItemType,\n index: number\n ): Array<RankedItem<ItemType>> {\n const rankingInfo = getHighestRanking(item, keys, value, options);\n const { rank, keyThreshold = threshold } = rankingInfo;\n if (rank >= keyThreshold) {\n matches.push({\n ...rankingInfo,\n item,\n index\n });\n }\n return matches;\n }\n}\n\nmatchSorter.rankings = rankings;\n\n/**\n * Gets the highest ranking for value for the given item based on its values for the given keys\n * @param item - the item to rank\n * @param keys - the keys to get values from the item for the ranking\n * @param value - the value to rank against\n * @param options - options to control the ranking\n * @returns The highest ranking\n */\nfunction getHighestRanking<ItemType>(\n item: ItemType,\n keys: ReadonlyArray<KeyOption<ItemType>> | undefined,\n value: string,\n options: MatchSorterOptions<ItemType>\n): RankingInfo {\n if (!keys) {\n // if keys is not specified, then we assume the item given is ready to be matched\n const stringItem = item as unknown as string;\n\n return {\n // ends up being duplicate of 'item' in matches but consistent\n rankedValue: stringItem,\n rank: getMatchRanking(stringItem, value, options),\n keyIndex: -1,\n keyThreshold: options.threshold\n };\n }\n const valuesToRank = getAllValuesToRank(item, keys);\n\n return valuesToRank.reduce(\n (\n { rank, rankedValue, keyIndex, keyThreshold },\n { itemValue, attributes },\n i\n ) => {\n let newRank = getMatchRanking(itemValue, value, options);\n let newRankedValue = rankedValue;\n const { minRanking, maxRanking, threshold } = attributes;\n if (newRank < minRanking && newRank >= rankings.MATCHES) {\n newRank = minRanking;\n } else if (newRank > maxRanking) {\n newRank = maxRanking;\n }\n if (newRank > rank) {\n rank = newRank as 0;\n keyIndex = i;\n keyThreshold = threshold;\n newRankedValue = itemValue;\n }\n return {\n rankedValue: newRankedValue,\n rank,\n keyIndex,\n keyThreshold\n };\n },\n {\n rankedValue: item as unknown as string,\n rank: rankings.NO_MATCH,\n keyIndex: -1,\n keyThreshold: options.threshold\n }\n );\n}\n\n/**\n * Gives a rankings score based on how well the two strings match.\n * @param testString - the string to test against\n * @param stringToRank - the string to rank\n * @param options - options for the match (like keepDiacritics for comparison)\n * @returns the ranking for how well stringToRank matches testString\n */\nfunction getMatchRanking<ItemType>(\n testString: string,\n stringToRank: string,\n options: MatchSorterOptions<ItemType>\n): Ranking {\n testString = prepareValueForComparison(testString, options);\n stringToRank = prepareValueForComparison(stringToRank, options);\n\n // too long\n if (stringToRank.length > testString.length) {\n return rankings.NO_MATCH;\n }\n\n // case sensitive equals\n if (testString === stringToRank) {\n return rankings.CASE_SENSITIVE_EQUAL;\n }\n\n // Lower casing before further comparison\n testString = testString.toLowerCase();\n stringToRank = stringToRank.toLowerCase();\n\n // case insensitive equals\n if (testString === stringToRank) {\n return rankings.EQUAL;\n }\n\n // starts with\n if (testString.startsWith(stringToRank)) {\n return rankings.STARTS_WITH;\n }\n\n // word starts with\n if (testString.includes(` ${stringToRank}`)) {\n return rankings.WORD_STARTS_WITH;\n }\n\n // contains\n if (testString.includes(stringToRank)) {\n return rankings.CONTAINS;\n } else if (stringToRank.length === 1) {\n // If the only character in the given stringToRank\n // isn't even contained in the testString, then\n // it's definitely not a match.\n return rankings.NO_MATCH;\n }\n\n // acronym\n if (getAcronym(testString).includes(stringToRank)) {\n return rankings.ACRONYM;\n }\n\n // will return a number between rankings.MATCHES and\n // rankings.MATCHES + 1 depending on how close of a match it is.\n return getClosenessRanking(testString, stringToRank);\n}\n\n/**\n * Generates an acronym for a string.\n *\n * @param value - the string for which to produce the acronym\n * @returns the acronym\n */\nfunction getAcronym(value: string): string {\n let acronym = \"\";\n const wordsInString = value.split(\" \");\n for (const wordInString of wordsInString) {\n const splitByHyphenWords = wordInString.split(\"-\");\n for (const splitByHyphenWord of splitByHyphenWords) {\n acronym += splitByHyphenWord.slice(0, 1);\n }\n }\n return acronym;\n}\n\n/**\n * Returns a score based on how spread apart the\n * characters from the stringToRank are within the testString.\n * A number close to rankings.MATCHES represents a loose match. A number close\n * to rankings.MATCHES + 1 represents a tighter match.\n * @param testString - the string to test against\n * @param stringToRank - the string to rank\n * @returns the number between rankings.MATCHES and\n * rankings.MATCHES + 1 for how well stringToRank matches testString\n */\nfunction getClosenessRanking(\n testString: string,\n stringToRank: string\n): Ranking {\n let matchingInOrderCharCount = 0;\n let charNumber = 0;\n function findMatchingCharacter(\n matchChar: string,\n string: string,\n index: number\n ) {\n for (let j = index, J = string.length; j < J; j++) {\n const stringChar = string[j];\n if (stringChar === matchChar) {\n matchingInOrderCharCount += 1;\n return j + 1;\n }\n }\n return -1;\n }\n function getRanking(spread: number) {\n const spreadPercentage = 1 / spread;\n const inOrderPercentage = matchingInOrderCharCount / stringToRank.length;\n const ranking = rankings.MATCHES + inOrderPercentage * spreadPercentage;\n\n return ranking as Ranking;\n }\n const firstIndex = findMatchingCharacter(stringToRank[0]!, testString, 0);\n if (firstIndex < 0) {\n return rankings.NO_MATCH;\n }\n charNumber = firstIndex;\n for (let i = 1, I = stringToRank.length; i < I; i++) {\n const matchChar = stringToRank[i];\n charNumber = findMatchingCharacter(matchChar!, testString, charNumber);\n const found = charNumber > -1;\n if (!found) {\n return rankings.NO_MATCH;\n }\n }\n\n const spread = charNumber - firstIndex;\n\n return getRanking(spread);\n}\n\n/**\n * Sorts items that have a rank, index, and keyIndex\n * @param a - the first item to sort\n * @param b - the second item to sort\n * @returns -1 if a should come first, 1 if b should come first, 0 if equal\n */\nfunction sortRankedValues<ItemType>(\n a: RankedItem<ItemType>,\n b: RankedItem<ItemType>,\n baseSort: BaseSorter<ItemType>\n): number {\n const aFirst = -1;\n const bFirst = 1;\n const { rank: aRank, keyIndex: aKeyIndex } = a;\n const { rank: bRank, keyIndex: bKeyIndex } = b;\n const same = aRank === bRank;\n if (same) {\n if (aKeyIndex === bKeyIndex) {\n // use the base sort function as a tie-breaker\n return baseSort(a, b);\n }\n return aKeyIndex < bKeyIndex ? aFirst : bFirst;\n }\n return aRank > bRank ? aFirst : bFirst;\n}\n\n/**\n * Prepares value for comparison by stringifying it, removing diacritics (if specified)\n * @param value - the value to clean\n * @param options - options for the match (like keepDiacritics for comparison)\n * @returns the prepared value\n */\nfunction prepareValueForComparison<ItemType>(\n value: string,\n options: MatchSorterOptions<ItemType>\n): string {\n // value might not actually be a string at this point (we don't get to choose)\n // so part of preparing the value for comparison is ensure that it is a string\n value = `${value}`; // toString\n if (!options.keepDiacritics) {\n value = removeAccents(value);\n }\n return value;\n}\n\n/**\n * Gets value for key in item at arbitrarily nested keypath\n * @param item - the item\n * @param key - the potentially nested keypath or property callback\n * @returns - an array containing the value(s) at the nested keypath\n */\nfunction getItemValues<ItemType>(\n item: ItemType,\n key: KeyOption<ItemType>\n): Array<string> {\n if (typeof key === \"object\") {\n key = key.key as string;\n }\n let value: string | Array<string> | null | unknown;\n if (typeof key === \"function\") {\n value = key(item);\n } else if (item === null) {\n value = null;\n } else if (Object.hasOwnProperty.call(item, key)) {\n value = (item as IndexableByString)[key];\n } else if (key.includes(\".\")) {\n return getNestedValues<ItemType>(key, item);\n } else {\n value = null;\n }\n\n // because `value` can also be undefined\n if (value === null) {\n return [];\n }\n if (Array.isArray(value)) {\n return value;\n }\n return [String(value)];\n}\n\n/**\n * Given path: \"foo.bar.baz\"\n * And item: \\{foo: \\{bar: \\{baz: 'buzz'\\}\\}\\}\n * -\\> 'buzz'\n *\n * @param path - a dot-separated set of keys\n * @param item - the item to get the value from\n */\nfunction getNestedValues<ItemType>(\n path: string,\n item: ItemType\n): Array<string> {\n const keys = path.split(\".\");\n\n type ValueA = Array<ItemType | IndexableByString | string>;\n let values: ValueA = [item];\n\n for (let i = 0, I = keys.length; i < I; i++) {\n const nestedKey = keys[i];\n let nestedValues: ValueA = [];\n\n for (let j = 0, J = values.length; j < J; j++) {\n const nestedItem = values[j];\n\n if (nestedItem === null) {\n continue;\n }\n\n if (nestedKey && Object.hasOwnProperty.call(nestedItem, nestedKey)) {\n const nestedValue = (nestedItem as IndexableByString)[nestedKey];\n if (nestedValue !== null) {\n nestedValues.push(nestedValue as IndexableByString | string);\n }\n } else if (nestedItem && nestedKey === \"*\") {\n // ensure that values is an array\n nestedValues = [...nestedValues, nestedItem];\n }\n }\n\n values = nestedValues;\n }\n\n if (Array.isArray(values[0])) {\n // keep allowing the implicit wildcard for an array of strings at the end of\n // the path; don't use `.flat()` because that's not available in node.js v10\n const result: Array<string> = [];\n\n return result.concat(...(values as Array<string>));\n }\n // Based on our logic it should be an array of strings by now...\n // assuming the user's path terminated in strings\n return values as Array<string>;\n}\n\n/**\n * Gets all the values for the given keys in the given item and returns an array of those values\n * @param item - the item from which the values will be retrieved\n * @param keys - the keys to use to retrieve the values\n * @returns objects with \\{itemValue, attributes\\}\n */\nfunction getAllValuesToRank<ItemType>(\n item: ItemType,\n keys: ReadonlyArray<KeyOption<ItemType>>\n) {\n const allValues: Array<{ itemValue: string; attributes: KeyAttributes }> = [];\n for (let j = 0, J = keys.length; j < J; j++) {\n const key = keys[j];\n const attributes = getKeyAttributes(key!);\n const itemValues = getItemValues(item, key!);\n for (let i = 0, I = itemValues.length; i < I; i++) {\n allValues.push({\n itemValue: itemValues[i]!,\n attributes\n });\n }\n }\n return allValues;\n}\n\nconst defaultKeyAttributes = {\n maxRanking: Infinity as Ranking,\n minRanking: -Infinity as Ranking\n};\n/**\n * Gets all the attributes for the given key\n * @param key - the key from which the attributes will be retrieved\n * @returns object containing the key's attributes\n */\nfunction getKeyAttributes<ItemType>(key: KeyOption<ItemType>): KeyAttributes {\n if (typeof key === \"string\") {\n return defaultKeyAttributes;\n }\n return {\n ...defaultKeyAttributes,\n ...key\n };\n}\n\nexport { defaultBaseSortFn, matchSorter, rankings };\n\nexport type {\n KeyAttributes,\n KeyAttributesOptions,\n KeyOption,\n MatchSorterOptions,\n RankingInfo,\n ValueGetterKey\n};\n"],"mappings":";;;AA0EA,MAAM,WAAW;CACf,sBAAsB;CACtB,OAAO;CACP,aAAa;CACb,kBAAkB;CAClB,UAAU;CACV,SAAS;CACT,SAAS;CACT,UAAU;CACX;AAID,MAAM,qBAA0C,GAAG,MACjD,OAAO,EAAE,YAAY,CAAC,cAAc,OAAO,EAAE,YAAY,CAAC;;;;;;;;AAS5D,SAAS,YACP,OACA,OACA,UAAwC,EAAE,EACzB;CACjB,MAAM,EACJ,MACA,YAAY,SAAS,SACrB,WAAW,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I,GAAG,KAAK;GAC7C,MAAM,aAAa,OAAO;AAE1B,OAAI,eAAe,KACjB;AAGF,OAAI,aAAa,OAAO,eAAe,KAAK,YAAY,UAAU,EAAE;IAClE,MAAM,cAAe,WAAiC;AACtD,QAAI,gBAAgB,KAClB,cAAa,KAAK,YAA0C;cAErD,cAAc,cAAc,IAErC,gBAAe,CAAC,GAAG,cAAc,WAAW;;AAIhD,WAAS;;AAGX,KAAI,MAAM,QAAQ,OAAO,GAAG,CAK1B,QAAO,EAAM,CAAC,OAAO,GAAI,OAAyB;AAIpD,QAAO;;;;;;;;AAST,SAAS,mBACP,MACA,MACA;CACA,MAAM,YAAqE,EAAE;AAC7E,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,IAAI,GAAG,KAAK;EAC3C,MAAM,MAAM,KAAK;EACjB,MAAM,aAAa,iBAAiB,IAAK;EACzC,MAAM,aAAa,cAAc,MAAM,IAAK;AAC5C,OAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,IAAI,GAAG,IAC5C,WAAU,KAAK;GACb,WAAW,WAAW;GACtB;GACD,CAAC;;AAGN,QAAO;;AAGT,MAAM,uBAAuB;CAC3B,YAAY;CACZ,YAAY;CACb;;;;;;AAMD,SAAS,iBAA2B,KAAyC;AAC3E,KAAI,OAAO,QAAQ,SACjB,QAAO;AAET,QAAO;EACL,GAAG;EACH,GAAG;EACJ"}
|
|
1
|
+
{"version":3,"file":"match-sorter.mjs","names":[],"sources":["../src/match-sorter.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 { removeAccents } from \"./remove-accents\";\n\n/**\n * Forked from match-sorter by Kent C. Dodds\n */\n\ninterface KeyAttributes {\n threshold?: Ranking;\n maxRanking: Ranking;\n minRanking: Ranking;\n}\ninterface RankingInfo {\n rankedValue: string;\n rank: Ranking;\n keyIndex: number;\n keyThreshold: Ranking | undefined;\n}\n\ninterface ValueGetterKey<ItemType> {\n (item: ItemType): string | Array<string>;\n}\ninterface IndexedItem<ItemType> {\n item: ItemType;\n index: number;\n}\ninterface RankedItem<ItemType> extends RankingInfo, IndexedItem<ItemType> {}\n\ninterface BaseSorter<ItemType> {\n (a: RankedItem<ItemType>, b: RankedItem<ItemType>): number;\n}\n\ninterface Sorter<ItemType> {\n (matchItems: Array<RankedItem<ItemType>>): Array<RankedItem<ItemType>>;\n}\n\ninterface KeyAttributesOptions<ItemType> {\n key?: string | ValueGetterKey<ItemType>;\n threshold?: Ranking;\n maxRanking?: Ranking;\n minRanking?: Ranking;\n}\n\ntype KeyOption<ItemType> =\n | KeyAttributesOptions<ItemType>\n | ValueGetterKey<ItemType>\n | string;\n\ninterface MatchSorterOptions<ItemType = unknown> {\n keys?: ReadonlyArray<KeyOption<ItemType>>;\n threshold?: Ranking;\n baseSort?: BaseSorter<ItemType>;\n keepDiacritics?: boolean;\n sorter?: Sorter<ItemType>;\n}\ntype IndexableByString = Record<string, unknown>;\n\nconst rankings = {\n CASE_SENSITIVE_EQUAL: 7,\n EQUAL: 6,\n STARTS_WITH: 5,\n WORD_STARTS_WITH: 4,\n CONTAINS: 3,\n ACRONYM: 2,\n MATCHES: 1,\n NO_MATCH: 0\n} as const;\n\ntype Ranking = (typeof rankings)[keyof typeof rankings];\n\nconst defaultBaseSortFn: BaseSorter<unknown> = (a, b) =>\n String(a.rankedValue).localeCompare(String(b.rankedValue));\n\n/**\n * Takes an array of items and a value and returns a new array with the items that match the given value\n * @param items - the items to sort\n * @param value - the value to use for ranking\n * @param options - Some options to configure the sorter\n * @returns - the new sorted array\n */\nfunction matchSorter<ItemType = string>(\n items: ReadonlyArray<ItemType>,\n value: string,\n options: MatchSorterOptions<ItemType> = {}\n): Array<ItemType> {\n const {\n keys,\n threshold = rankings.MATCHES,\n baseSort = defaultBaseSortFn,\n sorter = matchedItems =>\n matchedItems.sort((a, b) => sortRankedValues(a, b, baseSort))\n } = options;\n const matchedItems = items.reduce(\n (ret: Array<RankedItem<ItemType>>, item: ItemType, index: number) =>\n reduceItemsToRanked(ret, item, index),\n []\n );\n\n return sorter(matchedItems).map(({ item }) => item);\n\n function reduceItemsToRanked(\n matches: Array<RankedItem<ItemType>>,\n item: ItemType,\n index: number\n ): Array<RankedItem<ItemType>> {\n const rankingInfo = getHighestRanking(item, keys, value, options);\n const { rank, keyThreshold = threshold } = rankingInfo;\n if (rank >= keyThreshold) {\n matches.push({\n ...rankingInfo,\n item,\n index\n });\n }\n return matches;\n }\n}\n\nmatchSorter.rankings = rankings;\n\n/**\n * Gets the highest ranking for value for the given item based on its values for the given keys\n * @param item - the item to rank\n * @param keys - the keys to get values from the item for the ranking\n * @param value - the value to rank against\n * @param options - options to control the ranking\n * @returns The highest ranking\n */\nfunction getHighestRanking<ItemType>(\n item: ItemType,\n keys: ReadonlyArray<KeyOption<ItemType>> | undefined,\n value: string,\n options: MatchSorterOptions<ItemType>\n): RankingInfo {\n if (!keys) {\n // if keys is not specified, then we assume the item given is ready to be matched\n const stringItem = item as unknown as string;\n\n return {\n // ends up being duplicate of 'item' in matches but consistent\n rankedValue: stringItem,\n rank: getMatchRanking(stringItem, value, options),\n keyIndex: -1,\n keyThreshold: options.threshold\n };\n }\n const valuesToRank = getAllValuesToRank(item, keys);\n\n return valuesToRank.reduce(\n (\n { rank, rankedValue, keyIndex, keyThreshold },\n { itemValue, attributes },\n i\n ) => {\n let newRank = getMatchRanking(itemValue, value, options);\n let newRankedValue = rankedValue;\n const { minRanking, maxRanking, threshold } = attributes;\n if (newRank < minRanking && newRank >= rankings.MATCHES) {\n newRank = minRanking;\n } else if (newRank > maxRanking) {\n newRank = maxRanking;\n }\n if (newRank > rank) {\n rank = newRank as 0;\n keyIndex = i;\n keyThreshold = threshold;\n newRankedValue = itemValue;\n }\n return {\n rankedValue: newRankedValue,\n rank,\n keyIndex,\n keyThreshold\n };\n },\n {\n rankedValue: item as unknown as string,\n rank: rankings.NO_MATCH,\n keyIndex: -1,\n keyThreshold: options.threshold\n }\n );\n}\n\n/**\n * Gives a rankings score based on how well the two strings match.\n * @param testString - the string to test against\n * @param stringToRank - the string to rank\n * @param options - options for the match (like keepDiacritics for comparison)\n * @returns the ranking for how well stringToRank matches testString\n */\nfunction getMatchRanking<ItemType>(\n testString: string,\n stringToRank: string,\n options: MatchSorterOptions<ItemType>\n): Ranking {\n testString = prepareValueForComparison(testString, options);\n stringToRank = prepareValueForComparison(stringToRank, options);\n\n // too long\n if (stringToRank.length > testString.length) {\n return rankings.NO_MATCH;\n }\n\n // case sensitive equals\n if (testString === stringToRank) {\n return rankings.CASE_SENSITIVE_EQUAL;\n }\n\n // Lower casing before further comparison\n testString = testString.toLowerCase();\n stringToRank = stringToRank.toLowerCase();\n\n // case insensitive equals\n if (testString === stringToRank) {\n return rankings.EQUAL;\n }\n\n // starts with\n if (testString.startsWith(stringToRank)) {\n return rankings.STARTS_WITH;\n }\n\n // word starts with\n if (testString.includes(` ${stringToRank}`)) {\n return rankings.WORD_STARTS_WITH;\n }\n\n // contains\n if (testString.includes(stringToRank)) {\n return rankings.CONTAINS;\n } else if (stringToRank.length === 1) {\n // If the only character in the given stringToRank\n // isn't even contained in the testString, then\n // it's definitely not a match.\n return rankings.NO_MATCH;\n }\n\n // acronym\n if (getAcronym(testString).includes(stringToRank)) {\n return rankings.ACRONYM;\n }\n\n // will return a number between rankings.MATCHES and\n // rankings.MATCHES + 1 depending on how close of a match it is.\n return getClosenessRanking(testString, stringToRank);\n}\n\n/**\n * Generates an acronym for a string.\n *\n * @param value - the string for which to produce the acronym\n * @returns the acronym\n */\nfunction getAcronym(value: string): string {\n let acronym = \"\";\n const wordsInString = value.split(\" \");\n for (const wordInString of wordsInString) {\n const splitByHyphenWords = wordInString.split(\"-\");\n for (const splitByHyphenWord of splitByHyphenWords) {\n acronym += splitByHyphenWord.slice(0, 1);\n }\n }\n return acronym;\n}\n\n/**\n * Returns a score based on how spread apart the\n * characters from the stringToRank are within the testString.\n * A number close to rankings.MATCHES represents a loose match. A number close\n * to rankings.MATCHES + 1 represents a tighter match.\n * @param testString - the string to test against\n * @param stringToRank - the string to rank\n * @returns the number between rankings.MATCHES and\n * rankings.MATCHES + 1 for how well stringToRank matches testString\n */\nfunction getClosenessRanking(\n testString: string,\n stringToRank: string\n): Ranking {\n let matchingInOrderCharCount = 0;\n let charNumber = 0;\n function findMatchingCharacter(\n matchChar: string,\n string: string,\n index: number\n ) {\n for (let j = index, J = string.length; j < J; j++) {\n const stringChar = string[j];\n if (stringChar === matchChar) {\n matchingInOrderCharCount += 1;\n return j + 1;\n }\n }\n return -1;\n }\n function getRanking(spread: number) {\n const spreadPercentage = 1 / spread;\n const inOrderPercentage = matchingInOrderCharCount / stringToRank.length;\n const ranking = rankings.MATCHES + inOrderPercentage * spreadPercentage;\n\n return ranking as Ranking;\n }\n const firstIndex = findMatchingCharacter(stringToRank[0]!, testString, 0);\n if (firstIndex < 0) {\n return rankings.NO_MATCH;\n }\n charNumber = firstIndex;\n for (let i = 1, I = stringToRank.length; i < I; i++) {\n const matchChar = stringToRank[i];\n charNumber = findMatchingCharacter(matchChar!, testString, charNumber);\n const found = charNumber > -1;\n if (!found) {\n return rankings.NO_MATCH;\n }\n }\n\n const spread = charNumber - firstIndex;\n\n return getRanking(spread);\n}\n\n/**\n * Sorts items that have a rank, index, and keyIndex\n * @param a - the first item to sort\n * @param b - the second item to sort\n * @returns -1 if a should come first, 1 if b should come first, 0 if equal\n */\nfunction sortRankedValues<ItemType>(\n a: RankedItem<ItemType>,\n b: RankedItem<ItemType>,\n baseSort: BaseSorter<ItemType>\n): number {\n const aFirst = -1;\n const bFirst = 1;\n const { rank: aRank, keyIndex: aKeyIndex } = a;\n const { rank: bRank, keyIndex: bKeyIndex } = b;\n const same = aRank === bRank;\n if (same) {\n if (aKeyIndex === bKeyIndex) {\n // use the base sort function as a tie-breaker\n return baseSort(a, b);\n }\n return aKeyIndex < bKeyIndex ? aFirst : bFirst;\n }\n return aRank > bRank ? aFirst : bFirst;\n}\n\n/**\n * Prepares value for comparison by stringifying it, removing diacritics (if specified)\n * @param value - the value to clean\n * @param options - options for the match (like keepDiacritics for comparison)\n * @returns the prepared value\n */\nfunction prepareValueForComparison<ItemType>(\n value: string,\n options: MatchSorterOptions<ItemType>\n): string {\n // value might not actually be a string at this point (we don't get to choose)\n // so part of preparing the value for comparison is ensure that it is a string\n value = `${value}`; // toString\n if (!options.keepDiacritics) {\n value = removeAccents(value);\n }\n return value;\n}\n\n/**\n * Gets value for key in item at arbitrarily nested keypath\n * @param item - the item\n * @param key - the potentially nested keypath or property callback\n * @returns - an array containing the value(s) at the nested keypath\n */\nfunction getItemValues<ItemType>(\n item: ItemType,\n key: KeyOption<ItemType>\n): Array<string> {\n if (typeof key === \"object\") {\n key = key.key as string;\n }\n let value: string | Array<string> | null | unknown;\n if (typeof key === \"function\") {\n value = key(item);\n } else if (item === null) {\n value = null;\n } else if (Object.hasOwnProperty.call(item, key)) {\n value = (item as IndexableByString)[key];\n } else if (key.includes(\".\")) {\n return getNestedValues<ItemType>(key, item);\n } else {\n value = null;\n }\n\n // because `value` can also be undefined\n if (value === null) {\n return [];\n }\n if (Array.isArray(value)) {\n return value;\n }\n return [String(value)];\n}\n\n/**\n * Given path: \"foo.bar.baz\"\n * And item: \\{foo: \\{bar: \\{baz: 'buzz'\\}\\}\\}\n * -\\> 'buzz'\n *\n * @param path - a dot-separated set of keys\n * @param item - the item to get the value from\n */\nfunction getNestedValues<ItemType>(\n path: string,\n item: ItemType\n): Array<string> {\n const keys = path.split(\".\");\n\n type ValueA = Array<ItemType | IndexableByString | string>;\n let values: ValueA = [item];\n\n for (let i = 0, I = keys.length; i < I; i++) {\n const nestedKey = keys[i];\n let nestedValues: ValueA = [];\n\n for (let j = 0, J = values.length; j < J; j++) {\n const nestedItem = values[j];\n\n if (nestedItem === null) {\n continue;\n }\n\n if (nestedKey && Object.hasOwnProperty.call(nestedItem, nestedKey)) {\n const nestedValue = (nestedItem as IndexableByString)[nestedKey];\n if (nestedValue !== null) {\n nestedValues.push(nestedValue as IndexableByString | string);\n }\n } else if (nestedItem && nestedKey === \"*\") {\n // ensure that values is an array\n nestedValues = [...nestedValues, nestedItem];\n }\n }\n\n values = nestedValues;\n }\n\n if (Array.isArray(values[0])) {\n // keep allowing the implicit wildcard for an array of strings at the end of\n // the path; don't use `.flat()` because that's not available in node.js v10\n const result: Array<string> = [];\n\n return result.concat(...(values as Array<string>));\n }\n // Based on our logic it should be an array of strings by now...\n // assuming the user's path terminated in strings\n return values as Array<string>;\n}\n\n/**\n * Gets all the values for the given keys in the given item and returns an array of those values\n * @param item - the item from which the values will be retrieved\n * @param keys - the keys to use to retrieve the values\n * @returns objects with \\{itemValue, attributes\\}\n */\nfunction getAllValuesToRank<ItemType>(\n item: ItemType,\n keys: ReadonlyArray<KeyOption<ItemType>>\n) {\n const allValues: Array<{ itemValue: string; attributes: KeyAttributes }> = [];\n for (let j = 0, J = keys.length; j < J; j++) {\n const key = keys[j];\n const attributes = getKeyAttributes(key!);\n const itemValues = getItemValues(item, key!);\n for (let i = 0, I = itemValues.length; i < I; i++) {\n allValues.push({\n itemValue: itemValues[i]!,\n attributes\n });\n }\n }\n return allValues;\n}\n\nconst defaultKeyAttributes = {\n maxRanking: Infinity as Ranking,\n minRanking: -Infinity as Ranking\n};\n/**\n * Gets all the attributes for the given key\n * @param key - the key from which the attributes will be retrieved\n * @returns object containing the key's attributes\n */\nfunction getKeyAttributes<ItemType>(key: KeyOption<ItemType>): KeyAttributes {\n if (typeof key === \"string\") {\n return defaultKeyAttributes;\n }\n return {\n ...defaultKeyAttributes,\n ...key\n };\n}\n\nexport { defaultBaseSortFn, matchSorter, rankings };\n\nexport type {\n KeyAttributes,\n KeyAttributesOptions,\n KeyOption,\n MatchSorterOptions,\n RankingInfo,\n ValueGetterKey\n};\n"],"mappings":";;;AA0EA,MAAM,WAAW;CACf,sBAAsB;CACtB,OAAO;CACP,aAAa;CACb,kBAAkB;CAClB,UAAU;CACV,SAAS;CACT,SAAS;CACT,UAAU;CACX;AAID,MAAM,qBAA0C,GAAG,MACjD,OAAO,EAAE,YAAY,CAAC,cAAc,OAAO,EAAE,YAAY,CAAC;;;;;;;;AAS5D,SAAS,YACP,OACA,OACA,UAAwC,EAAE,EACzB;CACjB,MAAM,EACJ,MACA,YAAY,SAAS,SACrB,WAAW,mBACX,UAAS,iBACP,aAAa,MAAM,GAAG,MAAM,iBAAiB,GAAG,GAAG,SAAS,CAAC,KAC7D;AAOJ,QAAO,OANc,MAAM,QACxB,KAAkC,MAAgB,UACjD,oBAAoB,KAAK,MAAM,MAAM,EACvC,EAAE,CAGsB,CAAC,CAAC,KAAK,EAAE,WAAW,KAAK;CAEnD,SAAS,oBACP,SACA,MACA,OAC6B;EAC7B,MAAM,cAAc,kBAAkB,MAAM,MAAM,OAAO,QAAQ;EACjE,MAAM,EAAE,MAAM,eAAe,cAAc;AAC3C,MAAI,QAAQ,aACV,SAAQ,KAAK;GACX,GAAG;GACH;GACA;GACD,CAAC;AAEJ,SAAO;;;AAIX,YAAY,WAAW;;;;;;;;;AAUvB,SAAS,kBACP,MACA,MACA,OACA,SACa;AACb,KAAI,CAAC,MAAM;EAET,MAAM,aAAa;AAEnB,SAAO;GAEL,aAAa;GACb,MAAM,gBAAgB,YAAY,OAAO,QAAQ;GACjD,UAAU;GACV,cAAc,QAAQ;GACvB;;AAIH,QAFqB,mBAAmB,MAAM,KAE3B,CAAC,QAEhB,EAAE,MAAM,aAAa,UAAU,gBAC/B,EAAE,WAAW,cACb,MACG;EACH,IAAI,UAAU,gBAAgB,WAAW,OAAO,QAAQ;EACxD,I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AAyC;AAC3E,KAAI,OAAO,QAAQ,SACjB,QAAO;AAET,QAAO;EACL,GAAG;EACH,GAAG;EACJ"}
|
package/dist/memoize.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoize.mjs","names":[],"sources":["../src/memoize.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"memoize.mjs","names":[],"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,MAAM,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/noop.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noop.mjs","names":[],"sources":["../src/noop.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
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 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 * 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":";;;;;;;;AAyBA,MAAa,QAAQ,YAA4B;;;;;;;;;;AAWjD,eAAsB,UAAU,SAAkC"}
|
package/dist/omit.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"omit.mjs","names":[],"sources":["../src/omit.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"omit.mjs","names":[],"sources":["../src/omit.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 * 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;\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/pick.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pick.mjs","names":[],"sources":["../src/pick.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"pick.mjs","names":[],"sources":["../src/pick.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 * 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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-accents.mjs","names":[],"sources":["../src/remove-accents.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 const characterMap: Record<string, string> = {\n À: \"A\",\n Á: \"A\",\n Â: \"A\",\n Ã: \"A\",\n Ä: \"A\",\n Å: \"A\",\n Ấ: \"A\",\n Ắ: \"A\",\n Ẳ: \"A\",\n Ẵ: \"A\",\n Ặ: \"A\",\n Æ: \"AE\",\n Ầ: \"A\",\n Ằ: \"A\",\n Ȃ: \"A\",\n Ç: \"C\",\n Ḉ: \"C\",\n È: \"E\",\n É: \"E\",\n Ê: \"E\",\n Ë: \"E\",\n Ế: \"E\",\n Ḗ: \"E\",\n Ề: \"E\",\n Ḕ: \"E\",\n Ḝ: \"E\",\n Ȇ: \"E\",\n Ì: \"I\",\n Í: \"I\",\n Î: \"I\",\n Ï: \"I\",\n Ḯ: \"I\",\n Ȋ: \"I\",\n Ð: \"D\",\n Ñ: \"N\",\n Ò: \"O\",\n Ó: \"O\",\n Ô: \"O\",\n Õ: \"O\",\n Ö: \"O\",\n Ø: \"O\",\n Ố: \"O\",\n Ṍ: \"O\",\n Ṓ: \"O\",\n Ȏ: \"O\",\n Ù: \"U\",\n Ú: \"U\",\n Û: \"U\",\n Ü: \"U\",\n Ý: \"Y\",\n à: \"a\",\n á: \"a\",\n â: \"a\",\n ã: \"a\",\n ä: \"a\",\n å: \"a\",\n ấ: \"a\",\n ắ: \"a\",\n ẳ: \"a\",\n ẵ: \"a\",\n ặ: \"a\",\n æ: \"ae\",\n ầ: \"a\",\n ằ: \"a\",\n ȃ: \"a\",\n ç: \"c\",\n ḉ: \"c\",\n è: \"e\",\n é: \"e\",\n ê: \"e\",\n ë: \"e\",\n ế: \"e\",\n ḗ: \"e\",\n ề: \"e\",\n ḕ: \"e\",\n ḝ: \"e\",\n ȇ: \"e\",\n ì: \"i\",\n í: \"i\",\n î: \"i\",\n ï: \"i\",\n ḯ: \"i\",\n ȋ: \"i\",\n ð: \"d\",\n ñ: \"n\",\n ò: \"o\",\n ó: \"o\",\n ô: \"o\",\n õ: \"o\",\n ö: \"o\",\n ø: \"o\",\n ố: \"o\",\n ṍ: \"o\",\n ṓ: \"o\",\n ȏ: \"o\",\n ù: \"u\",\n ú: \"u\",\n û: \"u\",\n ü: \"u\",\n ý: \"y\",\n ÿ: \"y\",\n Ā: \"A\",\n ā: \"a\",\n Ă: \"A\",\n ă: \"a\",\n Ą: \"A\",\n ą: \"a\",\n Ć: \"C\",\n ć: \"c\",\n Ĉ: \"C\",\n ĉ: \"c\",\n Ċ: \"C\",\n ċ: \"c\",\n Č: \"C\",\n č: \"c\",\n C̆: \"C\",\n c̆: \"c\",\n Ď: \"D\",\n ď: \"d\",\n Đ: \"D\",\n đ: \"d\",\n Ē: \"E\",\n ē: \"e\",\n Ĕ: \"E\",\n ĕ: \"e\",\n Ė: \"E\",\n ė: \"e\",\n Ę: \"E\",\n ę: \"e\",\n Ě: \"E\",\n ě: \"e\",\n Ĝ: \"G\",\n Ǵ: \"G\",\n ĝ: \"g\",\n ǵ: \"g\",\n Ğ: \"G\",\n ğ: \"g\",\n Ġ: \"G\",\n ġ: \"g\",\n Ģ: \"G\",\n ģ: \"g\",\n Ĥ: \"H\",\n ĥ: \"h\",\n Ħ: \"H\",\n ħ: \"h\",\n Ḫ: \"H\",\n ḫ: \"h\",\n Ĩ: \"I\",\n ĩ: \"i\",\n Ī: \"I\",\n ī: \"i\",\n Ĭ: \"I\",\n ĭ: \"i\",\n Į: \"I\",\n į: \"i\",\n İ: \"I\",\n ı: \"i\",\n IJ: \"IJ\",\n ij: \"ij\",\n Ĵ: \"J\",\n ĵ: \"j\",\n Ķ: \"K\",\n ķ: \"k\",\n Ḱ: \"K\",\n ḱ: \"k\",\n K̆: \"K\",\n k̆: \"k\",\n Ĺ: \"L\",\n ĺ: \"l\",\n Ļ: \"L\",\n ļ: \"l\",\n Ľ: \"L\",\n ľ: \"l\",\n Ŀ: \"L\",\n ŀ: \"l\",\n Ł: \"l\",\n ł: \"l\",\n Ḿ: \"M\",\n ḿ: \"m\",\n M̆: \"M\",\n m̆: \"m\",\n Ń: \"N\",\n ń: \"n\",\n Ņ: \"N\",\n ņ: \"n\",\n Ň: \"N\",\n ň: \"n\",\n ʼn: \"n\",\n N̆: \"N\",\n n̆: \"n\",\n Ō: \"O\",\n ō: \"o\",\n Ŏ: \"O\",\n ŏ: \"o\",\n Ő: \"O\",\n ő: \"o\",\n Œ: \"OE\",\n œ: \"oe\",\n P̆: \"P\",\n p̆: \"p\",\n Ŕ: \"R\",\n ŕ: \"r\",\n Ŗ: \"R\",\n ŗ: \"r\",\n Ř: \"R\",\n ř: \"r\",\n R̆: \"R\",\n r̆: \"r\",\n Ȓ: \"R\",\n ȓ: \"r\",\n Ś: \"S\",\n ś: \"s\",\n Ŝ: \"S\",\n ŝ: \"s\",\n Ş: \"S\",\n Ș: \"S\",\n ș: \"s\",\n ş: \"s\",\n Š: \"S\",\n š: \"s\",\n Ţ: \"T\",\n ţ: \"t\",\n ț: \"t\",\n Ț: \"T\",\n Ť: \"T\",\n ť: \"t\",\n Ŧ: \"T\",\n ŧ: \"t\",\n T̆: \"T\",\n t̆: \"t\",\n Ũ: \"U\",\n ũ: \"u\",\n Ū: \"U\",\n ū: \"u\",\n Ŭ: \"U\",\n ŭ: \"u\",\n Ů: \"U\",\n ů: \"u\",\n Ű: \"U\",\n ű: \"u\",\n Ų: \"U\",\n ų: \"u\",\n Ȗ: \"U\",\n ȗ: \"u\",\n V̆: \"V\",\n v̆: \"v\",\n Ŵ: \"W\",\n ŵ: \"w\",\n Ẃ: \"W\",\n ẃ: \"w\",\n X̆: \"X\",\n x̆: \"x\",\n Ŷ: \"Y\",\n ŷ: \"y\",\n Ÿ: \"Y\",\n Y̆: \"Y\",\n y̆: \"y\",\n Ź: \"Z\",\n ź: \"z\",\n Ż: \"Z\",\n ż: \"z\",\n Ž: \"Z\",\n ž: \"z\",\n ſ: \"s\",\n ƒ: \"f\",\n Ơ: \"O\",\n ơ: \"o\",\n Ư: \"U\",\n ư: \"u\",\n Ǎ: \"A\",\n ǎ: \"a\",\n Ǐ: \"I\",\n ǐ: \"i\",\n Ǒ: \"O\",\n ǒ: \"o\",\n Ǔ: \"U\",\n ǔ: \"u\",\n Ǖ: \"U\",\n ǖ: \"u\",\n Ǘ: \"U\",\n ǘ: \"u\",\n Ǚ: \"U\",\n ǚ: \"u\",\n Ǜ: \"U\",\n ǜ: \"u\",\n Ứ: \"U\",\n ứ: \"u\",\n Ṹ: \"U\",\n ṹ: \"u\",\n Ǻ: \"A\",\n ǻ: \"a\",\n Ǽ: \"AE\",\n ǽ: \"ae\",\n Ǿ: \"O\",\n ǿ: \"o\",\n Þ: \"TH\",\n þ: \"th\",\n Ṕ: \"P\",\n ṕ: \"p\",\n Ṥ: \"S\",\n ṥ: \"s\",\n X́: \"X\",\n x́: \"x\",\n Ѓ: \"Г\",\n ѓ: \"г\",\n Ќ: \"К\",\n ќ: \"к\",\n A̋: \"A\",\n a̋: \"a\",\n E̋: \"E\",\n e̋: \"e\",\n I̋: \"I\",\n i̋: \"i\",\n Ǹ: \"N\",\n ǹ: \"n\",\n Ồ: \"O\",\n ồ: \"o\",\n Ṑ: \"O\",\n ṑ: \"o\",\n Ừ: \"U\",\n ừ: \"u\",\n Ẁ: \"W\",\n ẁ: \"w\",\n Ỳ: \"Y\",\n ỳ: \"y\",\n Ȁ: \"A\",\n ȁ: \"a\",\n Ȅ: \"E\",\n ȅ: \"e\",\n Ȉ: \"I\",\n ȉ: \"i\",\n Ȍ: \"O\",\n ȍ: \"o\",\n Ȑ: \"R\",\n ȑ: \"r\",\n Ȕ: \"U\",\n ȕ: \"u\",\n B̌: \"B\",\n b̌: \"b\",\n Č̣: \"C\",\n č̣: \"c\",\n Ê̌: \"E\",\n ê̌: \"e\",\n F̌: \"F\",\n f̌: \"f\",\n Ǧ: \"G\",\n ǧ: \"g\",\n Ȟ: \"H\",\n ȟ: \"h\",\n J̌: \"J\",\n ǰ: \"j\",\n Ǩ: \"K\",\n ǩ: \"k\",\n M̌: \"M\",\n m̌: \"m\",\n P̌: \"P\",\n p̌: \"p\",\n Q̌: \"Q\",\n q̌: \"q\",\n Ř̩: \"R\",\n ř̩: \"r\",\n Ṧ: \"S\",\n ṧ: \"s\",\n V̌: \"V\",\n v̌: \"v\",\n W̌: \"W\",\n w̌: \"w\",\n X̌: \"X\",\n x̌: \"x\",\n Y̌: \"Y\",\n y̌: \"y\",\n A̧: \"A\",\n a̧: \"a\",\n B̧: \"B\",\n b̧: \"b\",\n Ḑ: \"D\",\n ḑ: \"d\",\n Ȩ: \"E\",\n ȩ: \"e\",\n Ɛ̧: \"E\",\n ɛ̧: \"e\",\n Ḩ: \"H\",\n ḩ: \"h\",\n I̧: \"I\",\n i̧: \"i\",\n Ɨ̧: \"I\",\n ɨ̧: \"i\",\n M̧: \"M\",\n m̧: \"m\",\n O̧: \"O\",\n o̧: \"o\",\n Q̧: \"Q\",\n q̧: \"q\",\n U̧: \"U\",\n u̧: \"u\",\n X̧: \"X\",\n x̧: \"x\",\n Z̧: \"Z\",\n z̧: \"z\"\n};\n\n/**\n * Removes accents from a string.\n *\n * @param str - The string to remove accents from\n * @returns The string without accents\n */\nexport const removeAccents = (str: string) =>\n str.replace(\n // eslint-disable-next-line regexp/no-dupe-disjunctions, regexp/prefer-character-class\n new RegExp(Object.keys(characterMap).join(\"|\"), \"g\"),\n match => characterMap[match]!\n );\n"],"mappings":";AAkBA,MAAa,eAAuC;CAClD,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,IAAI;CACJ,IAAI;CACJ,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH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IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACL;;;;;;;AAQD,MAAa,iBAAiB,QAC5B,IAAI,QAEF,IAAI,OAAO,OAAO,KAAK,aAAa,CAAC,KAAK,IAAI,EAAE,IAAI,GACpD,UAAS,aAAa,OACvB"}
|
|
1
|
+
{"version":3,"file":"remove-accents.mjs","names":[],"sources":["../src/remove-accents.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 const characterMap: Record<string, string> = {\n À: \"A\",\n Á: \"A\",\n Â: \"A\",\n Ã: \"A\",\n Ä: \"A\",\n Å: \"A\",\n Ấ: \"A\",\n Ắ: \"A\",\n Ẳ: \"A\",\n Ẵ: \"A\",\n Ặ: \"A\",\n Æ: \"AE\",\n Ầ: \"A\",\n Ằ: \"A\",\n Ȃ: \"A\",\n Ç: \"C\",\n Ḉ: \"C\",\n È: \"E\",\n É: \"E\",\n Ê: \"E\",\n Ë: \"E\",\n Ế: \"E\",\n Ḗ: \"E\",\n Ề: \"E\",\n Ḕ: \"E\",\n Ḝ: \"E\",\n Ȇ: \"E\",\n Ì: \"I\",\n Í: \"I\",\n Î: \"I\",\n Ï: \"I\",\n Ḯ: \"I\",\n Ȋ: \"I\",\n Ð: \"D\",\n Ñ: \"N\",\n Ò: \"O\",\n Ó: \"O\",\n Ô: \"O\",\n Õ: \"O\",\n Ö: \"O\",\n Ø: \"O\",\n Ố: \"O\",\n Ṍ: \"O\",\n Ṓ: \"O\",\n Ȏ: \"O\",\n Ù: \"U\",\n Ú: \"U\",\n Û: \"U\",\n Ü: \"U\",\n Ý: \"Y\",\n à: \"a\",\n á: \"a\",\n â: \"a\",\n ã: \"a\",\n ä: \"a\",\n å: \"a\",\n ấ: \"a\",\n ắ: \"a\",\n ẳ: \"a\",\n ẵ: \"a\",\n ặ: \"a\",\n æ: \"ae\",\n ầ: \"a\",\n ằ: \"a\",\n ȃ: \"a\",\n ç: \"c\",\n ḉ: \"c\",\n è: \"e\",\n é: \"e\",\n ê: \"e\",\n ë: \"e\",\n ế: \"e\",\n ḗ: \"e\",\n ề: \"e\",\n ḕ: \"e\",\n ḝ: \"e\",\n ȇ: \"e\",\n ì: \"i\",\n í: \"i\",\n î: \"i\",\n ï: \"i\",\n ḯ: \"i\",\n ȋ: \"i\",\n ð: \"d\",\n ñ: \"n\",\n ò: \"o\",\n ó: \"o\",\n ô: \"o\",\n õ: \"o\",\n ö: \"o\",\n ø: \"o\",\n ố: \"o\",\n ṍ: \"o\",\n ṓ: \"o\",\n ȏ: \"o\",\n ù: \"u\",\n ú: \"u\",\n û: \"u\",\n ü: \"u\",\n ý: \"y\",\n ÿ: \"y\",\n Ā: \"A\",\n ā: \"a\",\n Ă: \"A\",\n ă: \"a\",\n Ą: \"A\",\n ą: \"a\",\n Ć: \"C\",\n ć: \"c\",\n Ĉ: \"C\",\n ĉ: \"c\",\n Ċ: \"C\",\n ċ: \"c\",\n Č: \"C\",\n č: \"c\",\n C̆: \"C\",\n c̆: \"c\",\n Ď: \"D\",\n ď: \"d\",\n Đ: \"D\",\n đ: \"d\",\n Ē: \"E\",\n ē: \"e\",\n Ĕ: \"E\",\n ĕ: \"e\",\n Ė: \"E\",\n ė: \"e\",\n Ę: \"E\",\n ę: \"e\",\n Ě: \"E\",\n ě: \"e\",\n Ĝ: \"G\",\n Ǵ: \"G\",\n ĝ: \"g\",\n ǵ: \"g\",\n Ğ: \"G\",\n ğ: \"g\",\n Ġ: \"G\",\n ġ: \"g\",\n Ģ: \"G\",\n ģ: \"g\",\n Ĥ: \"H\",\n ĥ: \"h\",\n Ħ: \"H\",\n ħ: \"h\",\n Ḫ: \"H\",\n ḫ: \"h\",\n Ĩ: \"I\",\n ĩ: \"i\",\n Ī: \"I\",\n ī: \"i\",\n Ĭ: \"I\",\n ĭ: \"i\",\n Į: \"I\",\n į: \"i\",\n İ: \"I\",\n ı: \"i\",\n IJ: \"IJ\",\n ij: \"ij\",\n Ĵ: \"J\",\n ĵ: \"j\",\n Ķ: \"K\",\n ķ: \"k\",\n Ḱ: \"K\",\n ḱ: \"k\",\n K̆: \"K\",\n k̆: \"k\",\n Ĺ: \"L\",\n ĺ: \"l\",\n Ļ: \"L\",\n ļ: \"l\",\n Ľ: \"L\",\n ľ: \"l\",\n Ŀ: \"L\",\n ŀ: \"l\",\n Ł: \"l\",\n ł: \"l\",\n Ḿ: \"M\",\n ḿ: \"m\",\n M̆: \"M\",\n m̆: \"m\",\n Ń: \"N\",\n ń: \"n\",\n Ņ: \"N\",\n ņ: \"n\",\n Ň: \"N\",\n ň: \"n\",\n ʼn: \"n\",\n N̆: \"N\",\n n̆: \"n\",\n Ō: \"O\",\n ō: \"o\",\n Ŏ: \"O\",\n ŏ: \"o\",\n Ő: \"O\",\n ő: \"o\",\n Œ: \"OE\",\n œ: \"oe\",\n P̆: \"P\",\n p̆: \"p\",\n Ŕ: \"R\",\n ŕ: \"r\",\n Ŗ: \"R\",\n ŗ: \"r\",\n Ř: \"R\",\n ř: \"r\",\n R̆: \"R\",\n r̆: \"r\",\n Ȓ: \"R\",\n ȓ: \"r\",\n Ś: \"S\",\n ś: \"s\",\n Ŝ: \"S\",\n ŝ: \"s\",\n Ş: \"S\",\n Ș: \"S\",\n ș: \"s\",\n ş: \"s\",\n Š: \"S\",\n š: \"s\",\n Ţ: \"T\",\n ţ: \"t\",\n ț: \"t\",\n Ț: \"T\",\n Ť: \"T\",\n ť: \"t\",\n Ŧ: \"T\",\n ŧ: \"t\",\n T̆: \"T\",\n t̆: \"t\",\n Ũ: \"U\",\n ũ: \"u\",\n Ū: \"U\",\n ū: \"u\",\n Ŭ: \"U\",\n ŭ: \"u\",\n Ů: \"U\",\n ů: \"u\",\n Ű: \"U\",\n ű: \"u\",\n Ų: \"U\",\n ų: \"u\",\n Ȗ: \"U\",\n ȗ: \"u\",\n V̆: \"V\",\n v̆: \"v\",\n Ŵ: \"W\",\n ŵ: \"w\",\n Ẃ: \"W\",\n ẃ: \"w\",\n X̆: \"X\",\n x̆: \"x\",\n Ŷ: \"Y\",\n ŷ: \"y\",\n Ÿ: \"Y\",\n Y̆: \"Y\",\n y̆: \"y\",\n Ź: \"Z\",\n ź: \"z\",\n Ż: \"Z\",\n ż: \"z\",\n Ž: \"Z\",\n ž: \"z\",\n ſ: \"s\",\n ƒ: \"f\",\n Ơ: \"O\",\n ơ: \"o\",\n Ư: \"U\",\n ư: \"u\",\n Ǎ: \"A\",\n ǎ: \"a\",\n Ǐ: \"I\",\n ǐ: \"i\",\n Ǒ: \"O\",\n ǒ: \"o\",\n Ǔ: \"U\",\n ǔ: \"u\",\n Ǖ: \"U\",\n ǖ: \"u\",\n Ǘ: \"U\",\n ǘ: \"u\",\n Ǚ: \"U\",\n ǚ: \"u\",\n Ǜ: \"U\",\n ǜ: \"u\",\n Ứ: \"U\",\n ứ: \"u\",\n Ṹ: \"U\",\n ṹ: \"u\",\n Ǻ: \"A\",\n ǻ: \"a\",\n Ǽ: \"AE\",\n ǽ: \"ae\",\n Ǿ: \"O\",\n ǿ: \"o\",\n Þ: \"TH\",\n þ: \"th\",\n Ṕ: \"P\",\n ṕ: \"p\",\n Ṥ: \"S\",\n ṥ: \"s\",\n X́: \"X\",\n x́: \"x\",\n Ѓ: \"Г\",\n ѓ: \"г\",\n Ќ: \"К\",\n ќ: \"к\",\n A̋: \"A\",\n a̋: \"a\",\n E̋: \"E\",\n e̋: \"e\",\n I̋: \"I\",\n i̋: \"i\",\n Ǹ: \"N\",\n ǹ: \"n\",\n Ồ: \"O\",\n ồ: \"o\",\n Ṑ: \"O\",\n ṑ: \"o\",\n Ừ: \"U\",\n ừ: \"u\",\n Ẁ: \"W\",\n ẁ: \"w\",\n Ỳ: \"Y\",\n ỳ: \"y\",\n Ȁ: \"A\",\n ȁ: \"a\",\n Ȅ: \"E\",\n ȅ: \"e\",\n Ȉ: \"I\",\n ȉ: \"i\",\n Ȍ: \"O\",\n ȍ: \"o\",\n Ȑ: \"R\",\n ȑ: \"r\",\n Ȕ: \"U\",\n ȕ: \"u\",\n B̌: \"B\",\n b̌: \"b\",\n Č̣: \"C\",\n č̣: \"c\",\n Ê̌: \"E\",\n ê̌: \"e\",\n F̌: \"F\",\n f̌: \"f\",\n Ǧ: \"G\",\n ǧ: \"g\",\n Ȟ: \"H\",\n ȟ: \"h\",\n J̌: \"J\",\n ǰ: \"j\",\n Ǩ: \"K\",\n ǩ: \"k\",\n M̌: \"M\",\n m̌: \"m\",\n P̌: \"P\",\n p̌: \"p\",\n Q̌: \"Q\",\n q̌: \"q\",\n Ř̩: \"R\",\n ř̩: \"r\",\n Ṧ: \"S\",\n ṧ: \"s\",\n V̌: \"V\",\n v̌: \"v\",\n W̌: \"W\",\n w̌: \"w\",\n X̌: \"X\",\n x̌: \"x\",\n Y̌: \"Y\",\n y̌: \"y\",\n A̧: \"A\",\n a̧: \"a\",\n B̧: \"B\",\n b̧: \"b\",\n Ḑ: \"D\",\n ḑ: \"d\",\n Ȩ: \"E\",\n ȩ: \"e\",\n Ɛ̧: \"E\",\n ɛ̧: \"e\",\n Ḩ: \"H\",\n ḩ: \"h\",\n I̧: \"I\",\n i̧: \"i\",\n Ɨ̧: \"I\",\n ɨ̧: \"i\",\n M̧: \"M\",\n m̧: \"m\",\n O̧: \"O\",\n o̧: \"o\",\n Q̧: \"Q\",\n q̧: \"q\",\n U̧: \"U\",\n u̧: \"u\",\n X̧: \"X\",\n x̧: \"x\",\n Z̧: \"Z\",\n z̧: \"z\"\n};\n\n/**\n * Removes accents from a string.\n *\n * @param str - The string to remove accents from\n * @returns The string without accents\n */\nexport const removeAccents = (str: string) =>\n str.replace(\n // eslint-disable-next-line regexp/no-dupe-disjunctions, regexp/prefer-character-class\n new RegExp(Object.keys(characterMap).join(\"|\"), \"g\"),\n match => characterMap[match]!\n );\n"],"mappings":";AAkBA,MAAa,eAAuC;CAClD,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,IAAI;CACJ,IAAI;CACJ,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,IAAI;CACJ,IAAI;CACJ,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,IAAI;CACJ,IAAI;CACJ,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,IAAI;CACJ,IAAI;CACJ,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,IAAI;CACJ,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"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"remove-empty-items.mjs","names":[],"sources":["../src/remove-empty-items.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 * Removes empty items from an array\n *\n * @param arr - The array to remove empty items from\n * @returns The array with empty items removed\n */\nexport const removeEmptyItems = <T = any>(\n arr: (T | undefined | null)[]\n): NonNullable<T>[] => arr.filter(Boolean) as NonNullable<T>[];\n"],"mappings":";;;;;;;AAwBA,MAAa,oBACX,QACqB,IAAI,OAAO,QAAQ"}
|
package/dist/set-field.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-field.mjs","names":[],"sources":["../src/set-field.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"set-field.mjs","names":[],"sources":["../src/set-field.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 { isObjectIndex } from \"@stryke/type-checks/is-object-index\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport type { DeepKey } from \"@stryke/types/object\";\nimport { toPath } from \"./to-path\";\n\n/**\n * Sets a value at a given deep path in an object.\n *\n * @param object - The object to set the value in.\n * @param path - The deep path to set the value at.\n * @param value - The value to set.\n * @returns The object with the value set at the given deep path.\n */\nexport function setField<\n TObject extends Record<string, any> = Record<string, any>\n>(object: TObject, path: DeepKey<TObject>, value: unknown): TObject {\n const resolvedPath = Array.isArray(path)\n ? path\n : isString(path)\n ? toPath(path)\n : [path];\n\n // Validate resolvedPath to prevent prototype pollution\n for (const key of resolvedPath) {\n if (key === \"__proto__\" || key === \"constructor\" || key === \"prototype\") {\n throw new Error(`Invalid key in path: ${key}`);\n }\n }\n\n let current: any = object;\n for (let i = 0; i < resolvedPath.length - 1; i++) {\n const key = resolvedPath[i];\n const nextKey = resolvedPath[i + 1];\n\n if (current[key] === null) {\n current[key] = isObjectIndex(nextKey) ? [] : {};\n }\n\n current = current[key];\n }\n\n const lastKey = resolvedPath.at(-1);\n if (lastKey) {\n current[lastKey] = value;\n }\n\n return object;\n}\n"],"mappings":";;;;;;;;;;;;;AA+BA,SAAgB,SAEd,QAAiB,MAAwB,OAAyB;CAClE,MAAM,eAAe,MAAM,QAAQ,KAAK,GACpC,OACA,SAAS,KAAK,GACZ,OAAO,KAAK,GACZ,CAAC,KAAK;AAGZ,MAAK,MAAM,OAAO,aAChB,KAAI,QAAQ,eAAe,QAAQ,iBAAiB,QAAQ,YAC1D,OAAM,IAAI,MAAM,wBAAwB,MAAM;CAIlD,IAAI,UAAe;AACnB,MAAK,IAAI,IAAI,GAAG,IAAI,aAAa,SAAS,GAAG,KAAK;EAChD,MAAM,MAAM,aAAa;EACzB,MAAM,UAAU,aAAa,IAAI;AAEjC,MAAI,QAAQ,SAAS,KACnB,SAAQ,OAAO,cAAc,QAAQ,GAAG,EAAE,GAAG,EAAE;AAGjD,YAAU,QAAQ;;CAGpB,MAAM,UAAU,aAAa,GAAG,GAAG;AACnC,KAAI,QACF,SAAQ,WAAW;AAGrB,QAAO"}
|
package/dist/to-deep-key.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-deep-key.mjs","names":[],"sources":["../src/to-deep-key.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"to-deep-key.mjs","names":[],"sources":["../src/to-deep-key.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 { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\n\n/**\n * Converts an array of path segments into a deep key string.\n *\n * This function takes an array of strings and numbers representing path segments and combines them into a deep key string.\n *\n * @example\n * toDeepKey(['a', 'b', 'c']) // Returns 'a.b.c'\n * toDeepKey(['a', 0, 'c']) // Returns 'a[0].c'\n * toDeepKey(['', 'a', 'b', 'c']) // Returns '.a.b.c'\n * toDeepKey(['a', 'b.c', 'd']) // Returns 'a.b.c.d'\n * toDeepKey([]) // Returns ''\n * toDeepKey(['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']) // Returns '.a.b.c.d.e.f.g.h'\n *\n * @param path - An array of strings and numbers representing path segments.\n * @returns A deep key string.\n */\nexport function toDeepKey(path: string[]): string {\n return path.reduce((ret, segment) => {\n return addPathToDeepKey(ret, segment);\n });\n}\n\n/**\n * Adds a path segment to a deep key string.\n *\n * @remarks\n * This function takes a deep key string and a path segment and combines them into a new deep key string.\n *\n * @example\n * ```ts\n * addPathToDeepKey('a.b', 'c') // Returns 'a.b.c'\n * addPathToDeepKey('a[0]', 'c') // Returns 'a[0].c'\n * addPathToDeepKey('.a.b', 'c') // Returns '.a.b.c'\n * addPathToDeepKey('a.b', 'b.c') // Returns 'a.b.b.c'\n * addPathToDeepKey('', 'a') // Returns 'a'\n * addPathToDeepKey('.a.b', 'c.d') // Returns '.a.b.c.d'\n * ```\n *\n * @param deepKey - The deep key string to add the path segment to.\n * @param path - The path segment to add to the deep key string.\n * @returns A new deep key string.\n */\nexport function addPathToDeepKey(\n deepKey: string,\n path: string | number\n): string {\n if (isNumber(path) || Number.isInteger(path)) {\n return `${deepKey}[${path}]`;\n }\n if (isSetString(path)) {\n return `${deepKey}.${path}`;\n }\n\n return deepKey;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,UAAU,MAAwB;AAChD,QAAO,KAAK,QAAQ,KAAK,YAAY;AACnC,SAAO,iBAAiB,KAAK,QAAQ;GACrC;;;;;;;;;;;;;;;;;;;;;;AAuBJ,SAAgB,iBACd,SACA,MACQ;AACR,KAAI,SAAS,KAAK,IAAI,OAAO,UAAU,KAAK,CAC1C,QAAO,GAAG,QAAQ,GAAG,KAAK;AAE5B,KAAI,YAAY,KAAK,CACnB,QAAO,GAAG,QAAQ,GAAG;AAGvB,QAAO"}
|
package/dist/to-path.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-path.mjs","names":[],"sources":["../src/to-path.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"to-path.mjs","names":[],"sources":["../src/to-path.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 DOTS_KEY = /^[\\w.]+$/g;\n\nconst ESCAPE_REGEXP = /\\\\(?<temp1>\\\\)?/g;\nconst PROPERTY_REGEXP = new RegExp(\n // Match anything that isn't a dot or bracket.\n `${String.raw`[^.[\\]]+`}|${\n // Or match property names within brackets.\n String.raw`\\[(?:`\n // Match a non-string expression.\n }([^\"'][^[]*)` +\n `|${\n // Or match strings (supports escaping characters).\n String.raw`([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2`\n }${String.raw`)\\]`}|${\n // Or match \"\" as the space between consecutive dots or empty brackets.\n String.raw`(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))`\n }`,\n \"g\"\n);\n\n/**\n * Converts a deep key string into an array of path segments.\n *\n * @remarks\n * This function takes a string representing a deep key (e.g., 'a.b.c' or 'a[b][c]') and breaks it down into an array of strings, each representing a segment of the path.\n *\n * @example\n * ```ts\n * toPath('a.b.c') // Returns ['a', 'b', 'c']\n * toPath('a[b][c]') // Returns ['a', 'b', 'c']\n * toPath('.a.b.c') // Returns ['', 'a', 'b', 'c']\n * toPath('a[\"b.c\"].d') // Returns ['a', 'b.c', 'd']\n * toPath('') // Returns []\n * toPath('.a[b].c.d[e][\"f.g\"].h') // Returns ['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']\n * ```\n *\n * @param deepKey - The deep key string to convert.\n * @returns An array of strings, each representing a segment of the path.\n */\nexport function toPath(deepKey: string): string[] {\n if (DOTS_KEY.test(deepKey)) {\n return deepKey.split(\".\");\n }\n\n const result: string[] = [];\n\n if (deepKey[0] === \".\") {\n result.push(\"\");\n }\n\n const matches = deepKey.matchAll(PROPERTY_REGEXP);\n\n for (const match of matches) {\n let key = match[0];\n const expr = match[1];\n const quote = match[2];\n const substr = match[3];\n\n if (quote && substr) {\n key = substr.replace(ESCAPE_REGEXP, \"$1\");\n } else if (expr) {\n key = expr;\n }\n\n result.push(key);\n }\n\n return result;\n}\n"],"mappings":";AAkBA,MAAM,WAAW;AAEjB,MAAM,gBAAgB;AACtB,MAAM,kBAAkB,IAAI,OAE1B,GAAG,OAAO,GAAG,WAAW,GAEtB,OAAO,GAAG,QAEX,eAGG,OAAO,GAAG,oCACT,OAAO,GAAG,MAAM,GAEjB,OAAO,GAAG,kCAEd,IACD;;;;;;;;;;;;;;;;;;;;AAqBD,SAAgB,OAAO,SAA2B;AAChD,KAAI,SAAS,KAAK,QAAQ,CACxB,QAAO,QAAQ,MAAM,IAAI;CAG3B,MAAM,SAAmB,EAAE;AAE3B,KAAI,QAAQ,OAAO,IACjB,QAAO,KAAK,GAAG;CAGjB,MAAM,UAAU,QAAQ,SAAS,gBAAgB;AAEjD,MAAK,MAAM,SAAS,SAAS;EAC3B,IAAI,MAAM,MAAM;EAChB,MAAM,OAAO,MAAM;EACnB,MAAM,QAAQ,MAAM;EACpB,MAAM,SAAS,MAAM;AAErB,MAAI,SAAS,OACX,OAAM,OAAO,QAAQ,eAAe,KAAK;WAChC,KACT,OAAM;AAGR,SAAO,KAAK,IAAI;;AAGlB,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unflatten-object.mjs","names":[],"sources":["../src/unflatten-object.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"unflatten-object.mjs","names":[],"sources":["../src/unflatten-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 type { DeepKey, DeepValue } from \"@stryke/types\";\nimport { setField } from \"./set-field\";\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 deepKeyObject - The object to flatten.\n * @returns - The flattened object.\n */\nexport function unflattenObject<\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>(deepKeyObject: TDeepKeyObject): TObject {\n return Object.entries(deepKeyObject).reduce(\n (ret: TObject, [key, value]: [string, any]) => {\n return setField<TObject>(ret, key as DeepKey<TObject>, value);\n },\n {} as TObject\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,gBAKd,eAAwC;AACxC,QAAO,OAAO,QAAQ,cAAc,CAAC,QAClC,KAAc,CAAC,KAAK,WAA0B;AAC7C,SAAO,SAAkB,KAAK,KAAyB,MAAM;IAE/D,EAAE,CACH"}
|
package/dist/union.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"union.mjs","names":[],"sources":["../src/union.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n
|
|
1
|
+
{"version":3,"file":"union.mjs","names":[],"sources":["../src/union.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 { getUnique } from \"./get-unique\";\n\n/**\n * Creates an array of unique values from all given arrays.\n *\n * @remarks\n * This function takes two arrays, merges them into a single array, and returns a new array\n * containing only the unique values from the merged array.\n *\n * @example\n * ```ts\n * const array1 = [1, 2, 3];\n * const array2 = [3, 4, 5];\n * const result = union(array1, array2);\n * // result will be [1, 2, 3, 4, 5]\n * ```\n *\n * @param arr1 - The first array to merge and filter for unique values.\n * @param arr2 - The second array to merge and filter for unique values.\n * @returns A new array of unique values.\n */\nexport function union<T>(arr1: readonly T[], arr2: readonly T[]): T[] {\n return getUnique([...arr1, ...arr2]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,MAAS,MAAoB,MAAyB;AACpE,QAAO,UAAU,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/helpers",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.26",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A package containing miscellaneous helper functions that are used across many different Storm Software projects.",
|
|
6
6
|
"repository": {
|
|
@@ -97,11 +97,11 @@
|
|
|
97
97
|
"module": "./dist/index.mjs",
|
|
98
98
|
"types": "./dist/index.d.cts",
|
|
99
99
|
"dependencies": {
|
|
100
|
-
"@stryke/convert": "^0.7.
|
|
101
|
-
"@stryke/type-checks": "^0.6.
|
|
102
|
-
"@stryke/types": "^0.12.
|
|
100
|
+
"@stryke/convert": "^0.7.17",
|
|
101
|
+
"@stryke/type-checks": "^0.6.19",
|
|
102
|
+
"@stryke/types": "^0.12.14"
|
|
103
103
|
},
|
|
104
104
|
"devDependencies": { "tsdown": "^0.21.10" },
|
|
105
105
|
"publishConfig": { "access": "public" },
|
|
106
|
-
"gitHead": "
|
|
106
|
+
"gitHead": "d3f870d01085e6fa75e7bb1b82609476531953fe"
|
|
107
107
|
}
|