@stryke/helpers 0.10.12 → 0.10.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/arg-identity.cjs +1 -0
- package/dist/arg-identity.d.cts.map +1 -1
- package/dist/arg-identity.d.mts.map +1 -1
- package/dist/deep-clone.cjs +4 -5
- package/dist/deep-clone.d.cts.map +1 -1
- package/dist/deep-clone.d.mts.map +1 -1
- package/dist/deep-clone.mjs +1 -3
- package/dist/deep-clone.mjs.map +1 -1
- package/dist/deep-merge.cjs +7 -6
- package/dist/deep-merge.d.cts.map +1 -1
- package/dist/deep-merge.d.mts.map +1 -1
- package/dist/deep-merge.mjs +3 -3
- package/dist/deep-merge.mjs.map +1 -1
- package/dist/filter-empty.cjs +3 -2
- package/dist/filter-empty.d.cts.map +1 -1
- package/dist/filter-empty.d.mts.map +1 -1
- package/dist/filter-empty.mjs +1 -1
- package/dist/flatten-object.cjs +3 -3
- package/dist/flatten-object.d.cts +1 -2
- package/dist/flatten-object.d.cts.map +1 -1
- package/dist/flatten-object.d.mts +1 -2
- package/dist/flatten-object.d.mts.map +1 -1
- package/dist/flatten-object.mjs +1 -2
- package/dist/flatten-object.mjs.map +1 -1
- package/dist/get-field.cjs +5 -12
- package/dist/get-field.d.cts.map +1 -1
- package/dist/get-field.d.mts.map +1 -1
- package/dist/get-field.mjs +2 -10
- package/dist/get-field.mjs.map +1 -1
- package/dist/get-ordered-by.cjs +1 -0
- package/dist/get-ordered-by.d.cts.map +1 -1
- package/dist/get-ordered-by.d.mts.map +1 -1
- package/dist/get-unique.cjs +1 -0
- package/dist/get-unique.d.cts.map +1 -1
- package/dist/get-unique.d.mts.map +1 -1
- package/dist/identity.cjs +1 -0
- package/dist/identity.d.cts.map +1 -1
- package/dist/identity.d.mts.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/is-equal.cjs +5 -4
- package/dist/is-equal.d.cts.map +1 -1
- package/dist/is-equal.d.mts.map +1 -1
- package/dist/is-equal.mjs +2 -2
- package/dist/lru-cache.cjs +1 -0
- package/dist/lru-cache.d.cts.map +1 -1
- package/dist/lru-cache.d.mts.map +1 -1
- package/dist/match-sorter.cjs +1 -0
- package/dist/match-sorter.d.cts.map +1 -1
- package/dist/match-sorter.d.mts.map +1 -1
- package/dist/match-sorter.mjs.map +1 -1
- package/dist/memoize.cjs +1 -0
- package/dist/memoize.d.cts.map +1 -1
- package/dist/memoize.d.mts.map +1 -1
- package/dist/memoize.mjs.map +1 -1
- package/dist/noop.cjs +1 -0
- package/dist/noop.d.cts.map +1 -1
- package/dist/noop.d.mts.map +1 -1
- package/dist/omit.cjs +1 -0
- package/dist/omit.d.cts.map +1 -1
- package/dist/omit.d.mts.map +1 -1
- package/dist/pick.cjs +1 -0
- package/dist/pick.d.cts.map +1 -1
- package/dist/pick.d.mts.map +1 -1
- package/dist/remove-accents.cjs +1 -0
- package/dist/remove-accents.d.cts.map +1 -1
- package/dist/remove-accents.d.mts.map +1 -1
- package/dist/remove-accents.mjs.map +1 -1
- package/dist/remove-empty-items.cjs +1 -0
- package/dist/remove-empty-items.d.cts.map +1 -1
- package/dist/remove-empty-items.d.mts.map +1 -1
- package/dist/set-field.cjs +5 -4
- package/dist/set-field.d.cts +1 -2
- package/dist/set-field.d.cts.map +1 -1
- package/dist/set-field.d.mts +1 -2
- package/dist/set-field.d.mts.map +1 -1
- package/dist/set-field.mjs +2 -2
- package/dist/set-field.mjs.map +1 -1
- package/dist/to-deep-key.cjs +5 -4
- package/dist/to-deep-key.d.cts.map +1 -1
- package/dist/to-deep-key.d.mts.map +1 -1
- package/dist/to-deep-key.mjs +2 -2
- package/dist/to-path.cjs +1 -0
- package/dist/to-path.d.cts.map +1 -1
- package/dist/to-path.d.mts.map +1 -1
- package/dist/to-path.mjs.map +1 -1
- package/dist/unflatten-object.cjs +1 -0
- package/dist/unflatten-object.d.cts +1 -2
- package/dist/unflatten-object.d.cts.map +1 -1
- package/dist/unflatten-object.d.mts +1 -2
- package/dist/unflatten-object.d.mts.map +1 -1
- package/dist/union.cjs +1 -0
- package/dist/union.d.cts.map +1 -1
- package/dist/union.d.mts.map +1 -1
- package/package.json +51 -46
- package/dist/convert/src/index.cjs +0 -5
- package/dist/convert/src/index.mjs +0 -7
- package/dist/convert/src/parse-type-definition.cjs +0 -1
- package/dist/convert/src/parse-type-definition.mjs +0 -3
- package/dist/convert/src/string-to-utf8-array.cjs +0 -5
- package/dist/convert/src/string-to-utf8-array.mjs +0 -6
- package/dist/convert/src/string-to-utf8-array.mjs.map +0 -1
- package/dist/convert/src/to-bool.cjs +0 -1
- package/dist/convert/src/to-bool.mjs +0 -3
- package/dist/convert/src/to-string-key.cjs +0 -15
- package/dist/convert/src/to-string-key.mjs +0 -15
- package/dist/convert/src/to-string-key.mjs.map +0 -1
- package/dist/convert/src/utf8-array-to-string.cjs +0 -5
- package/dist/convert/src/utf8-array-to-string.mjs +0 -6
- package/dist/convert/src/utf8-array-to-string.mjs.map +0 -1
- package/dist/type-checks/src/get-object-tag.cjs +0 -15
- package/dist/type-checks/src/get-object-tag.mjs +0 -15
- package/dist/type-checks/src/get-object-tag.mjs.map +0 -1
- package/dist/type-checks/src/index.cjs +0 -21
- package/dist/type-checks/src/index.mjs +0 -23
- package/dist/type-checks/src/is-buffer.cjs +0 -13
- package/dist/type-checks/src/is-buffer.mjs +0 -14
- package/dist/type-checks/src/is-buffer.mjs.map +0 -1
- package/dist/type-checks/src/is-collection.cjs +0 -1
- package/dist/type-checks/src/is-collection.mjs +0 -3
- package/dist/type-checks/src/is-deep-key.cjs +0 -34
- package/dist/type-checks/src/is-deep-key.mjs +0 -34
- package/dist/type-checks/src/is-deep-key.mjs.map +0 -1
- package/dist/type-checks/src/is-empty.cjs +0 -20
- package/dist/type-checks/src/is-empty.mjs +0 -21
- package/dist/type-checks/src/is-empty.mjs.map +0 -1
- package/dist/type-checks/src/is-function.cjs +0 -27
- package/dist/type-checks/src/is-function.mjs +0 -26
- package/dist/type-checks/src/is-function.mjs.map +0 -1
- package/dist/type-checks/src/is-mergeable-object.cjs +0 -14
- package/dist/type-checks/src/is-mergeable-object.mjs +0 -15
- package/dist/type-checks/src/is-mergeable-object.mjs.map +0 -1
- package/dist/type-checks/src/is-non-null-object.cjs +0 -16
- package/dist/type-checks/src/is-non-null-object.mjs +0 -17
- package/dist/type-checks/src/is-non-null-object.mjs.map +0 -1
- package/dist/type-checks/src/is-null.cjs +0 -12
- package/dist/type-checks/src/is-null.mjs +0 -12
- package/dist/type-checks/src/is-null.mjs.map +0 -1
- package/dist/type-checks/src/is-number.cjs +0 -18
- package/dist/type-checks/src/is-number.mjs +0 -18
- package/dist/type-checks/src/is-number.mjs.map +0 -1
- package/dist/type-checks/src/is-object-index.cjs +0 -25
- package/dist/type-checks/src/is-object-index.mjs +0 -25
- package/dist/type-checks/src/is-object-index.mjs.map +0 -1
- package/dist/type-checks/src/is-object.cjs +0 -19
- package/dist/type-checks/src/is-object.mjs +0 -20
- package/dist/type-checks/src/is-object.mjs.map +0 -1
- package/dist/type-checks/src/is-plain-object.cjs +0 -64
- package/dist/type-checks/src/is-plain-object.mjs +0 -64
- package/dist/type-checks/src/is-plain-object.mjs.map +0 -1
- package/dist/type-checks/src/is-primitive.cjs +0 -12
- package/dist/type-checks/src/is-primitive.mjs +0 -12
- package/dist/type-checks/src/is-primitive.mjs.map +0 -1
- package/dist/type-checks/src/is-react-element.cjs +0 -8
- package/dist/type-checks/src/is-react-element.mjs +0 -8
- package/dist/type-checks/src/is-react-element.mjs.map +0 -1
- package/dist/type-checks/src/is-set-string.cjs +0 -20
- package/dist/type-checks/src/is-set-string.mjs +0 -21
- package/dist/type-checks/src/is-set-string.mjs.map +0 -1
- package/dist/type-checks/src/is-set.cjs +0 -19
- package/dist/type-checks/src/is-set.mjs +0 -20
- package/dist/type-checks/src/is-set.mjs.map +0 -1
- package/dist/type-checks/src/is-string.cjs +0 -12
- package/dist/type-checks/src/is-string.mjs +0 -12
- package/dist/type-checks/src/is-string.mjs.map +0 -1
- package/dist/type-checks/src/is-typed-array.cjs +0 -8
- package/dist/type-checks/src/is-typed-array.mjs +0 -8
- package/dist/type-checks/src/is-typed-array.mjs.map +0 -1
- package/dist/type-checks/src/is-undefined.cjs +0 -8
- package/dist/type-checks/src/is-undefined.mjs +0 -8
- package/dist/type-checks/src/is-undefined.mjs.map +0 -1
- package/dist/type-checks/src/property-exists.cjs +0 -31
- package/dist/type-checks/src/property-exists.mjs +0 -31
- package/dist/type-checks/src/property-exists.mjs.map +0 -1
- package/dist/type-checks/src/type-detect.cjs +0 -15
- package/dist/type-checks/src/type-detect.mjs +0 -17
- package/dist/type-checks/src/type-detect.mjs.map +0 -1
- package/dist/types/src/base.d.cts +0 -8
- package/dist/types/src/base.d.cts.map +0 -1
- package/dist/types/src/base.d.mts +0 -8
- package/dist/types/src/base.d.mts.map +0 -1
- package/dist/types/src/json.d.cts +0 -28
- package/dist/types/src/json.d.cts.map +0 -1
- package/dist/types/src/json.d.mts +0 -28
- package/dist/types/src/json.d.mts.map +0 -1
- package/dist/types/src/object.d.cts +0 -125
- package/dist/types/src/object.d.cts.map +0 -1
- package/dist/types/src/object.d.mts +0 -125
- package/dist/types/src/object.d.mts.map +0 -1
- package/dist/types/src/string.d.cts +0 -6
- package/dist/types/src/string.d.cts.map +0 -1
- package/dist/types/src/string.d.mts +0 -6
- package/dist/types/src/string.d.mts.map +0 -1
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;;EAET,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,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"}
|
package/dist/get-ordered-by.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-ordered-by.d.cts","names":[],"sources":["../src/get-ordered-by.ts"],"
|
|
1
|
+
{"version":3,"file":"get-ordered-by.d.cts","names":[],"sources":["../src/get-ordered-by.ts"],"mappings":";KAkBK,KAAA;;;;;;AAmCL;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,YAAA,GAAA,CACd,UAAA,EAAY,CAAA,IACZ,IAAA,SAAa,CAAA,KACb,MAAA,EAAQ,KAAA,KACP,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-ordered-by.d.mts","names":[],"sources":["../src/get-ordered-by.ts"],"
|
|
1
|
+
{"version":3,"file":"get-ordered-by.d.mts","names":[],"sources":["../src/get-ordered-by.ts"],"mappings":";KAkBK,KAAA;;;;;;AAmCL;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,YAAA,GAAA,CACd,UAAA,EAAY,CAAA,IACZ,IAAA,SAAa,CAAA,KACb,MAAA,EAAQ,KAAA,KACP,CAAA"}
|
package/dist/get-unique.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-unique.d.cts","names":[],"sources":["../src/get-unique.ts"],"
|
|
1
|
+
{"version":3,"file":"get-unique.d.cts","names":[],"sources":["../src/get-unique.ts"],"mappings":";;AAwBA;;;;;cAAa,SAAA,YAAsB,GAAA,EAAK,CAAA,OAAM,CAAA;;;;;AAkB9C;;;;;;;;;;iBAAgB,WAAA,MAAA,CACd,GAAA,WAAc,CAAA,IACd,MAAA,IAAS,IAAA,EAAM,CAAA,KAAM,CAAA,GACpB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-unique.d.mts","names":[],"sources":["../src/get-unique.ts"],"
|
|
1
|
+
{"version":3,"file":"get-unique.d.mts","names":[],"sources":["../src/get-unique.ts"],"mappings":";;AAwBA;;;;;cAAa,SAAA,YAAsB,GAAA,EAAK,CAAA,OAAM,CAAA;;;;;AAkB9C;;;;;;;;;;iBAAgB,WAAA,MAAA,CACd,GAAA,WAAc,CAAA,IACd,MAAA,IAAS,IAAA,EAAM,CAAA,KAAM,CAAA,GACpB,CAAA"}
|
package/dist/identity.cjs
CHANGED
package/dist/identity.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.cts","names":[],"sources":["../src/identity.ts"],"
|
|
1
|
+
{"version":3,"file":"identity.d.cts","names":[],"sources":["../src/identity.ts"],"mappings":";;AA+BA;;;;;;;;;;;;iBAAgB,QAAA,GAAA,CAAY,CAAA,EAAG,CAAA,GAAI,CAAA"}
|
package/dist/identity.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.mts","names":[],"sources":["../src/identity.ts"],"
|
|
1
|
+
{"version":3,"file":"identity.d.mts","names":[],"sources":["../src/identity.ts"],"mappings":";;AA+BA;;;;;;;;;;;;iBAAgB,QAAA,GAAA,CAAY,CAAA,EAAG,CAAA,GAAI,CAAA"}
|
package/dist/index.cjs
CHANGED
package/dist/is-equal.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
|
|
3
|
+
let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
3
4
|
|
|
4
5
|
//#region src/is-equal.ts
|
|
5
6
|
const hasMap = typeof Map === "function";
|
|
@@ -45,10 +46,10 @@ function equal(a, b) {
|
|
|
45
46
|
const keys = Object.keys(a);
|
|
46
47
|
length = keys.length;
|
|
47
48
|
if (length !== Object.keys(b).length) return false;
|
|
48
|
-
for (let i = length; i-- !== 0;) if (!
|
|
49
|
+
for (let i = length; i-- !== 0;) if (!(0, _stryke_type_checks_is_set.isSet)(i) || !(0, _stryke_type_checks_is_set_string.isSetString)(keys[i]) || !Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
|
49
50
|
for (let i = length; i-- !== 0;) {
|
|
50
51
|
if (Array.isArray(keys) && (keys[i] === "_owner" || keys[i] === "__v" || keys[i] === "__o") && a.$$typeof) continue;
|
|
51
|
-
if (!
|
|
52
|
+
if (!(0, _stryke_type_checks_is_set.isSet)(i) || !(0, _stryke_type_checks_is_set_string.isSetString)(keys[i]) || !equal(a[keys[i]], b[keys[i]])) return false;
|
|
52
53
|
}
|
|
53
54
|
return true;
|
|
54
55
|
}
|
package/dist/is-equal.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-equal.d.cts","names":[],"sources":["../src/is-equal.ts"],"
|
|
1
|
+
{"version":3,"file":"is-equal.d.cts","names":[],"sources":["../src/is-equal.ts"],"mappings":";;AA+JA;;;;;;;;;;;;;;;;iBAAgB,OAAA,CAAQ,CAAA,OAAQ,CAAA"}
|
package/dist/is-equal.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-equal.d.mts","names":[],"sources":["../src/is-equal.ts"],"
|
|
1
|
+
{"version":3,"file":"is-equal.d.mts","names":[],"sources":["../src/is-equal.ts"],"mappings":";;AA+JA;;;;;;;;;;;;;;;;iBAAgB,OAAA,CAAQ,CAAA,OAAQ,CAAA"}
|
package/dist/is-equal.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isSet } from "
|
|
2
|
-
import { isSetString } from "
|
|
1
|
+
import { isSet } from "@stryke/type-checks/is-set";
|
|
2
|
+
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
3
3
|
|
|
4
4
|
//#region src/is-equal.ts
|
|
5
5
|
const hasMap = typeof Map === "function";
|
package/dist/lru-cache.cjs
CHANGED
package/dist/lru-cache.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lru-cache.d.cts","names":[],"sources":["../src/lru-cache.ts"],"
|
|
1
|
+
{"version":3,"file":"lru-cache.d.cts","names":[],"sources":["../src/lru-cache.ts"],"mappings":";;AAgEA;;;;;;;;;;;;;;;;;cAAa,QAAA;EAAA,iBACM,KAAA;EAAA,iBAEA,IAAA;EAAA,iBAEA,IAAA;EAAA,QAET,SAAA;EAAA,iBAES,OAAA;EAAA,iBAEA,aAAA;cAEL,OAAA,UAAiB,aAAA,IAAiB,KAAA,EAAO,CAAA;EAyC7C;;;;;EAAA,QAxBA,SAAA;EAyFD;;;;;EAAA,QA5EC,UAAA;EAoGQ;;;;;EAAA,QAzFR,UAAA;EA6HG;;;;;EAAA,QAnHH,UAAA;;;;;;;;;;;;;EAmBD,GAAA,CAAI,GAAA,UAAa,KAAA,EAAO,CAAA;;;;;;;EAoCxB,GAAA,CAAI,GAAA;;;;;;;EAUJ,GAAA,CAAI,GAAA,WAAc,CAAA;;;;;GAchB,MAAA,CAAO,QAAA,KAAa,gBAAA,UAA0B,CAAA;;;;;;;EAgBhD,MAAA,CAAO,GAAA;;;;MAYH,IAAA,CAAA;;;;;MAQA,WAAA,CAAA;AAAA"}
|
package/dist/lru-cache.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lru-cache.d.mts","names":[],"sources":["../src/lru-cache.ts"],"
|
|
1
|
+
{"version":3,"file":"lru-cache.d.mts","names":[],"sources":["../src/lru-cache.ts"],"mappings":";;AAgEA;;;;;;;;;;;;;;;;;cAAa,QAAA;EAAA,iBACM,KAAA;EAAA,iBAEA,IAAA;EAAA,iBAEA,IAAA;EAAA,QAET,SAAA;EAAA,iBAES,OAAA;EAAA,iBAEA,aAAA;cAEL,OAAA,UAAiB,aAAA,IAAiB,KAAA,EAAO,CAAA;EAyC7C;;;;;EAAA,QAxBA,SAAA;EAyFD;;;;;EAAA,QA5EC,UAAA;EAoGQ;;;;;EAAA,QAzFR,UAAA;EA6HG;;;;;EAAA,QAnHH,UAAA;;;;;;;;;;;;;EAmBD,GAAA,CAAI,GAAA,UAAa,KAAA,EAAO,CAAA;;;;;;;EAoCxB,GAAA,CAAI,GAAA;;;;;;;EAUJ,GAAA,CAAI,GAAA,WAAc,CAAA;;;;;GAchB,MAAA,CAAO,QAAA,KAAa,gBAAA,UAA0B,CAAA;;;;;;;EAgBhD,MAAA,CAAO,GAAA;;;;MAYH,IAAA,CAAA;;;;;MAQA,WAAA,CAAA;AAAA"}
|
package/dist/match-sorter.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match-sorter.d.cts","names":[],"sources":["../src/match-sorter.ts"],"
|
|
1
|
+
{"version":3,"file":"match-sorter.d.cts","names":[],"sources":["../src/match-sorter.ts"],"mappings":";;;;UAwBU,aAAA;EACR,SAAA,GAAY,OAAA;EACZ,UAAA,EAAY,OAAA;EACZ,UAAA,EAAY,OAAA;AAAA;AAAA,UAEJ,WAAA;EACR,WAAA;EACA,IAAA,EAAM,OAAA;EACN,QAAA;EACA,YAAA,EAAc,OAAA;AAAA;AAAA,UAGN,cAAA;EAAA,CACP,IAAA,EAAM,QAAA,YAAoB,KAAA;AAAA;AAAA,UAEnB,WAAA;EACR,IAAA,EAAM,QAAA;EACN,KAAA;AAAA;AAAA,UAEQ,UAAA,mBAA6B,WAAA,EAAa,WAAA,CAAY,QAAA;AAAA,UAEtD,UAAA;EAAA,CACP,CAAA,EAAG,UAAA,CAAW,QAAA,GAAW,CAAA,EAAG,UAAA,CAAW,QAAA;AAAA;AAAA,UAGhC,MAAA;EAAA,CACP,UAAA,EAAY,KAAA,CAAM,UAAA,CAAW,QAAA,KAAa,KAAA,CAAM,UAAA,CAAW,QAAA;AAAA;AAAA,UAGpD,oBAAA;EACR,GAAA,YAAe,cAAA,CAAe,QAAA;EAC9B,SAAA,GAAY,OAAA;EACZ,UAAA,GAAa,OAAA;EACb,UAAA,GAAa,OAAA;AAAA;AAAA,KAGV,SAAA,aACD,oBAAA,CAAqB,QAAA,IACrB,cAAA,CAAe,QAAA;AAAA,UAGT,kBAAA;EACR,IAAA,GAAO,aAAA,CAAc,SAAA,CAAU,QAAA;EAC/B,SAAA,GAAY,OAAA;EACZ,QAAA,GAAW,UAAA,CAAW,QAAA;EACtB,cAAA;EACA,MAAA,GAAS,MAAA,CAAO,QAAA;AAAA;AAAA,cAIZ,QAAA;EAAA;;;;;;;;;KAWD,OAAA,WAAkB,QAAA,eAAuB,QAAA;AAAA,cAExC,iBAAA,EAAmB,UAAA;;;;;;;;iBAUhB,WAAA,mBAAA,CACP,KAAA,EAAO,aAAA,CAAc,QAAA,GACrB,KAAA,UACA,OAAA,GAAS,kBAAA,CAAmB,QAAA,IAC3B,KAAA,CAAM,QAAA;AAAA,kBAJA,WAAA;EAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match-sorter.d.mts","names":[],"sources":["../src/match-sorter.ts"],"
|
|
1
|
+
{"version":3,"file":"match-sorter.d.mts","names":[],"sources":["../src/match-sorter.ts"],"mappings":";;;;UAwBU,aAAA;EACR,SAAA,GAAY,OAAA;EACZ,UAAA,EAAY,OAAA;EACZ,UAAA,EAAY,OAAA;AAAA;AAAA,UAEJ,WAAA;EACR,WAAA;EACA,IAAA,EAAM,OAAA;EACN,QAAA;EACA,YAAA,EAAc,OAAA;AAAA;AAAA,UAGN,cAAA;EAAA,CACP,IAAA,EAAM,QAAA,YAAoB,KAAA;AAAA;AAAA,UAEnB,WAAA;EACR,IAAA,EAAM,QAAA;EACN,KAAA;AAAA;AAAA,UAEQ,UAAA,mBAA6B,WAAA,EAAa,WAAA,CAAY,QAAA;AAAA,UAEtD,UAAA;EAAA,CACP,CAAA,EAAG,UAAA,CAAW,QAAA,GAAW,CAAA,EAAG,UAAA,CAAW,QAAA;AAAA;AAAA,UAGhC,MAAA;EAAA,CACP,UAAA,EAAY,KAAA,CAAM,UAAA,CAAW,QAAA,KAAa,KAAA,CAAM,UAAA,CAAW,QAAA;AAAA;AAAA,UAGpD,oBAAA;EACR,GAAA,YAAe,cAAA,CAAe,QAAA;EAC9B,SAAA,GAAY,OAAA;EACZ,UAAA,GAAa,OAAA;EACb,UAAA,GAAa,OAAA;AAAA;AAAA,KAGV,SAAA,aACD,oBAAA,CAAqB,QAAA,IACrB,cAAA,CAAe,QAAA;AAAA,UAGT,kBAAA;EACR,IAAA,GAAO,aAAA,CAAc,SAAA,CAAU,QAAA;EAC/B,SAAA,GAAY,OAAA;EACZ,QAAA,GAAW,UAAA,CAAW,QAAA;EACtB,cAAA;EACA,MAAA,GAAS,MAAA,CAAO,QAAA;AAAA;AAAA,cAIZ,QAAA;EAAA;;;;;;;;;KAWD,OAAA,WAAkB,QAAA,eAAuB,QAAA;AAAA,cAExC,iBAAA,EAAmB,UAAA;;;;;;;;iBAUhB,WAAA,mBAAA,CACP,KAAA,EAAO,aAAA,CAAc,QAAA,GACrB,KAAA,UACA,OAAA,GAAS,kBAAA,CAAmB,QAAA,IAC3B,KAAA,CAAM,QAAA;AAAA,kBAJA,WAAA;EAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match-sorter.mjs","names":["defaultBaseSortFn: BaseSorter<unknown>","value: string | Array<string> | null | unknown","values: ValueA","nestedValues: ValueA","allValues: Array<{ itemValue: string; attributes: KeyAttributes }>"],"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,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
+
{"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,YA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,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"}
|
package/dist/memoize.cjs
CHANGED
package/dist/memoize.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoize.d.cts","names":[],"sources":["../src/memoize.ts"],"
|
|
1
|
+
{"version":3,"file":"memoize.d.cts","names":[],"sources":["../src/memoize.ts"],"mappings":";;AAwBA;;;;;cAAa,WAAA,MAAkB,EAAA,GAAK,EAAA,aAAe,CAAA,MAAC,EAAA,aAKpB,CAAA"}
|
package/dist/memoize.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoize.d.mts","names":[],"sources":["../src/memoize.ts"],"
|
|
1
|
+
{"version":3,"file":"memoize.d.mts","names":[],"sources":["../src/memoize.ts"],"mappings":";;AAwBA;;;;;cAAa,WAAA,MAAkB,EAAA,GAAK,EAAA,aAAe,CAAA,MAAC,EAAA,aAKpB,CAAA"}
|
package/dist/memoize.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoize.mjs","names":[
|
|
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.cjs
CHANGED
package/dist/noop.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noop.d.cts","names":[],"sources":["../src/noop.ts"],"
|
|
1
|
+
{"version":3,"file":"noop.d.cts","names":[],"sources":["../src/noop.ts"],"mappings":";;AAyBA;;;;;AAWA;cAXa,IAAA,GAAQ,OAAA;;;;;;;;;;iBAWC,SAAA,CAAU,OAAA,aAAoB,OAAA"}
|
package/dist/noop.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noop.d.mts","names":[],"sources":["../src/noop.ts"],"
|
|
1
|
+
{"version":3,"file":"noop.d.mts","names":[],"sources":["../src/noop.ts"],"mappings":";;AAyBA;;;;;AAWA;cAXa,IAAA,GAAQ,OAAA;;;;;;;;;;iBAWC,SAAA,CAAU,OAAA,aAAoB,OAAA"}
|
package/dist/omit.cjs
CHANGED
package/dist/omit.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"omit.d.cts","names":[],"sources":["../src/omit.ts"],"
|
|
1
|
+
{"version":3,"file":"omit.d.cts","names":[],"sources":["../src/omit.ts"],"mappings":";;AAmCA;;;;;;;;;;;;;;;;iBAAgB,IAAA,WAAe,MAAA,+BAAqC,CAAA,CAAA,CAClE,GAAA,EAAK,CAAA,EACL,IAAA,WAAe,CAAA,KACd,IAAA,CAAK,CAAA,EAAG,CAAA"}
|
package/dist/omit.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"omit.d.mts","names":[],"sources":["../src/omit.ts"],"
|
|
1
|
+
{"version":3,"file":"omit.d.mts","names":[],"sources":["../src/omit.ts"],"mappings":";;AAmCA;;;;;;;;;;;;;;;;iBAAgB,IAAA,WAAe,MAAA,+BAAqC,CAAA,CAAA,CAClE,GAAA,EAAK,CAAA,EACL,IAAA,WAAe,CAAA,KACd,IAAA,CAAK,CAAA,EAAG,CAAA"}
|
package/dist/pick.cjs
CHANGED
package/dist/pick.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pick.d.cts","names":[],"sources":["../src/pick.ts"],"
|
|
1
|
+
{"version":3,"file":"pick.d.cts","names":[],"sources":["../src/pick.ts"],"mappings":";;AAmCA;;;;;;;;;;;;;;;;iBAAgB,IAAA,WAAe,MAAA,+BAAqC,CAAA,CAAA,CAClE,GAAA,EAAK,CAAA,EACL,IAAA,WAAe,CAAA,KACd,IAAA,CAAK,CAAA,EAAG,CAAA"}
|
package/dist/pick.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pick.d.mts","names":[],"sources":["../src/pick.ts"],"
|
|
1
|
+
{"version":3,"file":"pick.d.mts","names":[],"sources":["../src/pick.ts"],"mappings":";;AAmCA;;;;;;;;;;;;;;;;iBAAgB,IAAA,WAAe,MAAA,+BAAqC,CAAA,CAAA,CAClE,GAAA,EAAK,CAAA,EACL,IAAA,WAAe,CAAA,KACd,IAAA,CAAK,CAAA,EAAG,CAAA"}
|
package/dist/remove-accents.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-accents.d.cts","names":[],"sources":["../src/remove-accents.ts"],"
|
|
1
|
+
{"version":3,"file":"remove-accents.d.cts","names":[],"sources":["../src/remove-accents.ts"],"mappings":";cAkBa,YAAA,EAAc,MAAA;AAA3B;;;;;AAwZA;AAxZA,cAwZa,aAAA,GAAiB,GAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-accents.d.mts","names":[],"sources":["../src/remove-accents.ts"],"
|
|
1
|
+
{"version":3,"file":"remove-accents.d.mts","names":[],"sources":["../src/remove-accents.ts"],"mappings":";cAkBa,YAAA,EAAc,MAAA;AAA3B;;;;;AAwZA;AAxZA,cAwZa,aAAA,GAAiB,GAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-accents.mjs","names":["characterMap: Record<string, string>"],"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,MAAaA,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,GA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;CACH,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;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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ources":["../src/remove-empty-items.ts"],"
|
|
1
|
+
{"version":3,"file":"remove-empty-items.d.cts","names":[],"sources":["../src/remove-empty-items.ts"],"mappings":";;AAwBA;;;;;cAAa,gBAAA,YACX,GAAA,GAAM,CAAA,2BACL,WAAA,CAAY,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-empty-items.d.mts","names":[],"sources":["../src/remove-empty-items.ts"],"
|
|
1
|
+
{"version":3,"file":"remove-empty-items.d.mts","names":[],"sources":["../src/remove-empty-items.ts"],"mappings":";;AAwBA;;;;;cAAa,gBAAA,YACX,GAAA,GAAM,CAAA,2BACL,WAAA,CAAY,CAAA"}
|
package/dist/set-field.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
const require_is_object_index = require('./type-checks/src/is-object-index.cjs');
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
3
2
|
const require_to_path = require('./to-path.cjs');
|
|
3
|
+
let _stryke_type_checks_is_object_index = require("@stryke/type-checks/is-object-index");
|
|
4
|
+
let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
4
5
|
|
|
5
6
|
//#region src/set-field.ts
|
|
6
7
|
/**
|
|
@@ -12,13 +13,13 @@ const require_to_path = require('./to-path.cjs');
|
|
|
12
13
|
* @returns The object with the value set at the given deep path.
|
|
13
14
|
*/
|
|
14
15
|
function setField(object, path, value) {
|
|
15
|
-
const resolvedPath = Array.isArray(path) ? path :
|
|
16
|
+
const resolvedPath = Array.isArray(path) ? path : (0, _stryke_type_checks_is_string.isString)(path) ? require_to_path.toPath(path) : [path];
|
|
16
17
|
for (const key of resolvedPath) if (key === "__proto__" || key === "constructor" || key === "prototype") throw new Error(`Invalid key in path: ${key}`);
|
|
17
18
|
let current = object;
|
|
18
19
|
for (let i = 0; i < resolvedPath.length - 1; i++) {
|
|
19
20
|
const key = resolvedPath[i];
|
|
20
21
|
const nextKey = resolvedPath[i + 1];
|
|
21
|
-
if (current[key] === null) current[key] =
|
|
22
|
+
if (current[key] === null) current[key] = (0, _stryke_type_checks_is_object_index.isObjectIndex)(nextKey) ? [] : {};
|
|
22
23
|
current = current[key];
|
|
23
24
|
}
|
|
24
25
|
const lastKey = resolvedPath.at(-1);
|
package/dist/set-field.d.cts
CHANGED
package/dist/set-field.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-field.d.cts","names":[],"sources":["../src/set-field.ts"],"
|
|
1
|
+
{"version":3,"file":"set-field.d.cts","names":[],"sources":["../src/set-field.ts"],"mappings":";;;;;AA+BA;;;;;;iBAAgB,QAAA,iBACE,MAAA,gBAAsB,MAAA,cAAA,CACtC,MAAA,EAAQ,OAAA,EAAS,IAAA,EAAM,OAAA,CAAQ,OAAA,GAAU,KAAA,YAAiB,OAAA"}
|