@kikiutils/shared 11.0.0 → 13.0.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/README.md +10 -1
- package/dist/buffer.d.ts +7 -3
- package/dist/buffer.d.ts.map +1 -1
- package/dist/buffer.js +42 -0
- package/dist/buffer.js.map +1 -0
- package/dist/clipboard.d.ts +8 -6
- package/dist/clipboard.d.ts.map +1 -1
- package/dist/clipboard.js +86 -0
- package/dist/clipboard.js.map +1 -0
- package/dist/consola.d.ts +8 -2
- package/dist/consola.d.ts.map +1 -1
- package/dist/consola.js +32 -0
- package/dist/consola.js.map +1 -0
- package/dist/crypto-hash.d.ts +16 -26
- package/dist/crypto-hash.d.ts.map +1 -1
- package/dist/crypto-hash.js +37 -0
- package/dist/crypto-hash.js.map +1 -0
- package/dist/datetime.d.ts +13 -9
- package/dist/datetime.d.ts.map +1 -1
- package/dist/datetime.js +131 -0
- package/dist/datetime.js.map +1 -0
- package/dist/element-plus.d.ts +8 -4
- package/dist/element-plus.d.ts.map +1 -1
- package/dist/element-plus.js +37 -0
- package/dist/element-plus.js.map +1 -0
- package/dist/enum.d.ts +6 -3
- package/dist/enum.d.ts.map +1 -1
- package/dist/enum.js +108 -0
- package/dist/enum.js.map +1 -0
- package/dist/env.d.ts +12 -9
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +51 -0
- package/dist/env.js.map +1 -0
- package/dist/general.d.ts +5 -2
- package/dist/general.d.ts.map +1 -1
- package/dist/general.js +8 -0
- package/dist/general.js.map +1 -0
- package/dist/hash.d.ts +7 -4
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +20 -0
- package/dist/hash.js.map +1 -0
- package/dist/math.d.ts +20 -17
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js +36 -0
- package/dist/math.js.map +1 -0
- package/dist/number.d.ts +7 -2
- package/dist/number.d.ts.map +1 -1
- package/dist/number.js +32 -0
- package/dist/number.js.map +1 -0
- package/dist/object.d.ts +4 -1
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +42 -0
- package/dist/object.js.map +1 -0
- package/dist/pino.d.ts +8 -2
- package/dist/pino.d.ts.map +1 -1
- package/dist/pino.js +40 -0
- package/dist/pino.js.map +1 -0
- package/dist/random.d.ts +4 -1
- package/dist/random.d.ts.map +1 -1
- package/dist/random.js +31 -0
- package/dist/random.js.map +1 -0
- package/dist/storage/enhanced/local/core.d.ts +45 -42
- package/dist/storage/enhanced/local/core.d.ts.map +1 -1
- package/dist/storage/enhanced/local/core.js +63 -0
- package/dist/storage/enhanced/local/core.js.map +1 -0
- package/dist/storage/enhanced/local/index.d.ts +3 -3
- package/dist/storage/enhanced/local/index.js +4 -0
- package/dist/storage/enhanced/local/keyed-store.d.ts +14 -11
- package/dist/storage/enhanced/local/keyed-store.d.ts.map +1 -1
- package/dist/storage/enhanced/local/keyed-store.js +36 -0
- package/dist/storage/enhanced/local/keyed-store.js.map +1 -0
- package/dist/storage/enhanced/redis/core.d.ts +64 -59
- package/dist/storage/enhanced/redis/core.d.ts.map +1 -1
- package/dist/storage/enhanced/redis/core.js +85 -0
- package/dist/storage/enhanced/redis/core.js.map +1 -0
- package/dist/storage/enhanced/redis/index.d.ts +3 -3
- package/dist/storage/enhanced/redis/index.js +4 -0
- package/dist/storage/enhanced/redis/keyed-store.d.ts +19 -14
- package/dist/storage/enhanced/redis/keyed-store.d.ts.map +1 -1
- package/dist/storage/enhanced/redis/keyed-store.js +41 -0
- package/dist/storage/enhanced/redis/keyed-store.js.map +1 -0
- package/dist/storage/lru/keyed-store.d.ts +21 -16
- package/dist/storage/lru/keyed-store.d.ts.map +1 -1
- package/dist/storage/lru/keyed-store.js +40 -0
- package/dist/storage/lru/keyed-store.js.map +1 -0
- package/dist/string.d.ts +5 -2
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +42 -0
- package/dist/string.js.map +1 -0
- package/dist/url.d.ts +4 -1
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js +21 -0
- package/dist/url.js.map +1 -0
- package/dist/vue.d.ts +10 -5
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +58 -0
- package/dist/vue.js.map +1 -0
- package/dist/web.d.ts +5 -2
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +32 -0
- package/dist/web.js.map +1 -0
- package/package.json +108 -32
- package/src/hash.ts +19 -5
- package/src/vue.ts +1 -1
- package/src/web.ts +1 -1
- package/dist/buffer.cjs +0 -43
- package/dist/buffer.cjs.map +0 -1
- package/dist/buffer.mjs +0 -41
- package/dist/buffer.mjs.map +0 -1
- package/dist/clipboard.cjs +0 -91
- package/dist/clipboard.cjs.map +0 -1
- package/dist/clipboard.mjs +0 -88
- package/dist/clipboard.mjs.map +0 -1
- package/dist/consola.cjs +0 -35
- package/dist/consola.cjs.map +0 -1
- package/dist/consola.mjs +0 -32
- package/dist/consola.mjs.map +0 -1
- package/dist/crypto-hash.cjs +0 -61
- package/dist/crypto-hash.cjs.map +0 -1
- package/dist/crypto-hash.mjs +0 -50
- package/dist/crypto-hash.mjs.map +0 -1
- package/dist/datetime.cjs +0 -134
- package/dist/datetime.cjs.map +0 -1
- package/dist/datetime.mjs +0 -130
- package/dist/datetime.mjs.map +0 -1
- package/dist/element-plus.cjs +0 -37
- package/dist/element-plus.cjs.map +0 -1
- package/dist/element-plus.mjs +0 -35
- package/dist/element-plus.mjs.map +0 -1
- package/dist/enum.cjs +0 -112
- package/dist/enum.cjs.map +0 -1
- package/dist/enum.mjs +0 -108
- package/dist/enum.mjs.map +0 -1
- package/dist/env.cjs +0 -53
- package/dist/env.cjs.map +0 -1
- package/dist/env.mjs +0 -50
- package/dist/env.mjs.map +0 -1
- package/dist/general.cjs +0 -10
- package/dist/general.cjs.map +0 -1
- package/dist/general.mjs +0 -8
- package/dist/general.mjs.map +0 -1
- package/dist/hash.cjs +0 -28
- package/dist/hash.cjs.map +0 -1
- package/dist/hash.mjs +0 -23
- package/dist/hash.mjs.map +0 -1
- package/dist/math.cjs +0 -38
- package/dist/math.cjs.map +0 -1
- package/dist/math.mjs +0 -36
- package/dist/math.mjs.map +0 -1
- package/dist/number.cjs +0 -32
- package/dist/number.cjs.map +0 -1
- package/dist/number.mjs +0 -30
- package/dist/number.mjs.map +0 -1
- package/dist/object.cjs +0 -55
- package/dist/object.cjs.map +0 -1
- package/dist/object.mjs +0 -53
- package/dist/object.mjs.map +0 -1
- package/dist/pino.cjs +0 -42
- package/dist/pino.cjs.map +0 -1
- package/dist/pino.mjs +0 -39
- package/dist/pino.mjs.map +0 -1
- package/dist/random.cjs +0 -31
- package/dist/random.cjs.map +0 -1
- package/dist/random.mjs +0 -29
- package/dist/random.mjs.map +0 -1
- package/dist/storage/enhanced/local/core.cjs +0 -105
- package/dist/storage/enhanced/local/core.cjs.map +0 -1
- package/dist/storage/enhanced/local/core.mjs +0 -103
- package/dist/storage/enhanced/local/core.mjs.map +0 -1
- package/dist/storage/enhanced/local/index.cjs +0 -10
- package/dist/storage/enhanced/local/index.cjs.map +0 -1
- package/dist/storage/enhanced/local/index.d.ts.map +0 -1
- package/dist/storage/enhanced/local/index.mjs +0 -3
- package/dist/storage/enhanced/local/index.mjs.map +0 -1
- package/dist/storage/enhanced/local/keyed-store.cjs +0 -41
- package/dist/storage/enhanced/local/keyed-store.cjs.map +0 -1
- package/dist/storage/enhanced/local/keyed-store.mjs +0 -39
- package/dist/storage/enhanced/local/keyed-store.mjs.map +0 -1
- package/dist/storage/enhanced/redis/core.cjs +0 -144
- package/dist/storage/enhanced/redis/core.cjs.map +0 -1
- package/dist/storage/enhanced/redis/core.mjs +0 -142
- package/dist/storage/enhanced/redis/core.mjs.map +0 -1
- package/dist/storage/enhanced/redis/index.cjs +0 -10
- package/dist/storage/enhanced/redis/index.cjs.map +0 -1
- package/dist/storage/enhanced/redis/index.d.ts.map +0 -1
- package/dist/storage/enhanced/redis/index.mjs +0 -3
- package/dist/storage/enhanced/redis/index.mjs.map +0 -1
- package/dist/storage/enhanced/redis/keyed-store.cjs +0 -46
- package/dist/storage/enhanced/redis/keyed-store.cjs.map +0 -1
- package/dist/storage/enhanced/redis/keyed-store.mjs +0 -44
- package/dist/storage/enhanced/redis/keyed-store.mjs.map +0 -1
- package/dist/storage/lru/keyed-store.cjs +0 -49
- package/dist/storage/lru/keyed-store.cjs.map +0 -1
- package/dist/storage/lru/keyed-store.mjs +0 -47
- package/dist/storage/lru/keyed-store.mjs.map +0 -1
- package/dist/string.cjs +0 -45
- package/dist/string.cjs.map +0 -1
- package/dist/string.mjs +0 -43
- package/dist/string.mjs.map +0 -1
- package/dist/url.cjs +0 -21
- package/dist/url.cjs.map +0 -1
- package/dist/url.mjs +0 -19
- package/dist/url.mjs.map +0 -1
- package/dist/vue.cjs +0 -64
- package/dist/vue.cjs.map +0 -1
- package/dist/vue.mjs +0 -59
- package/dist/vue.mjs.map +0 -1
- package/dist/web.cjs +0 -35
- package/dist/web.cjs.map +0 -1
- package/dist/web.mjs +0 -32
- package/dist/web.mjs.map +0 -1
package/dist/pino.cjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const pino = require('pino');
|
|
4
|
-
const pinoPretty = require('pino-pretty');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Configure pinoPretty to enhance the log output.
|
|
8
|
-
*/
|
|
9
|
-
const stream = pinoPretty.PinoPretty({
|
|
10
|
-
colorize: true, // Enable colored output for better readability
|
|
11
|
-
ignore: 'hostname,pid', // Exclude 'hostname' and 'pid' fields from the logs
|
|
12
|
-
translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l', // Format the timestamp in 'yyyy-mm-dd HH:MM:ss.l' format
|
|
13
|
-
});
|
|
14
|
-
/**
|
|
15
|
-
* A pino logger instance with the configured stream.
|
|
16
|
-
*
|
|
17
|
-
* The logger's level is determined based on the `PINO_LOGGER_LEVEL` and `NODE_ENV` environment variables.
|
|
18
|
-
* If `PINO_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,
|
|
19
|
-
* the level will be set to `error`.
|
|
20
|
-
*
|
|
21
|
-
* To manually change the level, assign the desired level to `logger.level`.
|
|
22
|
-
*
|
|
23
|
-
* See available levels [here](https://getpino.io/#/docs/api?id=level-string).
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* import { logger } from '@kikiutils/shared/pino';
|
|
28
|
-
*
|
|
29
|
-
* logger.info('test'); // [2024-07-11 12:12:30.085] INFO: test
|
|
30
|
-
*
|
|
31
|
-
* // Manually change the level
|
|
32
|
-
* logger.level = 'info';
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
const pinoLogger = pino.pino({}, stream);
|
|
36
|
-
const logger = pinoLogger;
|
|
37
|
-
// eslint-disable-next-line style/max-len
|
|
38
|
-
pinoLogger.level = process.env.PINO_LOGGER_LEVEL || (process.env.NODE_ENV === 'production' ? 'error' : pinoLogger.level);
|
|
39
|
-
|
|
40
|
-
exports.logger = logger;
|
|
41
|
-
exports.pinoLogger = pinoLogger;
|
|
42
|
-
//# sourceMappingURL=pino.cjs.map
|
package/dist/pino.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pino.cjs","sources":["../src/pino.ts"],"sourcesContent":["import { pino } from 'pino';\nimport { PinoPretty } from 'pino-pretty';\n\n/**\n * Configure pinoPretty to enhance the log output.\n */\nconst stream = PinoPretty({\n colorize: true, // Enable colored output for better readability\n ignore: 'hostname,pid', // Exclude 'hostname' and 'pid' fields from the logs\n translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l', // Format the timestamp in 'yyyy-mm-dd HH:MM:ss.l' format\n});\n\n/**\n * A pino logger instance with the configured stream.\n *\n * The logger's level is determined based on the `PINO_LOGGER_LEVEL` and `NODE_ENV` environment variables.\n * If `PINO_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,\n * the level will be set to `error`.\n *\n * To manually change the level, assign the desired level to `logger.level`.\n *\n * See available levels [here](https://getpino.io/#/docs/api?id=level-string).\n *\n * @example\n * ```typescript\n * import { logger } from '@kikiutils/shared/pino';\n *\n * logger.info('test'); // [2024-07-11 12:12:30.085] INFO: test\n *\n * // Manually change the level\n * logger.level = 'info';\n * ```\n */\nexport const pinoLogger = pino({}, stream);\nexport const logger = pinoLogger;\n// eslint-disable-next-line style/max-len\npinoLogger.level = process.env.PINO_LOGGER_LEVEL || (process.env.NODE_ENV === 'production' ? 'error' : pinoLogger.level);\n"],"names":["PinoPretty","pino"],"mappings":";;;;;AAGA;;AAEG;AACH,MAAM,MAAM,GAAGA,qBAAU,CAAC;IACtB,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,cAAc;IACtB,aAAa,EAAE,2BAA2B;AAC7C,CAAA,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;AAoBG;AACI,MAAM,UAAU,GAAGC,SAAI,CAAC,EAAE,EAAE,MAAM;AAClC,MAAM,MAAM,GAAG;AACtB;AACA,UAAU,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,GAAG,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC;;;;;"}
|
package/dist/pino.mjs
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { pino } from 'pino';
|
|
2
|
-
import { PinoPretty } from 'pino-pretty';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Configure pinoPretty to enhance the log output.
|
|
6
|
-
*/
|
|
7
|
-
const stream = PinoPretty({
|
|
8
|
-
colorize: true, // Enable colored output for better readability
|
|
9
|
-
ignore: 'hostname,pid', // Exclude 'hostname' and 'pid' fields from the logs
|
|
10
|
-
translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l', // Format the timestamp in 'yyyy-mm-dd HH:MM:ss.l' format
|
|
11
|
-
});
|
|
12
|
-
/**
|
|
13
|
-
* A pino logger instance with the configured stream.
|
|
14
|
-
*
|
|
15
|
-
* The logger's level is determined based on the `PINO_LOGGER_LEVEL` and `NODE_ENV` environment variables.
|
|
16
|
-
* If `PINO_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,
|
|
17
|
-
* the level will be set to `error`.
|
|
18
|
-
*
|
|
19
|
-
* To manually change the level, assign the desired level to `logger.level`.
|
|
20
|
-
*
|
|
21
|
-
* See available levels [here](https://getpino.io/#/docs/api?id=level-string).
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* import { logger } from '@kikiutils/shared/pino';
|
|
26
|
-
*
|
|
27
|
-
* logger.info('test'); // [2024-07-11 12:12:30.085] INFO: test
|
|
28
|
-
*
|
|
29
|
-
* // Manually change the level
|
|
30
|
-
* logger.level = 'info';
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
const pinoLogger = pino({}, stream);
|
|
34
|
-
const logger = pinoLogger;
|
|
35
|
-
// eslint-disable-next-line style/max-len
|
|
36
|
-
pinoLogger.level = process.env.PINO_LOGGER_LEVEL || (process.env.NODE_ENV === 'production' ? 'error' : pinoLogger.level);
|
|
37
|
-
|
|
38
|
-
export { logger, pinoLogger };
|
|
39
|
-
//# sourceMappingURL=pino.mjs.map
|
package/dist/pino.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pino.mjs","sources":["../src/pino.ts"],"sourcesContent":["import { pino } from 'pino';\nimport { PinoPretty } from 'pino-pretty';\n\n/**\n * Configure pinoPretty to enhance the log output.\n */\nconst stream = PinoPretty({\n colorize: true, // Enable colored output for better readability\n ignore: 'hostname,pid', // Exclude 'hostname' and 'pid' fields from the logs\n translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l', // Format the timestamp in 'yyyy-mm-dd HH:MM:ss.l' format\n});\n\n/**\n * A pino logger instance with the configured stream.\n *\n * The logger's level is determined based on the `PINO_LOGGER_LEVEL` and `NODE_ENV` environment variables.\n * If `PINO_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,\n * the level will be set to `error`.\n *\n * To manually change the level, assign the desired level to `logger.level`.\n *\n * See available levels [here](https://getpino.io/#/docs/api?id=level-string).\n *\n * @example\n * ```typescript\n * import { logger } from '@kikiutils/shared/pino';\n *\n * logger.info('test'); // [2024-07-11 12:12:30.085] INFO: test\n *\n * // Manually change the level\n * logger.level = 'info';\n * ```\n */\nexport const pinoLogger = pino({}, stream);\nexport const logger = pinoLogger;\n// eslint-disable-next-line style/max-len\npinoLogger.level = process.env.PINO_LOGGER_LEVEL || (process.env.NODE_ENV === 'production' ? 'error' : pinoLogger.level);\n"],"names":[],"mappings":";;;AAGA;;AAEG;AACH,MAAM,MAAM,GAAG,UAAU,CAAC;IACtB,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,cAAc;IACtB,aAAa,EAAE,2BAA2B;AAC7C,CAAA,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;AAoBG;AACI,MAAM,UAAU,GAAG,IAAI,CAAC,EAAE,EAAE,MAAM;AAClC,MAAM,MAAM,GAAG;AACtB;AACA,UAAU,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,GAAG,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC;;;;"}
|
package/dist/random.cjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Generates a value using a provided generator function, where the input length
|
|
5
|
-
* is determined by two levels of nested random ranges:
|
|
6
|
-
*
|
|
7
|
-
* 1. First, a random number (`innerMin`) is chosen between `minMin` and `minMax`.
|
|
8
|
-
* 2. Then, a final length is chosen between `Math.max(innerMin, maxMin)` and `maxMax`.
|
|
9
|
-
* 3. The generator is called with the final length and its result is returned.
|
|
10
|
-
*
|
|
11
|
-
* This function supports any return type by using a generic type parameter.
|
|
12
|
-
*
|
|
13
|
-
* @template T - The return type of the generator function
|
|
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
|
|
20
|
-
*
|
|
21
|
-
* @returns {T} The result of the generator function using the computed final length
|
|
22
|
-
*/
|
|
23
|
-
function generateWithNestedRandomLength(generator, minMin, minMax, maxMin, maxMax) {
|
|
24
|
-
const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
|
|
25
|
-
const innerMin = random(minMin, minMax);
|
|
26
|
-
const finalLength = random(Math.max(innerMin, maxMin), maxMax);
|
|
27
|
-
return generator(finalLength);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
exports.generateWithNestedRandomLength = generateWithNestedRandomLength;
|
|
31
|
-
//# sourceMappingURL=random.cjs.map
|
package/dist/random.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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.mjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates a value using a provided generator function, where the input length
|
|
3
|
-
* is determined by two levels of nested random ranges:
|
|
4
|
-
*
|
|
5
|
-
* 1. First, a random number (`innerMin`) is chosen between `minMin` and `minMax`.
|
|
6
|
-
* 2. Then, a final length is chosen between `Math.max(innerMin, maxMin)` and `maxMax`.
|
|
7
|
-
* 3. The generator is called with the final length and its result is returned.
|
|
8
|
-
*
|
|
9
|
-
* This function supports any return type by using a generic type parameter.
|
|
10
|
-
*
|
|
11
|
-
* @template T - The return type of the generator function
|
|
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
|
|
18
|
-
*
|
|
19
|
-
* @returns {T} The result of the generator function using the computed final length
|
|
20
|
-
*/
|
|
21
|
-
function generateWithNestedRandomLength(generator, minMin, minMax, maxMin, maxMax) {
|
|
22
|
-
const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
|
|
23
|
-
const innerMin = random(minMin, minMax);
|
|
24
|
-
const finalLength = random(Math.max(innerMin, maxMin), maxMax);
|
|
25
|
-
return generator(finalLength);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { generateWithNestedRandomLength };
|
|
29
|
-
//# sourceMappingURL=random.mjs.map
|
package/dist/random.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;;;;"}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const superjson = require('superjson');
|
|
4
|
-
|
|
5
|
-
var StorageValueEncodingType;
|
|
6
|
-
(function (StorageValueEncodingType) {
|
|
7
|
-
StorageValueEncodingType["Json"] = "0";
|
|
8
|
-
StorageValueEncodingType["String"] = "1";
|
|
9
|
-
})(StorageValueEncodingType || (StorageValueEncodingType = {}));
|
|
10
|
-
const customValueHeader = '';
|
|
11
|
-
const customValueHeaderLength = customValueHeader.length + 1;
|
|
12
|
-
const toCustomValue = (type, payload) => `${customValueHeader}${type}${payload}`;
|
|
13
|
-
/**
|
|
14
|
-
* An enhanced localStorage wrapper that supports storing
|
|
15
|
-
* complex data types (e.g. Dates, Maps, Sets) using SuperJSON encoding.
|
|
16
|
-
*
|
|
17
|
-
* This utility preserves type structure when saving and retrieving values.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { enhancedLocalStorage } from '@kikiutils/shared/storage/enhanced/local';
|
|
22
|
-
*
|
|
23
|
-
* enhancedLocalStorage.setItem('user', { name: 'user', createdAt: new Date() });
|
|
24
|
-
* const user = enhancedLocalStorage.getItem<{ name: string, createdAt: Date }>('user');
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
const enhancedLocalStorage = Object.freeze({
|
|
28
|
-
/**
|
|
29
|
-
* Removes all items from localStorage.
|
|
30
|
-
*/
|
|
31
|
-
clear: () => window.localStorage.clear(),
|
|
32
|
-
/**
|
|
33
|
-
* Retrieves a value by key and decodes it using SuperJSON or raw string.
|
|
34
|
-
*
|
|
35
|
-
* @template T - The expected type of the value
|
|
36
|
-
*
|
|
37
|
-
* @param {string} key - The key of the value to retrieve
|
|
38
|
-
*
|
|
39
|
-
* @returns {null | T} The decoded value or null if not found
|
|
40
|
-
*/
|
|
41
|
-
getItem(key) {
|
|
42
|
-
const rawValue = window.localStorage.getItem(key);
|
|
43
|
-
return rawValue ? decodeStorageValue(rawValue) : null;
|
|
44
|
-
},
|
|
45
|
-
/**
|
|
46
|
-
* Checks whether a key exists in localStorage.
|
|
47
|
-
*
|
|
48
|
-
* @param {string} key - The key to check
|
|
49
|
-
*
|
|
50
|
-
* @returns {boolean} True if the key exists, false otherwise
|
|
51
|
-
*/
|
|
52
|
-
hasItem: (key) => window.localStorage.getItem(key) !== null,
|
|
53
|
-
/**
|
|
54
|
-
* Returns the number of items stored in localStorage.
|
|
55
|
-
*
|
|
56
|
-
* @returns {number} The number of items stored in localStorage
|
|
57
|
-
*/
|
|
58
|
-
get length() {
|
|
59
|
-
return window.localStorage.length;
|
|
60
|
-
},
|
|
61
|
-
/**
|
|
62
|
-
* Removes a specific key from localStorage.
|
|
63
|
-
*
|
|
64
|
-
* @param {string} key - The key to remove
|
|
65
|
-
*/
|
|
66
|
-
removeItem: (key) => window.localStorage.removeItem(key),
|
|
67
|
-
/**
|
|
68
|
-
* Stores a value in localStorage with automatic serialization.
|
|
69
|
-
*
|
|
70
|
-
* @param {string} key - The key to store the value under
|
|
71
|
-
* @param {any} value - The value to store
|
|
72
|
-
*/
|
|
73
|
-
setItem: (key, value) => window.localStorage.setItem(key, encodeToStorageValue(value)),
|
|
74
|
-
});
|
|
75
|
-
function decodeStorageValue(data) {
|
|
76
|
-
if (!isCustomFormat(data))
|
|
77
|
-
return data;
|
|
78
|
-
const payload = data.substring(customValueHeaderLength);
|
|
79
|
-
const type = data.charAt(customValueHeader.length);
|
|
80
|
-
switch (type) {
|
|
81
|
-
case StorageValueEncodingType.Json:
|
|
82
|
-
try {
|
|
83
|
-
return superjson.deserialize(JSON.parse(payload));
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
throw new Error('[EnhancedLocalStorage] Failed to parse JSON payload');
|
|
87
|
-
}
|
|
88
|
-
case StorageValueEncodingType.String: return payload;
|
|
89
|
-
default:
|
|
90
|
-
throw new Error(`[EnhancedLocalStorage] Unknown encoding type: ${type}`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function encodeToStorageValue(value) {
|
|
94
|
-
if (typeof value === 'string')
|
|
95
|
-
return toCustomValue(StorageValueEncodingType.String, value);
|
|
96
|
-
return toCustomValue(StorageValueEncodingType.Json, JSON.stringify(superjson.serialize(value)));
|
|
97
|
-
}
|
|
98
|
-
function isCustomFormat(data) {
|
|
99
|
-
return (data.length >= customValueHeaderLength
|
|
100
|
-
&& data[0] === customValueHeader[0]
|
|
101
|
-
&& data[1] === customValueHeader[1]);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
exports.enhancedLocalStorage = enhancedLocalStorage;
|
|
105
|
-
//# sourceMappingURL=core.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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;;;;"}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { serialize, deserialize } from 'superjson';
|
|
2
|
-
|
|
3
|
-
var StorageValueEncodingType;
|
|
4
|
-
(function (StorageValueEncodingType) {
|
|
5
|
-
StorageValueEncodingType["Json"] = "0";
|
|
6
|
-
StorageValueEncodingType["String"] = "1";
|
|
7
|
-
})(StorageValueEncodingType || (StorageValueEncodingType = {}));
|
|
8
|
-
const customValueHeader = '';
|
|
9
|
-
const customValueHeaderLength = customValueHeader.length + 1;
|
|
10
|
-
const toCustomValue = (type, payload) => `${customValueHeader}${type}${payload}`;
|
|
11
|
-
/**
|
|
12
|
-
* An enhanced localStorage wrapper that supports storing
|
|
13
|
-
* complex data types (e.g. Dates, Maps, Sets) using SuperJSON encoding.
|
|
14
|
-
*
|
|
15
|
-
* This utility preserves type structure when saving and retrieving values.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* import { enhancedLocalStorage } from '@kikiutils/shared/storage/enhanced/local';
|
|
20
|
-
*
|
|
21
|
-
* enhancedLocalStorage.setItem('user', { name: 'user', createdAt: new Date() });
|
|
22
|
-
* const user = enhancedLocalStorage.getItem<{ name: string, createdAt: Date }>('user');
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
const enhancedLocalStorage = Object.freeze({
|
|
26
|
-
/**
|
|
27
|
-
* Removes all items from localStorage.
|
|
28
|
-
*/
|
|
29
|
-
clear: () => window.localStorage.clear(),
|
|
30
|
-
/**
|
|
31
|
-
* Retrieves a value by key and decodes it using SuperJSON or raw string.
|
|
32
|
-
*
|
|
33
|
-
* @template T - The expected type of the value
|
|
34
|
-
*
|
|
35
|
-
* @param {string} key - The key of the value to retrieve
|
|
36
|
-
*
|
|
37
|
-
* @returns {null | T} The decoded value or null if not found
|
|
38
|
-
*/
|
|
39
|
-
getItem(key) {
|
|
40
|
-
const rawValue = window.localStorage.getItem(key);
|
|
41
|
-
return rawValue ? decodeStorageValue(rawValue) : null;
|
|
42
|
-
},
|
|
43
|
-
/**
|
|
44
|
-
* Checks whether a key exists in localStorage.
|
|
45
|
-
*
|
|
46
|
-
* @param {string} key - The key to check
|
|
47
|
-
*
|
|
48
|
-
* @returns {boolean} True if the key exists, false otherwise
|
|
49
|
-
*/
|
|
50
|
-
hasItem: (key) => window.localStorage.getItem(key) !== null,
|
|
51
|
-
/**
|
|
52
|
-
* Returns the number of items stored in localStorage.
|
|
53
|
-
*
|
|
54
|
-
* @returns {number} The number of items stored in localStorage
|
|
55
|
-
*/
|
|
56
|
-
get length() {
|
|
57
|
-
return window.localStorage.length;
|
|
58
|
-
},
|
|
59
|
-
/**
|
|
60
|
-
* Removes a specific key from localStorage.
|
|
61
|
-
*
|
|
62
|
-
* @param {string} key - The key to remove
|
|
63
|
-
*/
|
|
64
|
-
removeItem: (key) => window.localStorage.removeItem(key),
|
|
65
|
-
/**
|
|
66
|
-
* Stores a value in localStorage with automatic serialization.
|
|
67
|
-
*
|
|
68
|
-
* @param {string} key - The key to store the value under
|
|
69
|
-
* @param {any} value - The value to store
|
|
70
|
-
*/
|
|
71
|
-
setItem: (key, value) => window.localStorage.setItem(key, encodeToStorageValue(value)),
|
|
72
|
-
});
|
|
73
|
-
function decodeStorageValue(data) {
|
|
74
|
-
if (!isCustomFormat(data))
|
|
75
|
-
return data;
|
|
76
|
-
const payload = data.substring(customValueHeaderLength);
|
|
77
|
-
const type = data.charAt(customValueHeader.length);
|
|
78
|
-
switch (type) {
|
|
79
|
-
case StorageValueEncodingType.Json:
|
|
80
|
-
try {
|
|
81
|
-
return deserialize(JSON.parse(payload));
|
|
82
|
-
}
|
|
83
|
-
catch {
|
|
84
|
-
throw new Error('[EnhancedLocalStorage] Failed to parse JSON payload');
|
|
85
|
-
}
|
|
86
|
-
case StorageValueEncodingType.String: return payload;
|
|
87
|
-
default:
|
|
88
|
-
throw new Error(`[EnhancedLocalStorage] Unknown encoding type: ${type}`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
function encodeToStorageValue(value) {
|
|
92
|
-
if (typeof value === 'string')
|
|
93
|
-
return toCustomValue(StorageValueEncodingType.String, value);
|
|
94
|
-
return toCustomValue(StorageValueEncodingType.Json, JSON.stringify(serialize(value)));
|
|
95
|
-
}
|
|
96
|
-
function isCustomFormat(data) {
|
|
97
|
-
return (data.length >= customValueHeaderLength
|
|
98
|
-
&& data[0] === customValueHeader[0]
|
|
99
|
-
&& data[1] === customValueHeader[1]);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export { enhancedLocalStorage };
|
|
103
|
-
//# sourceMappingURL=core.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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;;;;"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const core = require('./core.cjs');
|
|
4
|
-
const keyedStore = require('./keyed-store.cjs');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.enhancedLocalStorage = core.enhancedLocalStorage;
|
|
9
|
-
exports.createKeyedEnhancedLocalStore = keyedStore.createKeyedEnhancedLocalStore;
|
|
10
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/enhanced/local/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const core = require('./core.cjs');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Creates a reusable, type-safe storage interface based on `enhancedLocalStorage`
|
|
7
|
-
* and a dynamic key-generation function.
|
|
8
|
-
*
|
|
9
|
-
* This utility allows you to abstract away key construction logic and work directly
|
|
10
|
-
* with scoped key-value operations like `getItem`, `setItem`, and `removeItem`.
|
|
11
|
-
*
|
|
12
|
-
* @template D - The value type to store
|
|
13
|
-
*
|
|
14
|
-
* @returns A factory that accepts a key generator function and returns a scoped storage interface
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* import { createKeyedEnhancedLocalStore } from '@kikiutils/shared/storage/enhanced/local';
|
|
19
|
-
*
|
|
20
|
-
* const userStore = createKeyedEnhancedLocalStore<User>()((id: number) => `user:${id}`);
|
|
21
|
-
* userStore.setItem({ id: 123, name: 'user' }, 123);
|
|
22
|
-
* const user = userStore.getItem(123);
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
function createKeyedEnhancedLocalStore() {
|
|
26
|
-
return (getKeyFunction) => Object.freeze({
|
|
27
|
-
getItem: (...args) => core.enhancedLocalStorage.getItem(getKeyFunction(...args)),
|
|
28
|
-
hasItem: (...args) => core.enhancedLocalStorage.hasItem(getKeyFunction(...args)),
|
|
29
|
-
removeItem: (...args) => core.enhancedLocalStorage.removeItem(getKeyFunction(...args)),
|
|
30
|
-
/**
|
|
31
|
-
* Resolves the storage key from the given arguments.
|
|
32
|
-
*
|
|
33
|
-
* @returns {string} The final string key used internally
|
|
34
|
-
*/
|
|
35
|
-
resolveKey: (...args) => getKeyFunction(...args),
|
|
36
|
-
setItem: (value, ...args) => core.enhancedLocalStorage.setItem(getKeyFunction(...args), value),
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
exports.createKeyedEnhancedLocalStore = createKeyedEnhancedLocalStore;
|
|
41
|
-
//# sourceMappingURL=keyed-store.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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;;;;"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { enhancedLocalStorage } from './core.mjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Creates a reusable, type-safe storage interface based on `enhancedLocalStorage`
|
|
5
|
-
* and a dynamic key-generation function.
|
|
6
|
-
*
|
|
7
|
-
* This utility allows you to abstract away key construction logic and work directly
|
|
8
|
-
* with scoped key-value operations like `getItem`, `setItem`, and `removeItem`.
|
|
9
|
-
*
|
|
10
|
-
* @template D - The value type to store
|
|
11
|
-
*
|
|
12
|
-
* @returns A factory that accepts a key generator function and returns a scoped storage interface
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* import { createKeyedEnhancedLocalStore } from '@kikiutils/shared/storage/enhanced/local';
|
|
17
|
-
*
|
|
18
|
-
* const userStore = createKeyedEnhancedLocalStore<User>()((id: number) => `user:${id}`);
|
|
19
|
-
* userStore.setItem({ id: 123, name: 'user' }, 123);
|
|
20
|
-
* const user = userStore.getItem(123);
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
function createKeyedEnhancedLocalStore() {
|
|
24
|
-
return (getKeyFunction) => Object.freeze({
|
|
25
|
-
getItem: (...args) => enhancedLocalStorage.getItem(getKeyFunction(...args)),
|
|
26
|
-
hasItem: (...args) => enhancedLocalStorage.hasItem(getKeyFunction(...args)),
|
|
27
|
-
removeItem: (...args) => enhancedLocalStorage.removeItem(getKeyFunction(...args)),
|
|
28
|
-
/**
|
|
29
|
-
* Resolves the storage key from the given arguments.
|
|
30
|
-
*
|
|
31
|
-
* @returns {string} The final string key used internally
|
|
32
|
-
*/
|
|
33
|
-
resolveKey: (...args) => getKeyFunction(...args),
|
|
34
|
-
setItem: (value, ...args) => enhancedLocalStorage.setItem(getKeyFunction(...args), value),
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { createKeyedEnhancedLocalStore };
|
|
39
|
-
//# sourceMappingURL=keyed-store.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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;;;;"}
|