@kikiutils/shared 10.2.1 → 10.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/buffer.cjs +43 -0
- package/dist/buffer.cjs.map +1 -0
- package/dist/buffer.d.ts +34 -0
- package/dist/buffer.d.ts.map +1 -0
- package/dist/buffer.mjs +41 -0
- package/dist/buffer.mjs.map +1 -0
- package/dist/clipboard.cjs +4 -4
- package/dist/clipboard.cjs.map +1 -1
- package/dist/clipboard.d.ts +3 -3
- package/dist/clipboard.mjs +4 -4
- package/dist/clipboard.mjs.map +1 -1
- package/dist/datetime.cjs +13 -13
- package/dist/datetime.cjs.map +1 -1
- package/dist/datetime.d.ts +12 -12
- package/dist/datetime.mjs +13 -13
- package/dist/datetime.mjs.map +1 -1
- package/dist/element-plus.cjs +6 -6
- package/dist/element-plus.cjs.map +1 -1
- package/dist/element-plus.d.ts +6 -6
- package/dist/element-plus.mjs +6 -6
- package/dist/element-plus.mjs.map +1 -1
- package/dist/enum.cjs +70 -25
- package/dist/enum.cjs.map +1 -1
- package/dist/enum.d.ts +61 -10
- package/dist/enum.d.ts.map +1 -1
- package/dist/enum.mjs +70 -26
- package/dist/enum.mjs.map +1 -1
- package/dist/env.cjs +4 -4
- package/dist/env.cjs.map +1 -1
- package/dist/env.d.ts +4 -4
- package/dist/env.mjs +4 -4
- package/dist/env.mjs.map +1 -1
- package/dist/general.cjs.map +1 -1
- package/dist/general.d.ts +5 -5
- package/dist/general.mjs.map +1 -1
- package/dist/math.cjs +4 -4
- package/dist/math.cjs.map +1 -1
- package/dist/math.d.ts +4 -4
- package/dist/math.mjs +4 -4
- package/dist/math.mjs.map +1 -1
- package/dist/number.cjs +3 -3
- package/dist/number.cjs.map +1 -1
- package/dist/number.d.ts +3 -3
- package/dist/number.mjs +3 -3
- package/dist/number.mjs.map +1 -1
- package/dist/object.cjs +4 -4
- package/dist/object.cjs.map +1 -1
- package/dist/object.d.ts +4 -4
- package/dist/object.mjs +4 -4
- package/dist/object.mjs.map +1 -1
- package/dist/random.cjs +7 -7
- package/dist/random.cjs.map +1 -1
- package/dist/random.d.ts +7 -7
- package/dist/random.mjs +7 -7
- package/dist/random.mjs.map +1 -1
- package/dist/storage/enhanced/local/core.cjs +11 -11
- package/dist/storage/enhanced/local/core.cjs.map +1 -1
- package/dist/storage/enhanced/local/core.d.ts +9 -9
- package/dist/storage/enhanced/local/core.mjs +11 -11
- package/dist/storage/enhanced/local/core.mjs.map +1 -1
- package/dist/storage/enhanced/local/keyed-store.cjs +3 -3
- package/dist/storage/enhanced/local/keyed-store.cjs.map +1 -1
- package/dist/storage/enhanced/local/keyed-store.d.ts +3 -3
- package/dist/storage/enhanced/local/keyed-store.mjs +3 -3
- package/dist/storage/enhanced/local/keyed-store.mjs.map +1 -1
- package/dist/storage/enhanced/redis/core.cjs +18 -18
- package/dist/storage/enhanced/redis/core.cjs.map +1 -1
- package/dist/storage/enhanced/redis/core.d.ts +16 -16
- package/dist/storage/enhanced/redis/core.mjs +18 -18
- package/dist/storage/enhanced/redis/core.mjs.map +1 -1
- package/dist/storage/enhanced/redis/keyed-store.cjs +4 -4
- package/dist/storage/enhanced/redis/keyed-store.cjs.map +1 -1
- package/dist/storage/enhanced/redis/keyed-store.d.ts +4 -4
- package/dist/storage/enhanced/redis/keyed-store.mjs +4 -4
- package/dist/storage/enhanced/redis/keyed-store.mjs.map +1 -1
- package/dist/storage/lru/keyed-store.cjs +3 -3
- package/dist/storage/lru/keyed-store.cjs.map +1 -1
- package/dist/storage/lru/keyed-store.d.ts +3 -3
- package/dist/storage/lru/keyed-store.mjs +3 -3
- package/dist/storage/lru/keyed-store.mjs.map +1 -1
- package/dist/string.cjs +5 -5
- package/dist/string.cjs.map +1 -1
- package/dist/string.d.ts +4 -4
- package/dist/string.mjs +5 -5
- package/dist/string.mjs.map +1 -1
- package/dist/url.cjs +3 -3
- package/dist/url.cjs.map +1 -1
- package/dist/url.d.ts +3 -3
- package/dist/url.mjs +3 -3
- package/dist/url.mjs.map +1 -1
- package/dist/vue.cjs +6 -6
- package/dist/vue.cjs.map +1 -1
- package/dist/vue.d.ts +6 -6
- package/dist/vue.mjs +6 -6
- package/dist/vue.mjs.map +1 -1
- package/dist/web.cjs +4 -4
- package/dist/web.cjs.map +1 -1
- package/dist/web.d.ts +4 -4
- package/dist/web.mjs +4 -4
- package/dist/web.mjs.map +1 -1
- package/package.json +9 -5
- package/src/buffer.ts +37 -0
- package/src/clipboard.ts +4 -4
- package/src/datetime.ts +13 -13
- package/src/element-plus.ts +6 -6
- package/src/enum.ts +68 -24
- package/src/env.ts +4 -4
- package/src/general.ts +5 -5
- package/src/math.ts +4 -4
- package/src/number.ts +3 -3
- package/src/object.ts +4 -4
- package/src/random.ts +7 -7
- package/src/storage/enhanced/local/core.ts +11 -11
- package/src/storage/enhanced/local/keyed-store.ts +3 -3
- package/src/storage/enhanced/redis/core.ts +18 -18
- package/src/storage/enhanced/redis/keyed-store.ts +4 -4
- package/src/storage/lru/keyed-store.ts +3 -3
- package/src/string.ts +5 -5
- package/src/url.ts +3 -3
- package/src/vue.ts +6 -6
- package/src/web.ts +4 -4
package/dist/math.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.mjs","sources":["../src/math.ts"],"sourcesContent":["import { Decimal } from 'decimal.js';\n\ntype CalculableValue = Decimal.Value | { toString: () => string };\n\n/**\n * Options for configuring the output of `toPercentageString`.\n */\nexport interface ToPercentageStringOptions {\n /**\n * Number of decimal places to include in the result.\n *\n * @default 2\n */\n decimalPlaces?: number;\n\n /**\n * Whether to include the '%' symbol in the result.\n *\n * @default true\n */\n withSymbol?: boolean;\n}\n\n/**\n * Converts a fraction (numerator / denominator) into a percentage string.\n *\n * - Uses `decimal.js` for precise decimal calculations.\n * - Supports custom decimal places and optional percentage symbol.\n * - Returns `'0.00%'` if result is `NaN` or division is invalid.\n *\n * @param {CalculableValue} molecular - The numerator of the fraction
|
|
1
|
+
{"version":3,"file":"math.mjs","sources":["../src/math.ts"],"sourcesContent":["import { Decimal } from 'decimal.js';\n\ntype CalculableValue = Decimal.Value | { toString: () => string };\n\n/**\n * Options for configuring the output of `toPercentageString`.\n */\nexport interface ToPercentageStringOptions {\n /**\n * Number of decimal places to include in the result.\n *\n * @default 2\n */\n decimalPlaces?: number;\n\n /**\n * Whether to include the '%' symbol in the result.\n *\n * @default true\n */\n withSymbol?: boolean;\n}\n\n/**\n * Converts a fraction (numerator / denominator) into a percentage string.\n *\n * - Uses `decimal.js` for precise decimal calculations.\n * - Supports custom decimal places and optional percentage symbol.\n * - Returns `'0.00%'` if result is `NaN` or division is invalid.\n *\n * @param {CalculableValue} molecular - The numerator of the fraction\n * @param {CalculableValue} denominator - The denominator of the fraction\n * @param {ToPercentageStringOptions} [options] - Optional output settings\n *\n * @returns {string} Formatted percentage string\n *\n * @example\n * ```typescript\n * import { toPercentageString } from '@kikiutils/shared/math';\n *\n * console.log(toPercentageString(50, 200)); // 25.00%\n * console.log(toPercentageString(50, 200, { withSymbol: false })); // 25.00\n * console.log(toPercentageString(50, 200, { decimalPlaces: 1 })); // 25.0%\n * ```\n */\nexport function toPercentageString(\n molecular: CalculableValue,\n denominator: CalculableValue,\n options?: ToPercentageStringOptions,\n) {\n const molecularDecimal = new Decimal(molecular.toString());\n const denominatorDecimal = new Decimal(denominator.toString());\n const calculationResult = molecularDecimal.div(denominatorDecimal);\n const result = calculationResult.isNaN()\n ? '0.00'\n : calculationResult.times(100).toFixed(options?.decimalPlaces ?? 2);\n\n return options?.withSymbol ?? true ? `${result}%` : result;\n}\n"],"names":[],"mappings":";;AAuBA;;;;;;;;;;;;;;;;;;;;;AAqBG;SACa,kBAAkB,CAC9B,SAA0B,EAC1B,WAA4B,EAC5B,OAAmC,EAAA;IAEnC,MAAM,gBAAgB,GAAG,IAAI,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC1D,MAAM,kBAAkB,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;IAC9D,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,GAAG,CAAC,kBAAkB,CAAC;AAClE,IAAA,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK;AAClC,UAAE;AACF,UAAE,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,aAAa,IAAI,CAAC,CAAC;AAEvE,IAAA,OAAO,OAAO,EAAE,UAAU,IAAI,IAAI,GAAG,CAAA,EAAG,MAAM,CAAA,CAAA,CAAG,GAAG,MAAM;AAC9D;;;;"}
|
package/dist/number.cjs
CHANGED
|
@@ -7,10 +7,10 @@ const millify = require('millify');
|
|
|
7
7
|
*
|
|
8
8
|
* Applies lowercase units (e.g. 'k', 'm') and default precision of 2, unless overridden.
|
|
9
9
|
*
|
|
10
|
-
* @param {number} value - The number to format
|
|
11
|
-
* @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify
|
|
10
|
+
* @param {number} value - The number to format
|
|
11
|
+
* @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify`
|
|
12
12
|
*
|
|
13
|
-
* @returns {string} The compact number string
|
|
13
|
+
* @returns {string} The compact number string
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```typescript
|
package/dist/number.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.cjs","sources":["../src/number.ts"],"sourcesContent":["import { millify } from 'millify';\n\n/**\n * Converts a large number into a compact, human-readable string using `millify`.\n *\n * Applies lowercase units (e.g. 'k', 'm') and default precision of 2, unless overridden.\n *\n * @param {number} value - The number to format
|
|
1
|
+
{"version":3,"file":"number.cjs","sources":["../src/number.ts"],"sourcesContent":["import { millify } from 'millify';\n\n/**\n * Converts a large number into a compact, human-readable string using `millify`.\n *\n * Applies lowercase units (e.g. 'k', 'm') and default precision of 2, unless overridden.\n *\n * @param {number} value - The number to format\n * @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify`\n *\n * @returns {string} The compact number string\n *\n * @example\n * ```typescript\n * import { toCompactNumberString } from '@kikiutils/shared/number';\n *\n * console.log(toCompactNumberString(1234567)); // 1.23m\n * console.log(toCompactNumberString(1234567, { precision: 3 })); // 1.235m\n * ```\n */\nexport function toCompactNumberString(value: number, options?: Parameters<typeof millify>[1]) {\n return millify(\n value,\n {\n lowercase: true,\n precision: 2,\n ...options,\n },\n );\n}\n"],"names":["millify"],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;AAiBG;AACG,SAAU,qBAAqB,CAAC,KAAa,EAAE,OAAuC,EAAA;IACxF,OAAOA,eAAO,CACV,KAAK,EACL;AACI,QAAA,SAAS,EAAE,IAAI;AACf,QAAA,SAAS,EAAE,CAAC;AACZ,QAAA,GAAG,OAAO;AACb,KAAA,CACJ;AACL;;;;"}
|
package/dist/number.d.ts
CHANGED
|
@@ -4,10 +4,10 @@ import { millify } from 'millify';
|
|
|
4
4
|
*
|
|
5
5
|
* Applies lowercase units (e.g. 'k', 'm') and default precision of 2, unless overridden.
|
|
6
6
|
*
|
|
7
|
-
* @param {number} value - The number to format
|
|
8
|
-
* @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify
|
|
7
|
+
* @param {number} value - The number to format
|
|
8
|
+
* @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify`
|
|
9
9
|
*
|
|
10
|
-
* @returns {string} The compact number string
|
|
10
|
+
* @returns {string} The compact number string
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```typescript
|
package/dist/number.mjs
CHANGED
|
@@ -5,10 +5,10 @@ import { millify } from 'millify';
|
|
|
5
5
|
*
|
|
6
6
|
* Applies lowercase units (e.g. 'k', 'm') and default precision of 2, unless overridden.
|
|
7
7
|
*
|
|
8
|
-
* @param {number} value - The number to format
|
|
9
|
-
* @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify
|
|
8
|
+
* @param {number} value - The number to format
|
|
9
|
+
* @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify`
|
|
10
10
|
*
|
|
11
|
-
* @returns {string} The compact number string
|
|
11
|
+
* @returns {string} The compact number string
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```typescript
|
package/dist/number.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.mjs","sources":["../src/number.ts"],"sourcesContent":["import { millify } from 'millify';\n\n/**\n * Converts a large number into a compact, human-readable string using `millify`.\n *\n * Applies lowercase units (e.g. 'k', 'm') and default precision of 2, unless overridden.\n *\n * @param {number} value - The number to format
|
|
1
|
+
{"version":3,"file":"number.mjs","sources":["../src/number.ts"],"sourcesContent":["import { millify } from 'millify';\n\n/**\n * Converts a large number into a compact, human-readable string using `millify`.\n *\n * Applies lowercase units (e.g. 'k', 'm') and default precision of 2, unless overridden.\n *\n * @param {number} value - The number to format\n * @param {Parameters<typeof millify>[1]} [options] - Optional configuration passed to `millify`\n *\n * @returns {string} The compact number string\n *\n * @example\n * ```typescript\n * import { toCompactNumberString } from '@kikiutils/shared/number';\n *\n * console.log(toCompactNumberString(1234567)); // 1.23m\n * console.log(toCompactNumberString(1234567, { precision: 3 })); // 1.235m\n * ```\n */\nexport function toCompactNumberString(value: number, options?: Parameters<typeof millify>[1]) {\n return millify(\n value,\n {\n lowercase: true,\n precision: 2,\n ...options,\n },\n );\n}\n"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;AAiBG;AACG,SAAU,qBAAqB,CAAC,KAAa,EAAE,OAAuC,EAAA;IACxF,OAAO,OAAO,CACV,KAAK,EACL;AACI,QAAA,SAAS,EAAE,IAAI;AACf,QAAA,SAAS,EAAE,CAAC;AACZ,QAAA,GAAG,OAAO;AACb,KAAA,CACJ;AACL;;;;"}
|
package/dist/object.cjs
CHANGED
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
* It is designed for use cases such as signature generation, cache key construction,
|
|
11
11
|
* or any context requiring consistent and predictable object serialization.
|
|
12
12
|
*
|
|
13
|
-
* @param {Record<string, any>} input - The object to serialize. Can contain nested objects and arrays
|
|
14
|
-
* @param {string} kvSeparator - The string used to separate each key from its value (default: '=')
|
|
15
|
-
* @param {string} pairSeparator - The string used to separate each key-value pair (default: '&')
|
|
16
|
-
* @returns {string} A deterministic string representation of the input object
|
|
13
|
+
* @param {Record<string, any>} input - The object to serialize. Can contain nested objects and arrays
|
|
14
|
+
* @param {string} kvSeparator - The string used to separate each key from its value (default: '=')
|
|
15
|
+
* @param {string} pairSeparator - The string used to separate each key-value pair (default: '&')
|
|
16
|
+
* @returns {string} A deterministic string representation of the input object
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* ```typescript
|
package/dist/object.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.cjs","sources":["../src/object.ts"],"sourcesContent":["/**\n * Serializes a nested object into a deterministic, flat string format.\n *\n * This function recursively traverses the input object (including nested objects and arrays),\n * flattens it into key paths using dot notation (e.g. \"a.b.0.c\"), sorts all keys,\n * and joins each key-value pair into a string with customizable separators.\n *\n * It is designed for use cases such as signature generation, cache key construction,\n * or any context requiring consistent and predictable object serialization.\n *\n * @param {Record<string, any>} input - The object to serialize. Can contain nested objects and arrays
|
|
1
|
+
{"version":3,"file":"object.cjs","sources":["../src/object.ts"],"sourcesContent":["/**\n * Serializes a nested object into a deterministic, flat string format.\n *\n * This function recursively traverses the input object (including nested objects and arrays),\n * flattens it into key paths using dot notation (e.g. \"a.b.0.c\"), sorts all keys,\n * and joins each key-value pair into a string with customizable separators.\n *\n * It is designed for use cases such as signature generation, cache key construction,\n * or any context requiring consistent and predictable object serialization.\n *\n * @param {Record<string, any>} input - The object to serialize. Can contain nested objects and arrays\n * @param {string} kvSeparator - The string used to separate each key from its value (default: '=')\n * @param {string} pairSeparator - The string used to separate each key-value pair (default: '&')\n * @returns {string} A deterministic string representation of the input object\n *\n * @example\n * ```typescript\n * import { stringifyObjectDeterministically } from '@kikiutils/shared/object';\n *\n * console.log(stringifyObjectDeterministically({ b: 2, a: { x: 1, y: [3, 4] } })); // a.x=1&a.y.0=3&a.y.1=4&b=2\n * console.log(stringifyObjectDeterministically({ foo: 'bar' }, ':', '|')); // foo:bar\n * ```\n */\nexport function stringifyObjectDeterministically(\n input: Record<string, any>,\n kvSeparator: string = '=',\n pairSeparator: string = '&',\n) {\n const entries: string[] = [];\n\n function walk(object: any, path: string[] = []) {\n if (Array.isArray(object)) {\n object.forEach((value, index) => {\n walk(\n value,\n [\n ...path,\n index.toString(),\n ],\n );\n });\n } else if (\n object !== null\n && typeof object === 'object'\n && Object.prototype.toString.call(object) === '[object Object]'\n ) {\n Object.keys(object).sort().forEach((key) => {\n walk(\n object[key],\n [\n ...path,\n key,\n ],\n );\n });\n } else entries.push(`${path.join('.')}${kvSeparator}${String(object)}`);\n }\n\n walk(input);\n return entries.sort().join(pairSeparator);\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;;;;;;;;;AAsBG;AACG,SAAU,gCAAgC,CAC5C,KAA0B,EAC1B,WAAA,GAAsB,GAAG,EACzB,aAAA,GAAwB,GAAG,EAAA;IAE3B,MAAM,OAAO,GAAa,EAAE;AAE5B,IAAA,SAAS,IAAI,CAAC,MAAW,EAAE,OAAiB,EAAE,EAAA;AAC1C,QAAA,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACvB,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,KAAI;gBAC5B,IAAI,CACA,KAAK,EACL;AACI,oBAAA,GAAG,IAAI;oBACP,KAAK,CAAC,QAAQ,EAAE;AACnB,iBAAA,CACJ;AACL,YAAA,CAAC,CAAC;QACN;aAAO,IACH,MAAM,KAAK;eACR,OAAO,MAAM,KAAK;AAClB,eAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,iBAAiB,EACjE;AACE,YAAA,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,CAAC,GAAG,KAAI;AACvC,gBAAA,IAAI,CACA,MAAM,CAAC,GAAG,CAAC,EACX;AACI,oBAAA,GAAG,IAAI;oBACP,GAAG;AACN,iBAAA,CACJ;AACL,YAAA,CAAC,CAAC;QACN;;AAAO,YAAA,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA,EAAG,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA,CAAE,CAAC;IAC3E;IAEA,IAAI,CAAC,KAAK,CAAC;IACX,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC;AAC7C;;;;"}
|
package/dist/object.d.ts
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
* It is designed for use cases such as signature generation, cache key construction,
|
|
9
9
|
* or any context requiring consistent and predictable object serialization.
|
|
10
10
|
*
|
|
11
|
-
* @param {Record<string, any>} input - The object to serialize. Can contain nested objects and arrays
|
|
12
|
-
* @param {string} kvSeparator - The string used to separate each key from its value (default: '=')
|
|
13
|
-
* @param {string} pairSeparator - The string used to separate each key-value pair (default: '&')
|
|
14
|
-
* @returns {string} A deterministic string representation of the input object
|
|
11
|
+
* @param {Record<string, any>} input - The object to serialize. Can contain nested objects and arrays
|
|
12
|
+
* @param {string} kvSeparator - The string used to separate each key from its value (default: '=')
|
|
13
|
+
* @param {string} pairSeparator - The string used to separate each key-value pair (default: '&')
|
|
14
|
+
* @returns {string} A deterministic string representation of the input object
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```typescript
|
package/dist/object.mjs
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
* It is designed for use cases such as signature generation, cache key construction,
|
|
9
9
|
* or any context requiring consistent and predictable object serialization.
|
|
10
10
|
*
|
|
11
|
-
* @param {Record<string, any>} input - The object to serialize. Can contain nested objects and arrays
|
|
12
|
-
* @param {string} kvSeparator - The string used to separate each key from its value (default: '=')
|
|
13
|
-
* @param {string} pairSeparator - The string used to separate each key-value pair (default: '&')
|
|
14
|
-
* @returns {string} A deterministic string representation of the input object
|
|
11
|
+
* @param {Record<string, any>} input - The object to serialize. Can contain nested objects and arrays
|
|
12
|
+
* @param {string} kvSeparator - The string used to separate each key from its value (default: '=')
|
|
13
|
+
* @param {string} pairSeparator - The string used to separate each key-value pair (default: '&')
|
|
14
|
+
* @returns {string} A deterministic string representation of the input object
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```typescript
|
package/dist/object.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.mjs","sources":["../src/object.ts"],"sourcesContent":["/**\n * Serializes a nested object into a deterministic, flat string format.\n *\n * This function recursively traverses the input object (including nested objects and arrays),\n * flattens it into key paths using dot notation (e.g. \"a.b.0.c\"), sorts all keys,\n * and joins each key-value pair into a string with customizable separators.\n *\n * It is designed for use cases such as signature generation, cache key construction,\n * or any context requiring consistent and predictable object serialization.\n *\n * @param {Record<string, any>} input - The object to serialize. Can contain nested objects and arrays
|
|
1
|
+
{"version":3,"file":"object.mjs","sources":["../src/object.ts"],"sourcesContent":["/**\n * Serializes a nested object into a deterministic, flat string format.\n *\n * This function recursively traverses the input object (including nested objects and arrays),\n * flattens it into key paths using dot notation (e.g. \"a.b.0.c\"), sorts all keys,\n * and joins each key-value pair into a string with customizable separators.\n *\n * It is designed for use cases such as signature generation, cache key construction,\n * or any context requiring consistent and predictable object serialization.\n *\n * @param {Record<string, any>} input - The object to serialize. Can contain nested objects and arrays\n * @param {string} kvSeparator - The string used to separate each key from its value (default: '=')\n * @param {string} pairSeparator - The string used to separate each key-value pair (default: '&')\n * @returns {string} A deterministic string representation of the input object\n *\n * @example\n * ```typescript\n * import { stringifyObjectDeterministically } from '@kikiutils/shared/object';\n *\n * console.log(stringifyObjectDeterministically({ b: 2, a: { x: 1, y: [3, 4] } })); // a.x=1&a.y.0=3&a.y.1=4&b=2\n * console.log(stringifyObjectDeterministically({ foo: 'bar' }, ':', '|')); // foo:bar\n * ```\n */\nexport function stringifyObjectDeterministically(\n input: Record<string, any>,\n kvSeparator: string = '=',\n pairSeparator: string = '&',\n) {\n const entries: string[] = [];\n\n function walk(object: any, path: string[] = []) {\n if (Array.isArray(object)) {\n object.forEach((value, index) => {\n walk(\n value,\n [\n ...path,\n index.toString(),\n ],\n );\n });\n } else if (\n object !== null\n && typeof object === 'object'\n && Object.prototype.toString.call(object) === '[object Object]'\n ) {\n Object.keys(object).sort().forEach((key) => {\n walk(\n object[key],\n [\n ...path,\n key,\n ],\n );\n });\n } else entries.push(`${path.join('.')}${kvSeparator}${String(object)}`);\n }\n\n walk(input);\n return entries.sort().join(pairSeparator);\n}\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;AAsBG;AACG,SAAU,gCAAgC,CAC5C,KAA0B,EAC1B,WAAA,GAAsB,GAAG,EACzB,aAAA,GAAwB,GAAG,EAAA;IAE3B,MAAM,OAAO,GAAa,EAAE;AAE5B,IAAA,SAAS,IAAI,CAAC,MAAW,EAAE,OAAiB,EAAE,EAAA;AAC1C,QAAA,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACvB,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,KAAI;gBAC5B,IAAI,CACA,KAAK,EACL;AACI,oBAAA,GAAG,IAAI;oBACP,KAAK,CAAC,QAAQ,EAAE;AACnB,iBAAA,CACJ;AACL,YAAA,CAAC,CAAC;QACN;aAAO,IACH,MAAM,KAAK;eACR,OAAO,MAAM,KAAK;AAClB,eAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,iBAAiB,EACjE;AACE,YAAA,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,CAAC,GAAG,KAAI;AACvC,gBAAA,IAAI,CACA,MAAM,CAAC,GAAG,CAAC,EACX;AACI,oBAAA,GAAG,IAAI;oBACP,GAAG;AACN,iBAAA,CACJ;AACL,YAAA,CAAC,CAAC;QACN;;AAAO,YAAA,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA,EAAG,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA,CAAE,CAAC;IAC3E;IAEA,IAAI,CAAC,KAAK,CAAC;IACX,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC;AAC7C;;;;"}
|
package/dist/random.cjs
CHANGED
|
@@ -10,15 +10,15 @@
|
|
|
10
10
|
*
|
|
11
11
|
* This function supports any return type by using a generic type parameter.
|
|
12
12
|
*
|
|
13
|
-
* @template T - The return type of the generator function
|
|
13
|
+
* @template T - The return type of the generator function
|
|
14
14
|
*
|
|
15
|
-
* @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T
|
|
16
|
-
* @param {number} minMin - Lower bound of the first random range
|
|
17
|
-
* @param {number} minMax - Upper bound of the first random range
|
|
18
|
-
* @param {number} maxMin - Lower bound of the second random range
|
|
19
|
-
* @param {number} maxMax - Upper bound of the second random range
|
|
15
|
+
* @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T
|
|
16
|
+
* @param {number} minMin - Lower bound of the first random range
|
|
17
|
+
* @param {number} minMax - Upper bound of the first random range
|
|
18
|
+
* @param {number} maxMin - Lower bound of the second random range
|
|
19
|
+
* @param {number} maxMax - Upper bound of the second random range
|
|
20
20
|
*
|
|
21
|
-
* @returns {T} The result of the generator function using the computed final length
|
|
21
|
+
* @returns {T} The result of the generator function using the computed final length
|
|
22
22
|
*/
|
|
23
23
|
function generateWithNestedRandomLength(generator, minMin, minMax, maxMin, maxMax) {
|
|
24
24
|
const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
|
package/dist/random.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.cjs","sources":["../src/random.ts"],"sourcesContent":["/**\n * Generates a value using a provided generator function, where the input length\n * is determined by two levels of nested random ranges:\n *\n * 1. First, a random number (`innerMin`) is chosen between `minMin` and `minMax`.\n * 2. Then, a final length is chosen between `Math.max(innerMin, maxMin)` and `maxMax`.\n * 3. The generator is called with the final length and its result is returned.\n *\n * This function supports any return type by using a generic type parameter.\n *\n * @template T - The return type of the generator function
|
|
1
|
+
{"version":3,"file":"random.cjs","sources":["../src/random.ts"],"sourcesContent":["/**\n * Generates a value using a provided generator function, where the input length\n * is determined by two levels of nested random ranges:\n *\n * 1. First, a random number (`innerMin`) is chosen between `minMin` and `minMax`.\n * 2. Then, a final length is chosen between `Math.max(innerMin, maxMin)` and `maxMax`.\n * 3. The generator is called with the final length and its result is returned.\n *\n * This function supports any return type by using a generic type parameter.\n *\n * @template T - The return type of the generator function\n *\n * @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T\n * @param {number} minMin - Lower bound of the first random range\n * @param {number} minMax - Upper bound of the first random range\n * @param {number} maxMin - Lower bound of the second random range\n * @param {number} maxMax - Upper bound of the second random range\n *\n * @returns {T} The result of the generator function using the computed final length\n */\nexport function generateWithNestedRandomLength<T = string>(\n generator: (length: number) => T,\n minMin: number,\n minMax: number,\n maxMin: number,\n maxMax: number,\n) {\n const random = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min;\n const innerMin = random(minMin, minMax);\n const finalLength = random(Math.max(innerMin, maxMin), maxMax);\n return generator(finalLength);\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;;;;;;AAmBG;AACG,SAAU,8BAA8B,CAC1C,SAAgC,EAChC,MAAc,EACd,MAAc,EACd,MAAc,EACd,MAAc,EAAA;AAEd,IAAA,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,GAAW,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG;IAC9F,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;AACvC,IAAA,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC;AAC9D,IAAA,OAAO,SAAS,CAAC,WAAW,CAAC;AACjC;;;;"}
|
package/dist/random.d.ts
CHANGED
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
*
|
|
9
9
|
* This function supports any return type by using a generic type parameter.
|
|
10
10
|
*
|
|
11
|
-
* @template T - The return type of the generator function
|
|
11
|
+
* @template T - The return type of the generator function
|
|
12
12
|
*
|
|
13
|
-
* @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T
|
|
14
|
-
* @param {number} minMin - Lower bound of the first random range
|
|
15
|
-
* @param {number} minMax - Upper bound of the first random range
|
|
16
|
-
* @param {number} maxMin - Lower bound of the second random range
|
|
17
|
-
* @param {number} maxMax - Upper bound of the second random range
|
|
13
|
+
* @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T
|
|
14
|
+
* @param {number} minMin - Lower bound of the first random range
|
|
15
|
+
* @param {number} minMax - Upper bound of the first random range
|
|
16
|
+
* @param {number} maxMin - Lower bound of the second random range
|
|
17
|
+
* @param {number} maxMax - Upper bound of the second random range
|
|
18
18
|
*
|
|
19
|
-
* @returns {T} The result of the generator function using the computed final length
|
|
19
|
+
* @returns {T} The result of the generator function using the computed final length
|
|
20
20
|
*/
|
|
21
21
|
export declare function generateWithNestedRandomLength<T = string>(generator: (length: number) => T, minMin: number, minMax: number, maxMin: number, maxMax: number): T;
|
|
22
22
|
//# sourceMappingURL=random.d.ts.map
|
package/dist/random.mjs
CHANGED
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
*
|
|
9
9
|
* This function supports any return type by using a generic type parameter.
|
|
10
10
|
*
|
|
11
|
-
* @template T - The return type of the generator function
|
|
11
|
+
* @template T - The return type of the generator function
|
|
12
12
|
*
|
|
13
|
-
* @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T
|
|
14
|
-
* @param {number} minMin - Lower bound of the first random range
|
|
15
|
-
* @param {number} minMax - Upper bound of the first random range
|
|
16
|
-
* @param {number} maxMin - Lower bound of the second random range
|
|
17
|
-
* @param {number} maxMax - Upper bound of the second random range
|
|
13
|
+
* @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T
|
|
14
|
+
* @param {number} minMin - Lower bound of the first random range
|
|
15
|
+
* @param {number} minMax - Upper bound of the first random range
|
|
16
|
+
* @param {number} maxMin - Lower bound of the second random range
|
|
17
|
+
* @param {number} maxMax - Upper bound of the second random range
|
|
18
18
|
*
|
|
19
|
-
* @returns {T} The result of the generator function using the computed final length
|
|
19
|
+
* @returns {T} The result of the generator function using the computed final length
|
|
20
20
|
*/
|
|
21
21
|
function generateWithNestedRandomLength(generator, minMin, minMax, maxMin, maxMax) {
|
|
22
22
|
const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
|
package/dist/random.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.mjs","sources":["../src/random.ts"],"sourcesContent":["/**\n * Generates a value using a provided generator function, where the input length\n * is determined by two levels of nested random ranges:\n *\n * 1. First, a random number (`innerMin`) is chosen between `minMin` and `minMax`.\n * 2. Then, a final length is chosen between `Math.max(innerMin, maxMin)` and `maxMax`.\n * 3. The generator is called with the final length and its result is returned.\n *\n * This function supports any return type by using a generic type parameter.\n *\n * @template T - The return type of the generator function
|
|
1
|
+
{"version":3,"file":"random.mjs","sources":["../src/random.ts"],"sourcesContent":["/**\n * Generates a value using a provided generator function, where the input length\n * is determined by two levels of nested random ranges:\n *\n * 1. First, a random number (`innerMin`) is chosen between `minMin` and `minMax`.\n * 2. Then, a final length is chosen between `Math.max(innerMin, maxMin)` and `maxMax`.\n * 3. The generator is called with the final length and its result is returned.\n *\n * This function supports any return type by using a generic type parameter.\n *\n * @template T - The return type of the generator function\n *\n * @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T\n * @param {number} minMin - Lower bound of the first random range\n * @param {number} minMax - Upper bound of the first random range\n * @param {number} maxMin - Lower bound of the second random range\n * @param {number} maxMax - Upper bound of the second random range\n *\n * @returns {T} The result of the generator function using the computed final length\n */\nexport function generateWithNestedRandomLength<T = string>(\n generator: (length: number) => T,\n minMin: number,\n minMax: number,\n maxMin: number,\n maxMax: number,\n) {\n const random = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min;\n const innerMin = random(minMin, minMax);\n const finalLength = random(Math.max(innerMin, maxMin), maxMax);\n return generator(finalLength);\n}\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;AAmBG;AACG,SAAU,8BAA8B,CAC1C,SAAgC,EAChC,MAAc,EACd,MAAc,EACd,MAAc,EACd,MAAc,EAAA;AAEd,IAAA,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,GAAW,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG;IAC9F,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;AACvC,IAAA,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC;AAC9D,IAAA,OAAO,SAAS,CAAC,WAAW,CAAC;AACjC;;;;"}
|
|
@@ -32,11 +32,11 @@ const enhancedLocalStorage = Object.freeze({
|
|
|
32
32
|
/**
|
|
33
33
|
* Retrieves a value by key and decodes it using SuperJSON or raw string.
|
|
34
34
|
*
|
|
35
|
-
* @template T - The expected type of the value
|
|
35
|
+
* @template T - The expected type of the value
|
|
36
36
|
*
|
|
37
|
-
* @param {string} key - The key of the value to retrieve
|
|
37
|
+
* @param {string} key - The key of the value to retrieve
|
|
38
38
|
*
|
|
39
|
-
* @returns {null | T} The decoded value or null if not found
|
|
39
|
+
* @returns {null | T} The decoded value or null if not found
|
|
40
40
|
*/
|
|
41
41
|
getItem(key) {
|
|
42
42
|
const rawValue = window.localStorage.getItem(key);
|
|
@@ -45,15 +45,15 @@ const enhancedLocalStorage = Object.freeze({
|
|
|
45
45
|
/**
|
|
46
46
|
* Checks whether a key exists in localStorage.
|
|
47
47
|
*
|
|
48
|
-
* @param {string} key - The key to check
|
|
48
|
+
* @param {string} key - The key to check
|
|
49
49
|
*
|
|
50
|
-
* @returns {boolean} True if the key exists, false otherwise
|
|
50
|
+
* @returns {boolean} True if the key exists, false otherwise
|
|
51
51
|
*/
|
|
52
52
|
hasItem: (key) => window.localStorage.getItem(key) !== null,
|
|
53
53
|
/**
|
|
54
54
|
* Returns the number of items stored in localStorage.
|
|
55
55
|
*
|
|
56
|
-
* @returns {number} The number of items stored in localStorage
|
|
56
|
+
* @returns {number} The number of items stored in localStorage
|
|
57
57
|
*/
|
|
58
58
|
get length() {
|
|
59
59
|
return window.localStorage.length;
|
|
@@ -61,14 +61,14 @@ const enhancedLocalStorage = Object.freeze({
|
|
|
61
61
|
/**
|
|
62
62
|
* Removes a specific key from localStorage.
|
|
63
63
|
*
|
|
64
|
-
* @param {string} key - The key to remove
|
|
64
|
+
* @param {string} key - The key to remove
|
|
65
65
|
*/
|
|
66
66
|
removeItem: (key) => window.localStorage.removeItem(key),
|
|
67
67
|
/**
|
|
68
68
|
* Stores a value in localStorage with automatic serialization.
|
|
69
69
|
*
|
|
70
|
-
* @param {string} key - The key to store the value under
|
|
71
|
-
* @param {any} value - The value to store
|
|
70
|
+
* @param {string} key - The key to store the value under
|
|
71
|
+
* @param {any} value - The value to store
|
|
72
72
|
*/
|
|
73
73
|
setItem: (key, value) => window.localStorage.setItem(key, encodeToStorageValue(value)),
|
|
74
74
|
});
|
|
@@ -83,11 +83,11 @@ function decodeStorageValue(data) {
|
|
|
83
83
|
return superjson.deserialize(JSON.parse(payload));
|
|
84
84
|
}
|
|
85
85
|
catch {
|
|
86
|
-
throw new Error('[EnhancedLocalStorage] Failed to parse JSON payload
|
|
86
|
+
throw new Error('[EnhancedLocalStorage] Failed to parse JSON payload');
|
|
87
87
|
}
|
|
88
88
|
case StorageValueEncodingType.String: return payload;
|
|
89
89
|
default:
|
|
90
|
-
throw new Error(`[EnhancedLocalStorage] Unknown encoding type: ${type}
|
|
90
|
+
throw new Error(`[EnhancedLocalStorage] Unknown encoding type: ${type}`);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
function encodeToStorageValue(value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.cjs","sources":["../../../../src/storage/enhanced/local/core.ts"],"sourcesContent":["import {\n deserialize,\n serialize,\n} from 'superjson';\n\nenum StorageValueEncodingType {\n Json = '0',\n String = '1',\n}\n\nconst customValueHeader = '';\nconst customValueHeaderLength = customValueHeader.length + 1;\nconst toCustomValue = (type: StorageValueEncodingType, payload: string) => `${customValueHeader}${type}${payload}`;\n\n/**\n * An enhanced localStorage wrapper that supports storing\n * complex data types (e.g. Dates, Maps, Sets) using SuperJSON encoding.\n *\n * This utility preserves type structure when saving and retrieving values.\n *\n * @example\n * ```typescript\n * import { enhancedLocalStorage } from '@kikiutils/shared/storage/enhanced/local';\n *\n * enhancedLocalStorage.setItem('user', { name: 'user', createdAt: new Date() });\n * const user = enhancedLocalStorage.getItem<{ name: string, createdAt: Date }>('user');\n * ```\n */\nexport const enhancedLocalStorage = Object.freeze({\n /**\n * Removes all items from localStorage.\n */\n clear: () => window.localStorage.clear(),\n /**\n * Retrieves a value by key and decodes it using SuperJSON or raw string.\n *\n * @template T - The expected type of the value
|
|
1
|
+
{"version":3,"file":"core.cjs","sources":["../../../../src/storage/enhanced/local/core.ts"],"sourcesContent":["import {\n deserialize,\n serialize,\n} from 'superjson';\n\nenum StorageValueEncodingType {\n Json = '0',\n String = '1',\n}\n\nconst customValueHeader = '';\nconst customValueHeaderLength = customValueHeader.length + 1;\nconst toCustomValue = (type: StorageValueEncodingType, payload: string) => `${customValueHeader}${type}${payload}`;\n\n/**\n * An enhanced localStorage wrapper that supports storing\n * complex data types (e.g. Dates, Maps, Sets) using SuperJSON encoding.\n *\n * This utility preserves type structure when saving and retrieving values.\n *\n * @example\n * ```typescript\n * import { enhancedLocalStorage } from '@kikiutils/shared/storage/enhanced/local';\n *\n * enhancedLocalStorage.setItem('user', { name: 'user', createdAt: new Date() });\n * const user = enhancedLocalStorage.getItem<{ name: string, createdAt: Date }>('user');\n * ```\n */\nexport const enhancedLocalStorage = Object.freeze({\n /**\n * Removes all items from localStorage.\n */\n clear: () => window.localStorage.clear(),\n /**\n * Retrieves a value by key and decodes it using SuperJSON or raw string.\n *\n * @template T - The expected type of the value\n *\n * @param {string} key - The key of the value to retrieve\n *\n * @returns {null | T} The decoded value or null if not found\n */\n getItem<T = unknown>(key: string) {\n const rawValue = window.localStorage.getItem(key);\n return rawValue ? decodeStorageValue(rawValue) as T : null;\n },\n /**\n * Checks whether a key exists in localStorage.\n *\n * @param {string} key - The key to check\n *\n * @returns {boolean} True if the key exists, false otherwise\n */\n hasItem: (key: string) => window.localStorage.getItem(key) !== null,\n /**\n * Returns the number of items stored in localStorage.\n *\n * @returns {number} The number of items stored in localStorage\n */\n get length() {\n return window.localStorage.length;\n },\n /**\n * Removes a specific key from localStorage.\n *\n * @param {string} key - The key to remove\n */\n removeItem: (key: string) => window.localStorage.removeItem(key),\n /**\n * Stores a value in localStorage with automatic serialization.\n *\n * @param {string} key - The key to store the value under\n * @param {any} value - The value to store\n */\n setItem: (key: string, value: any) => window.localStorage.setItem(key, encodeToStorageValue(value)),\n});\n\nfunction decodeStorageValue(data: string) {\n if (!isCustomFormat(data)) return data;\n const payload = data.substring(customValueHeaderLength);\n const type = data.charAt(customValueHeader.length);\n switch (type) {\n case StorageValueEncodingType.Json:\n try {\n return deserialize(JSON.parse(payload));\n } catch {\n throw new Error('[EnhancedLocalStorage] Failed to parse JSON payload');\n }\n case StorageValueEncodingType.String: return payload;\n default:\n throw new Error(`[EnhancedLocalStorage] Unknown encoding type: ${type}`);\n }\n}\n\nfunction encodeToStorageValue(value: any) {\n if (typeof value === 'string') return toCustomValue(StorageValueEncodingType.String, value);\n return toCustomValue(StorageValueEncodingType.Json, JSON.stringify(serialize(value)));\n}\n\nfunction isCustomFormat(data: string) {\n return (\n data.length >= customValueHeaderLength\n && data[0] === customValueHeader[0]\n && data[1] === customValueHeader[1]\n );\n}\n"],"names":["deserialize","serialize"],"mappings":";;;;AAKA,IAAK,wBAGJ;AAHD,CAAA,UAAK,wBAAwB,EAAA;AACzB,IAAA,wBAAA,CAAA,MAAA,CAAA,GAAA,GAAU;AACV,IAAA,wBAAA,CAAA,QAAA,CAAA,GAAA,GAAY;AAChB,CAAC,EAHI,wBAAwB,KAAxB,wBAAwB,GAAA,EAAA,CAAA,CAAA;AAK7B,MAAM,iBAAiB,GAAG,IAAI;AAC9B,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,MAAM,GAAG,CAAC;AAC5D,MAAM,aAAa,GAAG,CAAC,IAA8B,EAAE,OAAe,KAAK,CAAA,EAAG,iBAAiB,CAAA,EAAG,IAAI,CAAA,EAAG,OAAO,EAAE;AAElH;;;;;;;;;;;;;AAaG;AACI,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC;AAC9C;;AAEG;IACH,KAAK,EAAE,MAAM,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE;AACxC;;;;;;;;AAQG;AACH,IAAA,OAAO,CAAc,GAAW,EAAA;QAC5B,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC;AACjD,QAAA,OAAO,QAAQ,GAAG,kBAAkB,CAAC,QAAQ,CAAM,GAAG,IAAI;IAC9D,CAAC;AACD;;;;;;AAMG;AACH,IAAA,OAAO,EAAE,CAAC,GAAW,KAAK,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI;AACnE;;;;AAIG;AACH,IAAA,IAAI,MAAM,GAAA;AACN,QAAA,OAAO,MAAM,CAAC,YAAY,CAAC,MAAM;IACrC,CAAC;AACD;;;;AAIG;AACH,IAAA,UAAU,EAAE,CAAC,GAAW,KAAK,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC;AAChE;;;;;AAKG;IACH,OAAO,EAAE,CAAC,GAAW,EAAE,KAAU,KAAK,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACtG,CAAA;AAED,SAAS,kBAAkB,CAAC,IAAY,EAAA;AACpC,IAAA,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;AAAE,QAAA,OAAO,IAAI;IACtC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,uBAAuB,CAAC;IACvD,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC;IAClD,QAAQ,IAAI;QACR,KAAK,wBAAwB,CAAC,IAAI;AAC9B,YAAA,IAAI;gBACA,OAAOA,qBAAW,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC3C;AAAE,YAAA,MAAM;AACJ,gBAAA,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC;YAC1E;AACJ,QAAA,KAAK,wBAAwB,CAAC,MAAM,EAAE,OAAO,OAAO;AACpD,QAAA;AACI,YAAA,MAAM,IAAI,KAAK,CAAC,iDAAiD,IAAI,CAAA,CAAE,CAAC;;AAEpF;AAEA,SAAS,oBAAoB,CAAC,KAAU,EAAA;IACpC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,aAAa,CAAC,wBAAwB,CAAC,MAAM,EAAE,KAAK,CAAC;AAC3F,IAAA,OAAO,aAAa,CAAC,wBAAwB,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAACC,mBAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AACzF;AAEA,SAAS,cAAc,CAAC,IAAY,EAAA;AAChC,IAAA,QACI,IAAI,CAAC,MAAM,IAAI;AACZ,WAAA,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAC,CAAC;WAC/B,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAC,CAAC,CAAC;AAE3C;;;;"}
|
|
@@ -20,38 +20,38 @@ export declare const enhancedLocalStorage: Readonly<{
|
|
|
20
20
|
/**
|
|
21
21
|
* Retrieves a value by key and decodes it using SuperJSON or raw string.
|
|
22
22
|
*
|
|
23
|
-
* @template T - The expected type of the value
|
|
23
|
+
* @template T - The expected type of the value
|
|
24
24
|
*
|
|
25
|
-
* @param {string} key - The key of the value to retrieve
|
|
25
|
+
* @param {string} key - The key of the value to retrieve
|
|
26
26
|
*
|
|
27
|
-
* @returns {null | T} The decoded value or null if not found
|
|
27
|
+
* @returns {null | T} The decoded value or null if not found
|
|
28
28
|
*/
|
|
29
29
|
getItem<T = unknown>(key: string): T | null;
|
|
30
30
|
/**
|
|
31
31
|
* Checks whether a key exists in localStorage.
|
|
32
32
|
*
|
|
33
|
-
* @param {string} key - The key to check
|
|
33
|
+
* @param {string} key - The key to check
|
|
34
34
|
*
|
|
35
|
-
* @returns {boolean} True if the key exists, false otherwise
|
|
35
|
+
* @returns {boolean} True if the key exists, false otherwise
|
|
36
36
|
*/
|
|
37
37
|
hasItem: (key: string) => boolean;
|
|
38
38
|
/**
|
|
39
39
|
* Returns the number of items stored in localStorage.
|
|
40
40
|
*
|
|
41
|
-
* @returns {number} The number of items stored in localStorage
|
|
41
|
+
* @returns {number} The number of items stored in localStorage
|
|
42
42
|
*/
|
|
43
43
|
readonly length: number;
|
|
44
44
|
/**
|
|
45
45
|
* Removes a specific key from localStorage.
|
|
46
46
|
*
|
|
47
|
-
* @param {string} key - The key to remove
|
|
47
|
+
* @param {string} key - The key to remove
|
|
48
48
|
*/
|
|
49
49
|
removeItem: (key: string) => void;
|
|
50
50
|
/**
|
|
51
51
|
* Stores a value in localStorage with automatic serialization.
|
|
52
52
|
*
|
|
53
|
-
* @param {string} key - The key to store the value under
|
|
54
|
-
* @param {any} value - The value to store
|
|
53
|
+
* @param {string} key - The key to store the value under
|
|
54
|
+
* @param {any} value - The value to store
|
|
55
55
|
*/
|
|
56
56
|
setItem: (key: string, value: any) => void;
|
|
57
57
|
}>;
|
|
@@ -30,11 +30,11 @@ const enhancedLocalStorage = Object.freeze({
|
|
|
30
30
|
/**
|
|
31
31
|
* Retrieves a value by key and decodes it using SuperJSON or raw string.
|
|
32
32
|
*
|
|
33
|
-
* @template T - The expected type of the value
|
|
33
|
+
* @template T - The expected type of the value
|
|
34
34
|
*
|
|
35
|
-
* @param {string} key - The key of the value to retrieve
|
|
35
|
+
* @param {string} key - The key of the value to retrieve
|
|
36
36
|
*
|
|
37
|
-
* @returns {null | T} The decoded value or null if not found
|
|
37
|
+
* @returns {null | T} The decoded value or null if not found
|
|
38
38
|
*/
|
|
39
39
|
getItem(key) {
|
|
40
40
|
const rawValue = window.localStorage.getItem(key);
|
|
@@ -43,15 +43,15 @@ const enhancedLocalStorage = Object.freeze({
|
|
|
43
43
|
/**
|
|
44
44
|
* Checks whether a key exists in localStorage.
|
|
45
45
|
*
|
|
46
|
-
* @param {string} key - The key to check
|
|
46
|
+
* @param {string} key - The key to check
|
|
47
47
|
*
|
|
48
|
-
* @returns {boolean} True if the key exists, false otherwise
|
|
48
|
+
* @returns {boolean} True if the key exists, false otherwise
|
|
49
49
|
*/
|
|
50
50
|
hasItem: (key) => window.localStorage.getItem(key) !== null,
|
|
51
51
|
/**
|
|
52
52
|
* Returns the number of items stored in localStorage.
|
|
53
53
|
*
|
|
54
|
-
* @returns {number} The number of items stored in localStorage
|
|
54
|
+
* @returns {number} The number of items stored in localStorage
|
|
55
55
|
*/
|
|
56
56
|
get length() {
|
|
57
57
|
return window.localStorage.length;
|
|
@@ -59,14 +59,14 @@ const enhancedLocalStorage = Object.freeze({
|
|
|
59
59
|
/**
|
|
60
60
|
* Removes a specific key from localStorage.
|
|
61
61
|
*
|
|
62
|
-
* @param {string} key - The key to remove
|
|
62
|
+
* @param {string} key - The key to remove
|
|
63
63
|
*/
|
|
64
64
|
removeItem: (key) => window.localStorage.removeItem(key),
|
|
65
65
|
/**
|
|
66
66
|
* Stores a value in localStorage with automatic serialization.
|
|
67
67
|
*
|
|
68
|
-
* @param {string} key - The key to store the value under
|
|
69
|
-
* @param {any} value - The value to store
|
|
68
|
+
* @param {string} key - The key to store the value under
|
|
69
|
+
* @param {any} value - The value to store
|
|
70
70
|
*/
|
|
71
71
|
setItem: (key, value) => window.localStorage.setItem(key, encodeToStorageValue(value)),
|
|
72
72
|
});
|
|
@@ -81,11 +81,11 @@ function decodeStorageValue(data) {
|
|
|
81
81
|
return deserialize(JSON.parse(payload));
|
|
82
82
|
}
|
|
83
83
|
catch {
|
|
84
|
-
throw new Error('[EnhancedLocalStorage] Failed to parse JSON payload
|
|
84
|
+
throw new Error('[EnhancedLocalStorage] Failed to parse JSON payload');
|
|
85
85
|
}
|
|
86
86
|
case StorageValueEncodingType.String: return payload;
|
|
87
87
|
default:
|
|
88
|
-
throw new Error(`[EnhancedLocalStorage] Unknown encoding type: ${type}
|
|
88
|
+
throw new Error(`[EnhancedLocalStorage] Unknown encoding type: ${type}`);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
function encodeToStorageValue(value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.mjs","sources":["../../../../src/storage/enhanced/local/core.ts"],"sourcesContent":["import {\n deserialize,\n serialize,\n} from 'superjson';\n\nenum StorageValueEncodingType {\n Json = '0',\n String = '1',\n}\n\nconst customValueHeader = '';\nconst customValueHeaderLength = customValueHeader.length + 1;\nconst toCustomValue = (type: StorageValueEncodingType, payload: string) => `${customValueHeader}${type}${payload}`;\n\n/**\n * An enhanced localStorage wrapper that supports storing\n * complex data types (e.g. Dates, Maps, Sets) using SuperJSON encoding.\n *\n * This utility preserves type structure when saving and retrieving values.\n *\n * @example\n * ```typescript\n * import { enhancedLocalStorage } from '@kikiutils/shared/storage/enhanced/local';\n *\n * enhancedLocalStorage.setItem('user', { name: 'user', createdAt: new Date() });\n * const user = enhancedLocalStorage.getItem<{ name: string, createdAt: Date }>('user');\n * ```\n */\nexport const enhancedLocalStorage = Object.freeze({\n /**\n * Removes all items from localStorage.\n */\n clear: () => window.localStorage.clear(),\n /**\n * Retrieves a value by key and decodes it using SuperJSON or raw string.\n *\n * @template T - The expected type of the value
|
|
1
|
+
{"version":3,"file":"core.mjs","sources":["../../../../src/storage/enhanced/local/core.ts"],"sourcesContent":["import {\n deserialize,\n serialize,\n} from 'superjson';\n\nenum StorageValueEncodingType {\n Json = '0',\n String = '1',\n}\n\nconst customValueHeader = '';\nconst customValueHeaderLength = customValueHeader.length + 1;\nconst toCustomValue = (type: StorageValueEncodingType, payload: string) => `${customValueHeader}${type}${payload}`;\n\n/**\n * An enhanced localStorage wrapper that supports storing\n * complex data types (e.g. Dates, Maps, Sets) using SuperJSON encoding.\n *\n * This utility preserves type structure when saving and retrieving values.\n *\n * @example\n * ```typescript\n * import { enhancedLocalStorage } from '@kikiutils/shared/storage/enhanced/local';\n *\n * enhancedLocalStorage.setItem('user', { name: 'user', createdAt: new Date() });\n * const user = enhancedLocalStorage.getItem<{ name: string, createdAt: Date }>('user');\n * ```\n */\nexport const enhancedLocalStorage = Object.freeze({\n /**\n * Removes all items from localStorage.\n */\n clear: () => window.localStorage.clear(),\n /**\n * Retrieves a value by key and decodes it using SuperJSON or raw string.\n *\n * @template T - The expected type of the value\n *\n * @param {string} key - The key of the value to retrieve\n *\n * @returns {null | T} The decoded value or null if not found\n */\n getItem<T = unknown>(key: string) {\n const rawValue = window.localStorage.getItem(key);\n return rawValue ? decodeStorageValue(rawValue) as T : null;\n },\n /**\n * Checks whether a key exists in localStorage.\n *\n * @param {string} key - The key to check\n *\n * @returns {boolean} True if the key exists, false otherwise\n */\n hasItem: (key: string) => window.localStorage.getItem(key) !== null,\n /**\n * Returns the number of items stored in localStorage.\n *\n * @returns {number} The number of items stored in localStorage\n */\n get length() {\n return window.localStorage.length;\n },\n /**\n * Removes a specific key from localStorage.\n *\n * @param {string} key - The key to remove\n */\n removeItem: (key: string) => window.localStorage.removeItem(key),\n /**\n * Stores a value in localStorage with automatic serialization.\n *\n * @param {string} key - The key to store the value under\n * @param {any} value - The value to store\n */\n setItem: (key: string, value: any) => window.localStorage.setItem(key, encodeToStorageValue(value)),\n});\n\nfunction decodeStorageValue(data: string) {\n if (!isCustomFormat(data)) return data;\n const payload = data.substring(customValueHeaderLength);\n const type = data.charAt(customValueHeader.length);\n switch (type) {\n case StorageValueEncodingType.Json:\n try {\n return deserialize(JSON.parse(payload));\n } catch {\n throw new Error('[EnhancedLocalStorage] Failed to parse JSON payload');\n }\n case StorageValueEncodingType.String: return payload;\n default:\n throw new Error(`[EnhancedLocalStorage] Unknown encoding type: ${type}`);\n }\n}\n\nfunction encodeToStorageValue(value: any) {\n if (typeof value === 'string') return toCustomValue(StorageValueEncodingType.String, value);\n return toCustomValue(StorageValueEncodingType.Json, JSON.stringify(serialize(value)));\n}\n\nfunction isCustomFormat(data: string) {\n return (\n data.length >= customValueHeaderLength\n && data[0] === customValueHeader[0]\n && data[1] === customValueHeader[1]\n );\n}\n"],"names":[],"mappings":";;AAKA,IAAK,wBAGJ;AAHD,CAAA,UAAK,wBAAwB,EAAA;AACzB,IAAA,wBAAA,CAAA,MAAA,CAAA,GAAA,GAAU;AACV,IAAA,wBAAA,CAAA,QAAA,CAAA,GAAA,GAAY;AAChB,CAAC,EAHI,wBAAwB,KAAxB,wBAAwB,GAAA,EAAA,CAAA,CAAA;AAK7B,MAAM,iBAAiB,GAAG,IAAI;AAC9B,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,MAAM,GAAG,CAAC;AAC5D,MAAM,aAAa,GAAG,CAAC,IAA8B,EAAE,OAAe,KAAK,CAAA,EAAG,iBAAiB,CAAA,EAAG,IAAI,CAAA,EAAG,OAAO,EAAE;AAElH;;;;;;;;;;;;;AAaG;AACI,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC;AAC9C;;AAEG;IACH,KAAK,EAAE,MAAM,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE;AACxC;;;;;;;;AAQG;AACH,IAAA,OAAO,CAAc,GAAW,EAAA;QAC5B,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC;AACjD,QAAA,OAAO,QAAQ,GAAG,kBAAkB,CAAC,QAAQ,CAAM,GAAG,IAAI;IAC9D,CAAC;AACD;;;;;;AAMG;AACH,IAAA,OAAO,EAAE,CAAC,GAAW,KAAK,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI;AACnE;;;;AAIG;AACH,IAAA,IAAI,MAAM,GAAA;AACN,QAAA,OAAO,MAAM,CAAC,YAAY,CAAC,MAAM;IACrC,CAAC;AACD;;;;AAIG;AACH,IAAA,UAAU,EAAE,CAAC,GAAW,KAAK,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC;AAChE;;;;;AAKG;IACH,OAAO,EAAE,CAAC,GAAW,EAAE,KAAU,KAAK,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACtG,CAAA;AAED,SAAS,kBAAkB,CAAC,IAAY,EAAA;AACpC,IAAA,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;AAAE,QAAA,OAAO,IAAI;IACtC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,uBAAuB,CAAC;IACvD,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC;IAClD,QAAQ,IAAI;QACR,KAAK,wBAAwB,CAAC,IAAI;AAC9B,YAAA,IAAI;gBACA,OAAO,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC3C;AAAE,YAAA,MAAM;AACJ,gBAAA,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC;YAC1E;AACJ,QAAA,KAAK,wBAAwB,CAAC,MAAM,EAAE,OAAO,OAAO;AACpD,QAAA;AACI,YAAA,MAAM,IAAI,KAAK,CAAC,iDAAiD,IAAI,CAAA,CAAE,CAAC;;AAEpF;AAEA,SAAS,oBAAoB,CAAC,KAAU,EAAA;IACpC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,aAAa,CAAC,wBAAwB,CAAC,MAAM,EAAE,KAAK,CAAC;AAC3F,IAAA,OAAO,aAAa,CAAC,wBAAwB,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AACzF;AAEA,SAAS,cAAc,CAAC,IAAY,EAAA;AAChC,IAAA,QACI,IAAI,CAAC,MAAM,IAAI;AACZ,WAAA,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAC,CAAC;WAC/B,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAC,CAAC,CAAC;AAE3C;;;;"}
|
|
@@ -9,9 +9,9 @@ const core = require('./core.cjs');
|
|
|
9
9
|
* This utility allows you to abstract away key construction logic and work directly
|
|
10
10
|
* with scoped key-value operations like `getItem`, `setItem`, and `removeItem`.
|
|
11
11
|
*
|
|
12
|
-
* @template D - The value type to store
|
|
12
|
+
* @template D - The value type to store
|
|
13
13
|
*
|
|
14
|
-
* @returns A factory that accepts a key generator function and returns a scoped storage interface
|
|
14
|
+
* @returns A factory that accepts a key generator function and returns a scoped storage interface
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```typescript
|
|
@@ -30,7 +30,7 @@ function createKeyedEnhancedLocalStore() {
|
|
|
30
30
|
/**
|
|
31
31
|
* Resolves the storage key from the given arguments.
|
|
32
32
|
*
|
|
33
|
-
* @returns {string} The final string key used internally
|
|
33
|
+
* @returns {string} The final string key used internally
|
|
34
34
|
*/
|
|
35
35
|
resolveKey: (...args) => getKeyFunction(...args),
|
|
36
36
|
setItem: (value, ...args) => core.enhancedLocalStorage.setItem(getKeyFunction(...args), value),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyed-store.cjs","sources":["../../../../src/storage/enhanced/local/keyed-store.ts"],"sourcesContent":["import { enhancedLocalStorage } from './core';\n\n/**\n * Creates a reusable, type-safe storage interface based on `enhancedLocalStorage`\n * and a dynamic key-generation function.\n *\n * This utility allows you to abstract away key construction logic and work directly\n * with scoped key-value operations like `getItem`, `setItem`, and `removeItem`.\n *\n * @template D - The value type to store
|
|
1
|
+
{"version":3,"file":"keyed-store.cjs","sources":["../../../../src/storage/enhanced/local/keyed-store.ts"],"sourcesContent":["import { enhancedLocalStorage } from './core';\n\n/**\n * Creates a reusable, type-safe storage interface based on `enhancedLocalStorage`\n * and a dynamic key-generation function.\n *\n * This utility allows you to abstract away key construction logic and work directly\n * with scoped key-value operations like `getItem`, `setItem`, and `removeItem`.\n *\n * @template D - The value type to store\n *\n * @returns A factory that accepts a key generator function and returns a scoped storage interface\n *\n * @example\n * ```typescript\n * import { createKeyedEnhancedLocalStore } from '@kikiutils/shared/storage/enhanced/local';\n *\n * const userStore = createKeyedEnhancedLocalStore<User>()((id: number) => `user:${id}`);\n * userStore.setItem({ id: 123, name: 'user' }, 123);\n * const user = userStore.getItem(123);\n * ```\n */\nexport function createKeyedEnhancedLocalStore<D = unknown>() {\n return <P extends any[]>(getKeyFunction: (...args: P) => string) => Object.freeze({\n getItem: (...args: P) => enhancedLocalStorage.getItem<D>(getKeyFunction(...args)),\n hasItem: (...args: P) => enhancedLocalStorage.hasItem(getKeyFunction(...args)),\n removeItem: (...args: P) => enhancedLocalStorage.removeItem(getKeyFunction(...args)),\n /**\n * Resolves the storage key from the given arguments.\n *\n * @returns {string} The final string key used internally\n */\n resolveKey: (...args: P) => getKeyFunction(...args),\n setItem: (value: D, ...args: P) => enhancedLocalStorage.setItem(getKeyFunction(...args), value),\n });\n}\n"],"names":["enhancedLocalStorage"],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;;;AAmBG;SACa,6BAA6B,GAAA;IACzC,OAAO,CAAkB,cAAsC,KAAK,MAAM,CAAC,MAAM,CAAC;AAC9E,QAAA,OAAO,EAAE,CAAC,GAAG,IAAO,KAAKA,yBAAoB,CAAC,OAAO,CAAI,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AACjF,QAAA,OAAO,EAAE,CAAC,GAAG,IAAO,KAAKA,yBAAoB,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AAC9E,QAAA,UAAU,EAAE,CAAC,GAAG,IAAO,KAAKA,yBAAoB,CAAC,UAAU,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AACpF;;;;AAIG;QACH,UAAU,EAAE,CAAC,GAAG,IAAO,KAAK,cAAc,CAAC,GAAG,IAAI,CAAC;QACnD,OAAO,EAAE,CAAC,KAAQ,EAAE,GAAG,IAAO,KAAKA,yBAAoB,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,EAAE,KAAK,CAAC;AAClG,KAAA,CAAC;AACN;;;;"}
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* This utility allows you to abstract away key construction logic and work directly
|
|
6
6
|
* with scoped key-value operations like `getItem`, `setItem`, and `removeItem`.
|
|
7
7
|
*
|
|
8
|
-
* @template D - The value type to store
|
|
8
|
+
* @template D - The value type to store
|
|
9
9
|
*
|
|
10
|
-
* @returns A factory that accepts a key generator function and returns a scoped storage interface
|
|
10
|
+
* @returns A factory that accepts a key generator function and returns a scoped storage interface
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```typescript
|
|
@@ -25,7 +25,7 @@ export declare function createKeyedEnhancedLocalStore<D = unknown>(): <P extends
|
|
|
25
25
|
/**
|
|
26
26
|
* Resolves the storage key from the given arguments.
|
|
27
27
|
*
|
|
28
|
-
* @returns {string} The final string key used internally
|
|
28
|
+
* @returns {string} The final string key used internally
|
|
29
29
|
*/
|
|
30
30
|
resolveKey: (...args: P) => string;
|
|
31
31
|
setItem: (value: D, ...args: P) => void;
|
|
@@ -7,9 +7,9 @@ import { enhancedLocalStorage } from './core.mjs';
|
|
|
7
7
|
* This utility allows you to abstract away key construction logic and work directly
|
|
8
8
|
* with scoped key-value operations like `getItem`, `setItem`, and `removeItem`.
|
|
9
9
|
*
|
|
10
|
-
* @template D - The value type to store
|
|
10
|
+
* @template D - The value type to store
|
|
11
11
|
*
|
|
12
|
-
* @returns A factory that accepts a key generator function and returns a scoped storage interface
|
|
12
|
+
* @returns A factory that accepts a key generator function and returns a scoped storage interface
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
@@ -28,7 +28,7 @@ function createKeyedEnhancedLocalStore() {
|
|
|
28
28
|
/**
|
|
29
29
|
* Resolves the storage key from the given arguments.
|
|
30
30
|
*
|
|
31
|
-
* @returns {string} The final string key used internally
|
|
31
|
+
* @returns {string} The final string key used internally
|
|
32
32
|
*/
|
|
33
33
|
resolveKey: (...args) => getKeyFunction(...args),
|
|
34
34
|
setItem: (value, ...args) => enhancedLocalStorage.setItem(getKeyFunction(...args), value),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyed-store.mjs","sources":["../../../../src/storage/enhanced/local/keyed-store.ts"],"sourcesContent":["import { enhancedLocalStorage } from './core';\n\n/**\n * Creates a reusable, type-safe storage interface based on `enhancedLocalStorage`\n * and a dynamic key-generation function.\n *\n * This utility allows you to abstract away key construction logic and work directly\n * with scoped key-value operations like `getItem`, `setItem`, and `removeItem`.\n *\n * @template D - The value type to store
|
|
1
|
+
{"version":3,"file":"keyed-store.mjs","sources":["../../../../src/storage/enhanced/local/keyed-store.ts"],"sourcesContent":["import { enhancedLocalStorage } from './core';\n\n/**\n * Creates a reusable, type-safe storage interface based on `enhancedLocalStorage`\n * and a dynamic key-generation function.\n *\n * This utility allows you to abstract away key construction logic and work directly\n * with scoped key-value operations like `getItem`, `setItem`, and `removeItem`.\n *\n * @template D - The value type to store\n *\n * @returns A factory that accepts a key generator function and returns a scoped storage interface\n *\n * @example\n * ```typescript\n * import { createKeyedEnhancedLocalStore } from '@kikiutils/shared/storage/enhanced/local';\n *\n * const userStore = createKeyedEnhancedLocalStore<User>()((id: number) => `user:${id}`);\n * userStore.setItem({ id: 123, name: 'user' }, 123);\n * const user = userStore.getItem(123);\n * ```\n */\nexport function createKeyedEnhancedLocalStore<D = unknown>() {\n return <P extends any[]>(getKeyFunction: (...args: P) => string) => Object.freeze({\n getItem: (...args: P) => enhancedLocalStorage.getItem<D>(getKeyFunction(...args)),\n hasItem: (...args: P) => enhancedLocalStorage.hasItem(getKeyFunction(...args)),\n removeItem: (...args: P) => enhancedLocalStorage.removeItem(getKeyFunction(...args)),\n /**\n * Resolves the storage key from the given arguments.\n *\n * @returns {string} The final string key used internally\n */\n resolveKey: (...args: P) => getKeyFunction(...args),\n setItem: (value: D, ...args: P) => enhancedLocalStorage.setItem(getKeyFunction(...args), value),\n });\n}\n"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;AAmBG;SACa,6BAA6B,GAAA;IACzC,OAAO,CAAkB,cAAsC,KAAK,MAAM,CAAC,MAAM,CAAC;AAC9E,QAAA,OAAO,EAAE,CAAC,GAAG,IAAO,KAAK,oBAAoB,CAAC,OAAO,CAAI,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AACjF,QAAA,OAAO,EAAE,CAAC,GAAG,IAAO,KAAK,oBAAoB,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AAC9E,QAAA,UAAU,EAAE,CAAC,GAAG,IAAO,KAAK,oBAAoB,CAAC,UAAU,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AACpF;;;;AAIG;QACH,UAAU,EAAE,CAAC,GAAG,IAAO,KAAK,cAAc,CAAC,GAAG,IAAI,CAAC;QACnD,OAAO,EAAE,CAAC,KAAQ,EAAE,GAAG,IAAO,KAAK,oBAAoB,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,EAAE,KAAK,CAAC;AAClG,KAAA,CAAC;AACN;;;;"}
|