@kikiutils/shared 15.1.1 → 16.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 +1 -1
- package/dist/classes/path.d.ts.map +1 -1
- package/dist/classes/path.js.map +1 -1
- package/dist/classes/precision-number.d.ts.map +1 -1
- package/dist/classes/precision-number.js.map +1 -1
- package/dist/classes/ssh-client.d.ts +4 -6
- package/dist/classes/ssh-client.d.ts.map +1 -1
- package/dist/classes/ssh-client.js.map +1 -1
- package/dist/consola.d.ts +2 -4
- package/dist/consola.d.ts.map +1 -1
- package/dist/crypto-hash.d.ts +11 -11
- package/dist/crypto-hash.d.ts.map +1 -1
- package/dist/crypto-hash.js +19 -15
- package/dist/crypto-hash.js.map +1 -1
- package/dist/enum.d.ts.map +1 -1
- package/dist/enum.js.map +1 -1
- package/dist/general.d.ts.map +1 -1
- package/dist/math.js.map +1 -1
- package/dist/object.js.map +1 -1
- package/dist/pino.d.ts +2 -4
- package/dist/pino.d.ts.map +1 -1
- package/dist/random.d.ts.map +1 -1
- package/dist/storages/lru/keyed-store.d.ts.map +1 -1
- package/dist/storages/redis/keyed-store.d.ts +2 -2
- package/dist/storages/redis/keyed-store.d.ts.map +1 -1
- package/dist/storages/redis/types.d.ts +2 -4
- package/dist/storages/redis/types.d.ts.map +1 -1
- package/dist/string.js +7 -10
- package/dist/string.js.map +1 -1
- package/dist/types/index.d.ts +1 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/vue.d.ts +1 -2
- package/dist/types/vue.d.ts.map +1 -1
- package/dist/url.js.map +1 -1
- package/dist/vue.d.ts +6 -7
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +3 -3
- package/dist/vue.js.map +1 -1
- package/package.json +23 -22
- package/src/classes/ssh-client.ts +4 -6
- package/src/crypto-hash.ts +26 -24
- package/src/storages/redis/types.ts +2 -4
- package/src/types/index.ts +0 -5
- package/src/types/vue.ts +1 -3
- package/src/vue.ts +6 -7
package/dist/math.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.js","names":[],"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\n const result = calculationResult.isNaN() || !calculationResult.isFinite()\n ? '0.00'\n : calculationResult.times(100).toFixed(options?.decimalPlaces ?? 2);\n\n return options?.withSymbol ?? true ? `${result}%` : result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,mBACZ,WACA,aACA,SACF;CACE,MAAM,mBAAmB,IAAI,QAAQ,UAAU,SAAS,CAAC;CACzD,MAAM,qBAAqB,IAAI,QAAQ,YAAY,SAAS,CAAC;CAC7D,MAAM,oBAAoB,iBAAiB,IAAI,kBAAkB;CAEjE,MAAM,SAAS,kBAAkB,MAAM,KAAK,CAAC,kBAAkB,SAAS,IAClE,SACA,kBAAkB,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"math.js","names":[],"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\n const result = calculationResult.isNaN() || !calculationResult.isFinite()\n ? '0.00'\n : calculationResult.times(100).toFixed(options?.decimalPlaces ?? 2);\n\n return options?.withSymbol ?? true ? `${result}%` : result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,mBACZ,WACA,aACA,SACF;CACE,MAAM,mBAAmB,IAAI,QAAQ,UAAU,SAAS,CAAC;CACzD,MAAM,qBAAqB,IAAI,QAAQ,YAAY,SAAS,CAAC;CAC7D,MAAM,oBAAoB,iBAAiB,IAAI,kBAAkB;CAEjE,MAAM,SAAS,kBAAkB,MAAM,KAAK,CAAC,kBAAkB,SAAS,IAClE,SACA,kBAAkB,MAAM,GAAG,CAAC,CAAC,QAAQ,SAAS,iBAAiB,CAAC;CAEtE,OAAO,SAAS,cAAc,OAAO,GAAG,OAAO,KAAK;AACxD"}
|
package/dist/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","names":[],"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 * Note: Empty objects and arrays produce an empty string, which is useful for\n * generating deterministic signature payloads.\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 * console.log(stringifyObjectDeterministically({})); // ''\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, i) => {\n walk(\n value,\n [\n ...path,\n i.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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,iCACZ,OACA,cAAsB,KACtB,gBAAwB,KAC1B;CACE,MAAM,UAAoB,CAAC;CAE3B,SAAS,KAAK,QAAa,OAAiB,CAAC,GAAG;EAC5C,IAAI,MAAM,QAAQ,MAAM,GACpB,OAAO,SAAS,OAAO,MAAM;GACzB,KACI,OACA,CACI,GAAG,MACH,EAAE,SAAS,CACf,CACJ;EACJ,CAAC;OACE,IACH,WAAW,QACR,OAAO,WAAW,YAClB,OAAO,UAAU,SAAS,KAAK,MAAM,MAAM,mBAE9C,OAAO,KAAK,MAAM,
|
|
1
|
+
{"version":3,"file":"object.js","names":[],"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 * Note: Empty objects and arrays produce an empty string, which is useful for\n * generating deterministic signature payloads.\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 * console.log(stringifyObjectDeterministically({})); // ''\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, i) => {\n walk(\n value,\n [\n ...path,\n i.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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,iCACZ,OACA,cAAsB,KACtB,gBAAwB,KAC1B;CACE,MAAM,UAAoB,CAAC;CAE3B,SAAS,KAAK,QAAa,OAAiB,CAAC,GAAG;EAC5C,IAAI,MAAM,QAAQ,MAAM,GACpB,OAAO,SAAS,OAAO,MAAM;GACzB,KACI,OACA,CACI,GAAG,MACH,EAAE,SAAS,CACf,CACJ;EACJ,CAAC;OACE,IACH,WAAW,QACR,OAAO,WAAW,YAClB,OAAO,UAAU,SAAS,KAAK,MAAM,MAAM,mBAE9C,OAAO,KAAK,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,SAAS,QAAQ;GACxC,KACI,OAAO,MACP,CACI,GAAG,MACH,GACJ,CACJ;EACJ,CAAC;OACE,QAAQ,KAAK,GAAG,KAAK,KAAK,GAAG,IAAI,cAAc,OAAO,MAAM,GAAG;CAC1E;CAEA,KAAK,KAAK;CACV,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,aAAa;AAC5C"}
|
package/dist/pino.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import * as _$pino from "pino";
|
|
2
|
-
|
|
3
1
|
//#region src/pino.d.ts
|
|
4
2
|
/**
|
|
5
3
|
* A pino logger instance with the configured stream.
|
|
@@ -22,8 +20,8 @@ import * as _$pino from "pino";
|
|
|
22
20
|
* logger.level = 'info';
|
|
23
21
|
* ```
|
|
24
22
|
*/
|
|
25
|
-
declare const pinoLogger:
|
|
26
|
-
declare const logger:
|
|
23
|
+
declare const pinoLogger: import("pino").Logger<never, boolean>;
|
|
24
|
+
declare const logger: import("pino").Logger<never, boolean>;
|
|
27
25
|
//#endregion
|
|
28
26
|
export { logger, pinoLogger };
|
|
29
27
|
//# sourceMappingURL=pino.d.ts.map
|
package/dist/pino.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pino.d.ts","names":[],"sources":["../src/pino.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"pino.d.ts","names":[],"sources":["../src/pino.ts"],"mappings":";;AAiCA;;;;AAAuB;AACvB;;;;AAAmB;;;;;;;;;;;cADN,UAAA,iBAAU,MAAA;AAAA,cACV,MAAA,iBAAM,MAAA"}
|
package/dist/random.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.d.ts","names":[],"sources":["../src/random.ts"],"mappings":";;AAoBA;;;;;;;;;;;;;;AAKkB;;;;;iBALF,8BAAA,
|
|
1
|
+
{"version":3,"file":"random.d.ts","names":[],"sources":["../src/random.ts"],"mappings":";;AAoBA;;;;;;;;;;;;;;AAKkB;;;;;iBALF,8BAAA,aACZ,SAAA,GAAY,MAAA,aAAmB,CAAA,EAC/B,MAAA,UACA,MAAA,UACA,MAAA,UACA,MAAA,WAAc,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyed-store.d.ts","names":[],"sources":["../../../src/storages/lru/keyed-store.ts"],"mappings":";;;;;AAwBA;;;;;;;;;;;;;;;;;;;;iBAAgB,mBAAA,
|
|
1
|
+
{"version":3,"file":"keyed-store.d.ts","names":[],"sources":["../../../src/storages/lru/keyed-store.ts"],"mappings":";;;;;AAwBA;;;;;;;;;;;;;;;;;;;;iBAAgB,mBAAA,cAAiC,WAAA,EAAa,QAAA,oCACjC,KAAA,MAAW,IAAA,EAAM,CAAA,gBAAY,QAAA;EAA9C;;;;;mBAMa,CAAA,GAAC,WAAA,CAAA,CAAA;wBAII,CAAA;qBACH,CAAA;wBACG,CAAA;EANJ;;;wBAUI,CAAA;mBACL,CAAA,KAAC,IAAA,EAAW,CAAA,KAAC,QAAA;AAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MaybeReadonly
|
|
1
|
+
import { MaybeReadonly } from "../../types/index.js";
|
|
2
2
|
import { RedisLikeStorage } from "./types.js";
|
|
3
3
|
|
|
4
4
|
//#region src/storages/redis/keyed-store.d.ts
|
|
@@ -28,7 +28,7 @@ import { RedisLikeStorage } from "./types.js";
|
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
30
|
declare function createRedisKeyedStore<D = unknown>(storage: MaybeReadonly<RedisLikeStorage>): <P extends any[]>(keyFn: (...args: P) => string) => Readonly<{
|
|
31
|
-
getItem: (...args: P) => Promise<
|
|
31
|
+
getItem: (...args: P) => Promise<D | null>;
|
|
32
32
|
getItemTtl: (...args: P) => Promise<number>;
|
|
33
33
|
hasItem: (...args: P) => Promise<boolean>;
|
|
34
34
|
removeItem: (...args: P) => Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyed-store.d.ts","names":[],"sources":["../../../src/storages/redis/keyed-store.ts"],"mappings":";;;;;;AA6BA;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,qBAAA,
|
|
1
|
+
{"version":3,"file":"keyed-store.d.ts","names":[],"sources":["../../../src/storages/redis/keyed-store.ts"],"mappings":";;;;;;AA6BA;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,qBAAA,cAAmC,OAAA,EAAS,aAAA,CAAc,gBAAA,sBAC7C,KAAA,MAAW,IAAA,EAAM,CAAA,gBAAY,QAAA;qBAC/B,CAAA,KAAC,OAAA,CAAA,CAAA;wBACE,CAAA,KAAC,OAAA;qBACJ,CAAA,KAAC,OAAA;wBACE,CAAA,KAAC,OAAA;wBACD,CAAA;mBACL,CAAA,KAAC,IAAA,EAAW,CAAA,KAAC,OAAA;qCACG,KAAA,EAAS,CAAA,KAAC,IAAA,EAAW,CAAA,GAAC,OAAA;AAAA"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Nullable } from "../../types/index.js";
|
|
2
|
-
|
|
3
1
|
//#region src/storages/redis/types.d.ts
|
|
4
2
|
/**
|
|
5
3
|
* Low-level Redis-like adapter interface for raw buffer operations.
|
|
@@ -12,7 +10,7 @@ interface RedisLikeAdapter {
|
|
|
12
10
|
/**
|
|
13
11
|
* Gets the raw buffer value for a key.
|
|
14
12
|
*/
|
|
15
|
-
getBuffer: (key: string) => Promise<
|
|
13
|
+
getBuffer: (key: string) => Promise<null | Uint8Array>;
|
|
16
14
|
/**
|
|
17
15
|
* Checks if a key exists.
|
|
18
16
|
*/
|
|
@@ -37,7 +35,7 @@ interface RedisLikeStorage {
|
|
|
37
35
|
/**
|
|
38
36
|
* Gets a deserialized value by key.
|
|
39
37
|
*/
|
|
40
|
-
getItem: <T = unknown>(key: string) => Promise<
|
|
38
|
+
getItem: <T = unknown>(key: string) => Promise<null | T>;
|
|
41
39
|
/**
|
|
42
40
|
* Gets the TTL of a key in seconds.
|
|
43
41
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/storages/redis/types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/storages/redis/types.ts"],"mappings":";;AAGA;;UAAiB,gBAAA;EAIY;;;EAAzB,MAAA,GAAS,GAAA,aAAgB,OAAA;EAeO;;;EAVhC,SAAA,GAAY,GAAA,aAAgB,OAAA,QAAe,UAAA;EAoBrB;;;EAftB,GAAA,GAAM,GAAA,aAAgB,OAAA;EAVb;;;EAeT,SAAA,GAAY,GAAA,UAAa,KAAA,EAAO,UAAA,KAAe,OAAA;EAVnB;;;EAe5B,WAAA,GAAc,GAAA,UAAa,UAAA,UAAoB,KAAA,EAAO,UAAA,KAAe,OAAA;EAV/C;;;EAetB,GAAA,GAAM,GAAA,aAAgB,OAAA;AAAA;;;;UAMT,gBAAA;EAXyC;;;EAetD,OAAA,gBAAuB,GAAA,aAAgB,OAAA,QAAe,CAAA;EAVhD;;;EAeN,UAAA,GAAa,GAAA,aAAgB,OAAA;EAThB;;;EAcb,OAAA,GAAU,GAAA,aAAgB,OAAA;EAVa;;;EAevC,UAAA,GAAa,GAAA,aAAgB,OAAA;EAKS;;;EAAtC,OAAA,GAAU,GAAA,UAAa,KAAA,UAAe,OAAA;EApBtC;;;EAyBA,cAAA,GAAiB,GAAA,UAAa,UAAA,UAAoB,KAAA,UAAe,OAAA;AAAA"}
|
package/dist/string.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
//#region src/string.ts
|
|
2
|
-
const DIGITS = "0123456789";
|
|
3
|
-
const LOWERCASE = "abcdefghijklmnopqrstuvwxyz";
|
|
4
|
-
const UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
5
2
|
const CHARSETS = {
|
|
6
|
-
"alphabetic":
|
|
7
|
-
"alphanumeric":
|
|
8
|
-
"lowercase":
|
|
9
|
-
"lowercase-numeric":
|
|
10
|
-
"numeric":
|
|
11
|
-
"uppercase":
|
|
12
|
-
"uppercase-numeric":
|
|
3
|
+
"alphabetic": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
4
|
+
"alphanumeric": "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
5
|
+
"lowercase": "abcdefghijklmnopqrstuvwxyz",
|
|
6
|
+
"lowercase-numeric": "0123456789abcdefghijklmnopqrstuvwxyz",
|
|
7
|
+
"numeric": "0123456789",
|
|
8
|
+
"uppercase": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
9
|
+
"uppercase-numeric": "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
13
10
|
};
|
|
14
11
|
/**
|
|
15
12
|
* Generates a random string of a given length using a predefined character set.
|
package/dist/string.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.js","names":[],"sources":["../src/string.ts"],"sourcesContent":["/**\n * Character-set presets supported by `randomString`.\n */\nexport type RandomStringMode =\n | 'alphabetic'\n | 'alphanumeric'\n | 'lowercase'\n | 'lowercase-numeric'\n | 'numeric'\n | 'uppercase'\n | 'uppercase-numeric';\n\nconst DIGITS = '0123456789';\nconst LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';\nconst UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\nconst CHARSETS: Record<RandomStringMode, string> = {\n 'alphabetic': LOWERCASE + UPPERCASE,\n 'alphanumeric': DIGITS + LOWERCASE + UPPERCASE,\n 'lowercase': LOWERCASE,\n 'lowercase-numeric': DIGITS + LOWERCASE,\n 'numeric': DIGITS,\n 'uppercase': UPPERCASE,\n 'uppercase-numeric': DIGITS + UPPERCASE,\n};\n\n/**\n * Generates a random string of a given length using a predefined character set.\n *\n * Uses `Math.random`, so this helper is suitable for display tokens, placeholders,\n * and test data, but not for passwords, API keys, or other cryptographic secrets.\n *\n * @param {number} length - The positive integer length of the string to generate\n * @param {RandomStringMode} [mode] - The character set to use (default: `'alphabetic'`)\n *\n * @returns {string} The generated random string\n *\n * @throws {Error} If the length is not a positive integer or the mode is unsupported\n *\n * @example\n * ```typescript\n * import { randomString } from '@kikiutils/shared/string';\n *\n * randomString(8); // e.g. 'aZbXwTyQ'\n * randomString(6, 'numeric'); // e.g. '402398'\n * randomString(10, 'alphanumeric'); // e.g. 'a9Z4pQ8xY2'\n * ```\n */\nexport function randomString(length: number, mode: RandomStringMode = 'alphabetic') {\n if (!Number.isInteger(length) || length <= 0) {\n throw new Error(`Invalid length: ${length}. Must be a positive integer`);\n }\n\n const charset = CHARSETS[mode];\n if (!charset) throw new Error(`Unsupported mode: ${mode}`);\n return Array.from({ length }, () => charset[Math.floor(Math.random() * charset.length)]).join('');\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"string.js","names":[],"sources":["../src/string.ts"],"sourcesContent":["/**\n * Character-set presets supported by `randomString`.\n */\nexport type RandomStringMode =\n | 'alphabetic'\n | 'alphanumeric'\n | 'lowercase'\n | 'lowercase-numeric'\n | 'numeric'\n | 'uppercase'\n | 'uppercase-numeric';\n\nconst DIGITS = '0123456789';\nconst LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';\nconst UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\nconst CHARSETS: Record<RandomStringMode, string> = {\n 'alphabetic': LOWERCASE + UPPERCASE,\n 'alphanumeric': DIGITS + LOWERCASE + UPPERCASE,\n 'lowercase': LOWERCASE,\n 'lowercase-numeric': DIGITS + LOWERCASE,\n 'numeric': DIGITS,\n 'uppercase': UPPERCASE,\n 'uppercase-numeric': DIGITS + UPPERCASE,\n};\n\n/**\n * Generates a random string of a given length using a predefined character set.\n *\n * Uses `Math.random`, so this helper is suitable for display tokens, placeholders,\n * and test data, but not for passwords, API keys, or other cryptographic secrets.\n *\n * @param {number} length - The positive integer length of the string to generate\n * @param {RandomStringMode} [mode] - The character set to use (default: `'alphabetic'`)\n *\n * @returns {string} The generated random string\n *\n * @throws {Error} If the length is not a positive integer or the mode is unsupported\n *\n * @example\n * ```typescript\n * import { randomString } from '@kikiutils/shared/string';\n *\n * randomString(8); // e.g. 'aZbXwTyQ'\n * randomString(6, 'numeric'); // e.g. '402398'\n * randomString(10, 'alphanumeric'); // e.g. 'a9Z4pQ8xY2'\n * ```\n */\nexport function randomString(length: number, mode: RandomStringMode = 'alphabetic') {\n if (!Number.isInteger(length) || length <= 0) {\n throw new Error(`Invalid length: ${length}. Must be a positive integer`);\n }\n\n const charset = CHARSETS[mode];\n if (!charset) throw new Error(`Unsupported mode: ${mode}`);\n return Array.from({ length }, () => charset[Math.floor(Math.random() * charset.length)]).join('');\n}\n"],"mappings":";AAeA,MAAM,WAA6C;CAC/C,cAAc;CACd,gBAAgB;CAChB,aAAa;CACb,qBAAqB;CACrB,WAAW;CACX,aAAa;CACb,qBAAqB;AACzB;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,aAAa,QAAgB,OAAyB,cAAc;CAChF,IAAI,CAAC,OAAO,UAAU,MAAM,KAAK,UAAU,GACvC,MAAM,IAAI,MAAM,mBAAmB,OAAO,6BAA6B;CAG3E,MAAM,UAAU,SAAS;CACzB,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,qBAAqB,MAAM;CACzD,OAAO,MAAM,KAAK,EAAE,OAAO,SAAS,QAAQ,KAAK,MAAM,KAAK,OAAO,IAAI,QAAQ,MAAM,EAAE,CAAC,CAAC,KAAK,EAAE;AACpG"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -22,10 +22,6 @@ type MaybePartial<T> = Partial<T> | T;
|
|
|
22
22
|
* Accepts either a mutable value or a readonly view of that value.
|
|
23
23
|
*/
|
|
24
24
|
type MaybeReadonly<T> = Readonly<T> | T;
|
|
25
|
-
/**
|
|
26
|
-
* Explicitly nullable value helper.
|
|
27
|
-
*/
|
|
28
|
-
type Nullable<T> = null | T;
|
|
29
25
|
/**
|
|
30
26
|
* Number-like value represented as a number or a numeric string.
|
|
31
27
|
*/
|
|
@@ -43,5 +39,5 @@ type ReadonlyPartialRecord<K extends keyof any, T> = Readonly<PartialRecord<K, T
|
|
|
43
39
|
*/
|
|
44
40
|
type ReadonlyRecord<K extends keyof any, T> = Readonly<Record<K, T>>;
|
|
45
41
|
//#endregion
|
|
46
|
-
export { AnyRecord, BinaryInput, Booleanish, type FilteredKeyPath, MaybePartial, MaybeReadonly,
|
|
42
|
+
export { AnyRecord, BinaryInput, Booleanish, type FilteredKeyPath, MaybePartial, MaybeReadonly, Numberish, PartialRecord, ReadonlyPartialRecord, ReadonlyRecord };
|
|
47
43
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types/index.ts"],"mappings":";;;;;;AAWA;KAAY,SAAA,GAAY,MAAM;;;AAAA;KAKlB,WAAA,GAAc,WAAA,GAAc,IAAA,GAAO,MAAA,GAAS,IAAA,GAAO,MAAA,GAAW,MAAA,GAAW,UAAA;;;;KAKzE,UAAA;;;;KAKA,YAAA,MAAkB,OAAA,CAAQ,CAAA,IAAK,CAAA;;;;KAK/B,aAAA,MAAmB,QAAA,CAAS,CAAA,IAAK,CAAA;;;;KAKjC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/types/index.ts"],"mappings":";;;;;;AAWA;KAAY,SAAA,GAAY,MAAM;;;AAAA;KAKlB,WAAA,GAAc,WAAA,GAAc,IAAA,GAAO,MAAA,GAAS,IAAA,GAAO,MAAA,GAAW,MAAA,GAAW,UAAA;;;;KAKzE,UAAA;;;;KAKA,YAAA,MAAkB,OAAA,CAAQ,CAAA,IAAK,CAAA;;;;KAK/B,aAAA,MAAmB,QAAA,CAAS,CAAA,IAAK,CAAA;;;;KAKjC,SAAA;;;;KAKA,aAAA,2BAAwC,OAAA,CAAQ,MAAA,CAAO,CAAA,EAAG,CAAA;AApBtE;;;AAAA,KAyBY,qBAAA,2BAAgD,QAAA,CAAS,aAAA,CAAc,CAAA,EAAG,CAAA;AAzBhE;AAKtB;;AALsB,KA8BV,cAAA,2BAAyC,QAAA,CAAS,MAAA,CAAO,CAAA,EAAG,CAAA"}
|
package/dist/types/vue.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Nullable } from "./index.js";
|
|
2
1
|
import { GlobalComponents } from "vue";
|
|
3
2
|
|
|
4
3
|
//#region src/types/vue.d.ts
|
|
@@ -15,7 +14,7 @@ import { GlobalComponents } from "vue";
|
|
|
15
14
|
* const keepAliveRef = ref<ComponentRef<'KeepAlive'>>(null);
|
|
16
15
|
* ```
|
|
17
16
|
*/
|
|
18
|
-
type ComponentRef<K extends keyof GlobalComponents> =
|
|
17
|
+
type ComponentRef<K extends keyof GlobalComponents> = InstanceType<GlobalComponents[K]> | null;
|
|
19
18
|
//#endregion
|
|
20
19
|
export { ComponentRef };
|
|
21
20
|
//# sourceMappingURL=vue.d.ts.map
|
package/dist/types/vue.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue.d.ts","names":[],"sources":["../../src/types/vue.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"vue.d.ts","names":[],"sources":["../../src/types/vue.ts"],"mappings":";;;;;AAeA;;;;;;;;;;;KAAY,YAAA,iBAA6B,gBAAA,IAAoB,YAAA,CAAa,gBAAA,CAAiB,CAAA"}
|
package/dist/url.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.js","names":[],"sources":["../src/url.ts"],"sourcesContent":["/**\n * Appends or updates the `redirect` query parameter on a given URL.\n *\n * Typically used to preserve the user's current path for post-login navigation.\n *\n * @param {string} url - The target URL to modify\n * @param {string} redirectPath - The path to use as the redirect destination\n * (must be a safe same-origin application path starting with `/`)\n *\n * @returns {string} A new URL string with the `redirect` query parameter\n *\n * @throws {Error} If redirectPath is not a safe same-origin application path\n */\nexport function appendRedirectParamToUrl(url: string, redirectPath: string) {\n // eslint-disable-next-line style/max-len\n if (!isSafeRedirectPath(redirectPath)) throw new Error(`Invalid redirect path: \"${redirectPath}\". Redirect paths must be safe same-origin paths starting with '/'.`);\n\n const [baseAndHash, rawQuery = ''] = url.split('?');\n const [base, hash] = (baseAndHash || '').split('#');\n const searchParams = new URLSearchParams(rawQuery);\n searchParams.set('redirect', redirectPath);\n const queryString = searchParams.toString();\n return hash ? `${base}?${queryString}#${hash}` : `${base}?${queryString}`;\n}\n\n/**\n * Returns whether a value is a safe same-origin redirect path.\n *\n * Safe redirect paths are absolute application paths such as `/dashboard`.\n * Protocol-relative URLs (`//example.com`), absolute URLs, backslash paths,\n * and non-string values are rejected.\n *\n * @param {unknown} value - The value to check\n *\n * @returns {boolean} Whether the value is safe to use as an application redirect path\n */\nexport function isSafeRedirectPath(value: unknown): value is string {\n if (typeof value !== 'string') return false;\n if (!value.startsWith('/')) return false;\n if (value.startsWith('//')) return false;\n if (value.includes('\\\\')) return false;\n return true;\n}\n\n/**\n * Normalizes a redirect value into a safe same-origin application path.\n *\n * If an array is provided, the first value is checked. Unsafe values fall back\n * to the provided fallback path.\n *\n * @param {unknown} value - The redirect value to normalize\n * @param {string} fallback - The safe fallback path\n *\n * @returns {string} A safe redirect path\n */\nexport function normalizeRedirectPath(value: unknown, fallback = '/') {\n const redirectPath = Array.isArray(value) ? value[0] : value;\n return isSafeRedirectPath(redirectPath) ? redirectPath : fallback;\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,yBAAyB,KAAa,cAAsB;CAExE,IAAI,CAAC,mBAAmB,YAAY,GAAG,MAAM,IAAI,MAAM,2BAA2B,aAAa,oEAAoE;CAEnK,MAAM,CAAC,aAAa,WAAW,MAAM,IAAI,MAAM,GAAG;CAClD,MAAM,CAAC,MAAM,SAAS,eAAe,
|
|
1
|
+
{"version":3,"file":"url.js","names":[],"sources":["../src/url.ts"],"sourcesContent":["/**\n * Appends or updates the `redirect` query parameter on a given URL.\n *\n * Typically used to preserve the user's current path for post-login navigation.\n *\n * @param {string} url - The target URL to modify\n * @param {string} redirectPath - The path to use as the redirect destination\n * (must be a safe same-origin application path starting with `/`)\n *\n * @returns {string} A new URL string with the `redirect` query parameter\n *\n * @throws {Error} If redirectPath is not a safe same-origin application path\n */\nexport function appendRedirectParamToUrl(url: string, redirectPath: string) {\n // eslint-disable-next-line style/max-len\n if (!isSafeRedirectPath(redirectPath)) throw new Error(`Invalid redirect path: \"${redirectPath}\". Redirect paths must be safe same-origin paths starting with '/'.`);\n\n const [baseAndHash, rawQuery = ''] = url.split('?');\n const [base, hash] = (baseAndHash || '').split('#');\n const searchParams = new URLSearchParams(rawQuery);\n searchParams.set('redirect', redirectPath);\n const queryString = searchParams.toString();\n return hash ? `${base}?${queryString}#${hash}` : `${base}?${queryString}`;\n}\n\n/**\n * Returns whether a value is a safe same-origin redirect path.\n *\n * Safe redirect paths are absolute application paths such as `/dashboard`.\n * Protocol-relative URLs (`//example.com`), absolute URLs, backslash paths,\n * and non-string values are rejected.\n *\n * @param {unknown} value - The value to check\n *\n * @returns {boolean} Whether the value is safe to use as an application redirect path\n */\nexport function isSafeRedirectPath(value: unknown): value is string {\n if (typeof value !== 'string') return false;\n if (!value.startsWith('/')) return false;\n if (value.startsWith('//')) return false;\n if (value.includes('\\\\')) return false;\n return true;\n}\n\n/**\n * Normalizes a redirect value into a safe same-origin application path.\n *\n * If an array is provided, the first value is checked. Unsafe values fall back\n * to the provided fallback path.\n *\n * @param {unknown} value - The redirect value to normalize\n * @param {string} fallback - The safe fallback path\n *\n * @returns {string} A safe redirect path\n */\nexport function normalizeRedirectPath(value: unknown, fallback = '/') {\n const redirectPath = Array.isArray(value) ? value[0] : value;\n return isSafeRedirectPath(redirectPath) ? redirectPath : fallback;\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,yBAAyB,KAAa,cAAsB;CAExE,IAAI,CAAC,mBAAmB,YAAY,GAAG,MAAM,IAAI,MAAM,2BAA2B,aAAa,oEAAoE;CAEnK,MAAM,CAAC,aAAa,WAAW,MAAM,IAAI,MAAM,GAAG;CAClD,MAAM,CAAC,MAAM,SAAS,eAAe,GAAA,CAAI,MAAM,GAAG;CAClD,MAAM,eAAe,IAAI,gBAAgB,QAAQ;CACjD,aAAa,IAAI,YAAY,YAAY;CACzC,MAAM,cAAc,aAAa,SAAS;CAC1C,OAAO,OAAO,GAAG,KAAK,GAAG,YAAY,GAAG,SAAS,GAAG,KAAK,GAAG;AAChE;;;;;;;;;;;;AAaA,SAAgB,mBAAmB,OAAiC;CAChE,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,CAAC,MAAM,WAAW,GAAG,GAAG,OAAO;CACnC,IAAI,MAAM,WAAW,IAAI,GAAG,OAAO;CACnC,IAAI,MAAM,SAAS,IAAI,GAAG,OAAO;CACjC,OAAO;AACX;;;;;;;;;;;;AAaA,SAAgB,sBAAsB,OAAgB,WAAW,KAAK;CAClE,MAAM,eAAe,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK;CACvD,OAAO,mBAAmB,YAAY,IAAI,eAAe;AAC7D"}
|
package/dist/vue.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Nullable } from "./types/index.js";
|
|
2
1
|
import { Ref } from "vue";
|
|
3
2
|
|
|
4
3
|
//#region src/vue.d.ts
|
|
@@ -13,15 +12,15 @@ declare function appendRedirectParamFromCurrentRouteToUrl(url: string): string;
|
|
|
13
12
|
/**
|
|
14
13
|
* Clears an interval referenced by a Vue ref and sets it to null.
|
|
15
14
|
*
|
|
16
|
-
* @param {Ref<
|
|
15
|
+
* @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null
|
|
17
16
|
*/
|
|
18
|
-
declare function clearIntervalRef(intervalRef: Ref<
|
|
17
|
+
declare function clearIntervalRef(intervalRef: Ref<null | ReturnType<typeof setInterval>>): void;
|
|
19
18
|
/**
|
|
20
19
|
* Clears a timeout referenced by a Vue ref and sets it to null.
|
|
21
20
|
*
|
|
22
|
-
* @param {Ref<
|
|
21
|
+
* @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null
|
|
23
22
|
*/
|
|
24
|
-
declare function clearTimeoutRef(timeoutRef: Ref<
|
|
23
|
+
declare function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof setTimeout>>): void;
|
|
25
24
|
/**
|
|
26
25
|
* A Vue composition function that remembers and restores scroll position
|
|
27
26
|
* of a scrollable container across route changes and keep-alive activation.
|
|
@@ -34,9 +33,9 @@ declare function clearTimeoutRef(timeoutRef: Ref<Nullable<ReturnType<typeof setT
|
|
|
34
33
|
*
|
|
35
34
|
* @template T - The type of the scrollable element (defaults to HTMLElement)
|
|
36
35
|
*
|
|
37
|
-
* @param {Ref<
|
|
36
|
+
* @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element
|
|
38
37
|
*/
|
|
39
|
-
declare function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<
|
|
38
|
+
declare function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<null | T>): void;
|
|
40
39
|
//#endregion
|
|
41
40
|
export { appendRedirectParamFromCurrentRouteToUrl, clearIntervalRef, clearTimeoutRef, usePreserveScroll };
|
|
42
41
|
//# sourceMappingURL=vue.d.ts.map
|
package/dist/vue.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue.d.ts","names":[],"sources":["../src/vue.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"vue.d.ts","names":[],"sources":["../src/vue.ts"],"mappings":";;;;;AAgBA;;;;AAAoE;iBAApD,wCAAA,CAAyC,GAAW;;;;;;iBASpD,gBAAA,CAAiB,WAAA,EAAa,GAAA,QAAW,UAAA,QAAkB,WAAA;;;;;;iBAU3D,eAAA,CAAgB,UAAA,EAAY,GAAA,QAAW,UAAA,QAAkB,UAAA;AAVe;AAUxF;;;;;;;;;;;;;AAVwF,iBA6BxE,iBAAA,WAA4B,OAAA,GAAU,WAAA,EAAa,YAAA,EAAc,GAAA,QAAW,CAAA"}
|
package/dist/vue.js
CHANGED
|
@@ -15,7 +15,7 @@ function appendRedirectParamFromCurrentRouteToUrl(url) {
|
|
|
15
15
|
/**
|
|
16
16
|
* Clears an interval referenced by a Vue ref and sets it to null.
|
|
17
17
|
*
|
|
18
|
-
* @param {Ref<
|
|
18
|
+
* @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null
|
|
19
19
|
*/
|
|
20
20
|
function clearIntervalRef(intervalRef) {
|
|
21
21
|
if (intervalRef.value) clearInterval(intervalRef.value);
|
|
@@ -24,7 +24,7 @@ function clearIntervalRef(intervalRef) {
|
|
|
24
24
|
/**
|
|
25
25
|
* Clears a timeout referenced by a Vue ref and sets it to null.
|
|
26
26
|
*
|
|
27
|
-
* @param {Ref<
|
|
27
|
+
* @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null
|
|
28
28
|
*/
|
|
29
29
|
function clearTimeoutRef(timeoutRef) {
|
|
30
30
|
if (timeoutRef.value) clearTimeout(timeoutRef.value);
|
|
@@ -42,7 +42,7 @@ function clearTimeoutRef(timeoutRef) {
|
|
|
42
42
|
*
|
|
43
43
|
* @template T - The type of the scrollable element (defaults to HTMLElement)
|
|
44
44
|
*
|
|
45
|
-
* @param {Ref<
|
|
45
|
+
* @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element
|
|
46
46
|
*/
|
|
47
47
|
function usePreserveScroll(containerRef) {
|
|
48
48
|
let scrollLeft = 0;
|
package/dist/vue.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue.js","names":[],"sources":["../src/vue.ts"],"sourcesContent":["import { onActivated } from 'vue';\nimport type { Ref } from 'vue';\nimport {\n onBeforeRouteLeave,\n useRoute,\n} from 'vue-router';\n\nimport
|
|
1
|
+
{"version":3,"file":"vue.js","names":[],"sources":["../src/vue.ts"],"sourcesContent":["import { onActivated } from 'vue';\nimport type { Ref } from 'vue';\nimport {\n onBeforeRouteLeave,\n useRoute,\n} from 'vue-router';\n\nimport { appendRedirectParamToUrl } from './url';\n\n/**\n * Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.\n *\n * @param {string} url - The base URL to modify\n *\n * @returns {string} A new URL with the current route fullPath as the `redirect` parameter\n */\nexport function appendRedirectParamFromCurrentRouteToUrl(url: string) {\n return appendRedirectParamToUrl(url, useRoute().fullPath);\n}\n\n/**\n * Clears an interval referenced by a Vue ref and sets it to null.\n *\n * @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null\n */\nexport function clearIntervalRef(intervalRef: Ref<null | ReturnType<typeof setInterval>>) {\n if (intervalRef.value) clearInterval(intervalRef.value);\n intervalRef.value = null;\n}\n\n/**\n * Clears a timeout referenced by a Vue ref and sets it to null.\n *\n * @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null\n */\nexport function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof setTimeout>>) {\n if (timeoutRef.value) clearTimeout(timeoutRef.value);\n timeoutRef.value = null;\n}\n\n/**\n * A Vue composition function that remembers and restores scroll position\n * of a scrollable container across route changes and keep-alive activation.\n *\n * Designed for use with `<KeepAlive>` components. Scroll state is saved on\n * route leave and restored when the component is activated again.\n *\n * Note: Without `<KeepAlive>`, the component state is destroyed on unmount,\n * so scroll position will not be preserved.\n *\n * @template T - The type of the scrollable element (defaults to HTMLElement)\n *\n * @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element\n */\nexport function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<null | T>) {\n let scrollLeft = 0;\n let scrollTop = 0;\n onActivated(() => {\n if (!containerRef.value) return;\n containerRef.value.scrollLeft = scrollLeft;\n containerRef.value.scrollTop = scrollTop;\n });\n\n onBeforeRouteLeave(() => {\n scrollLeft = containerRef.value?.scrollLeft || 0;\n scrollTop = containerRef.value?.scrollTop || 0;\n });\n}\n"],"mappings":";;;;;;;;;;;AAgBA,SAAgB,yCAAyC,KAAa;CAClE,OAAO,yBAAyB,KAAK,SAAS,CAAC,CAAC,QAAQ;AAC5D;;;;;;AAOA,SAAgB,iBAAiB,aAAyD;CACtF,IAAI,YAAY,OAAO,cAAc,YAAY,KAAK;CACtD,YAAY,QAAQ;AACxB;;;;;;AAOA,SAAgB,gBAAgB,YAAuD;CACnF,IAAI,WAAW,OAAO,aAAa,WAAW,KAAK;CACnD,WAAW,QAAQ;AACvB;;;;;;;;;;;;;;;AAgBA,SAAgB,kBAAmD,cAA6B;CAC5F,IAAI,aAAa;CACjB,IAAI,YAAY;CAChB,kBAAkB;EACd,IAAI,CAAC,aAAa,OAAO;EACzB,aAAa,MAAM,aAAa;EAChC,aAAa,MAAM,YAAY;CACnC,CAAC;CAED,yBAAyB;EACrB,aAAa,aAAa,OAAO,cAAc;EAC/C,YAAY,aAAa,OAAO,aAAa;CACjD,CAAC;AACL"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "16.0.0",
|
|
5
5
|
"description": "A lightweight and modular utility library for modern JavaScript and TypeScript — includes secure hashing, flexible logging, datetime tools, Vue/web helpers, storage abstraction, and more.",
|
|
6
6
|
"author": "kiki-kanri",
|
|
7
7
|
"license": "MIT",
|
|
@@ -70,18 +70,18 @@
|
|
|
70
70
|
"@noble/hashes": "^2.2.0",
|
|
71
71
|
"@types/ssh2": "^1.15.5",
|
|
72
72
|
"async-validator": "^4.2.5",
|
|
73
|
-
"bson": "^7.
|
|
73
|
+
"bson": "^7.3.1",
|
|
74
74
|
"consola": "^3.4.2",
|
|
75
|
-
"date-fns": "^4.
|
|
75
|
+
"date-fns": "^4.4.0",
|
|
76
76
|
"decimal.js": "^10.6.0",
|
|
77
|
-
"element-plus": "^2.
|
|
78
|
-
"lru-cache": "^11.
|
|
77
|
+
"element-plus": "^2.14.2",
|
|
78
|
+
"lru-cache": "^11.5.2",
|
|
79
79
|
"millify": "^6.1.0",
|
|
80
|
-
"msgpackr": "^2.0.
|
|
80
|
+
"msgpackr": "^2.0.4",
|
|
81
81
|
"node-ssh": "^13.2.1",
|
|
82
82
|
"pino": "^10.3.1",
|
|
83
83
|
"pino-pretty": "^13.1.3",
|
|
84
|
-
"vue": "^3.5.
|
|
84
|
+
"vue": "^3.5.39",
|
|
85
85
|
"vue-router": ">= 4.6.4"
|
|
86
86
|
},
|
|
87
87
|
"peerDependenciesMeta": {
|
|
@@ -135,35 +135,36 @@
|
|
|
135
135
|
}
|
|
136
136
|
},
|
|
137
137
|
"devDependencies": {
|
|
138
|
-
"@antfu/eslint-config": "^9.
|
|
139
|
-
"@kikiutils/eslint-config": "^9.
|
|
140
|
-
"@kikiutils/tsconfigs": "^
|
|
138
|
+
"@antfu/eslint-config": "^9.1.0",
|
|
139
|
+
"@kikiutils/eslint-config": "^9.2.0",
|
|
140
|
+
"@kikiutils/tsconfigs": "^7.0.0",
|
|
141
141
|
"@noble/hashes": "^2.2.0",
|
|
142
|
-
"@types/node": "^
|
|
142
|
+
"@types/node": "^26.1.0",
|
|
143
143
|
"@types/ssh2": "^1.15.5",
|
|
144
|
-
"@vitest/coverage-v8": "^4.1.
|
|
144
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
145
145
|
"async-validator": "^4.2.5",
|
|
146
|
-
"bson": "^7.
|
|
146
|
+
"bson": "^7.3.1",
|
|
147
147
|
"changelogen": "^0.6.2",
|
|
148
148
|
"consola": "^3.4.2",
|
|
149
149
|
"cross-env": "^10.1.0",
|
|
150
|
-
"date-fns": "^4.
|
|
150
|
+
"date-fns": "^4.4.0",
|
|
151
151
|
"decimal.js": "^10.6.0",
|
|
152
|
-
"element-plus": "^2.14.
|
|
152
|
+
"element-plus": "^2.14.2",
|
|
153
|
+
"eslint": "^10.6.0",
|
|
153
154
|
"jsdom": "^29.1.1",
|
|
154
|
-
"knip": "^6.
|
|
155
|
-
"lru-cache": "^11.
|
|
155
|
+
"knip": "^6.25.0",
|
|
156
|
+
"lru-cache": "^11.5.2",
|
|
156
157
|
"millify": "^6.1.0",
|
|
157
|
-
"msgpackr": "^2.0.
|
|
158
|
+
"msgpackr": "^2.0.4",
|
|
158
159
|
"node-ssh": "^13.2.1",
|
|
159
160
|
"pino": "^10.3.1",
|
|
160
161
|
"pino-pretty": "^13.1.3",
|
|
161
162
|
"publint": "^0.3.21",
|
|
162
|
-
"tsdown": "^0.22.
|
|
163
|
+
"tsdown": "^0.22.3",
|
|
163
164
|
"typescript": "^6.0.3",
|
|
164
165
|
"unplugin-unused": "^0.5.7",
|
|
165
|
-
"vitest": "^4.1.
|
|
166
|
-
"vue": "^3.5.
|
|
167
|
-
"vue-router": "^5.0
|
|
166
|
+
"vitest": "^4.1.10",
|
|
167
|
+
"vue": "^3.5.39",
|
|
168
|
+
"vue-router": "^5.1.0"
|
|
168
169
|
}
|
|
169
170
|
}
|
|
@@ -12,8 +12,6 @@ import type {
|
|
|
12
12
|
TransferOptions,
|
|
13
13
|
} from 'ssh2';
|
|
14
14
|
|
|
15
|
-
import type { Nullable } from '../types';
|
|
16
|
-
|
|
17
15
|
import type { PathLike } from './path';
|
|
18
16
|
|
|
19
17
|
const loggerLevelStringToConsolaLogLevelMap = {
|
|
@@ -101,8 +99,8 @@ export class SshClient {
|
|
|
101
99
|
async getFile(
|
|
102
100
|
localFile: PathLike,
|
|
103
101
|
remoteFile: PathLike,
|
|
104
|
-
givenSftp?:
|
|
105
|
-
transferOptions?:
|
|
102
|
+
givenSftp?: null | SFTPWrapper,
|
|
103
|
+
transferOptions?: null | TransferOptions,
|
|
106
104
|
) {
|
|
107
105
|
try {
|
|
108
106
|
await this.#nodeSsh.getFile(localFile.toString(), remoteFile.toString(), givenSftp, transferOptions);
|
|
@@ -141,8 +139,8 @@ export class SshClient {
|
|
|
141
139
|
async putFile(
|
|
142
140
|
localFile: PathLike,
|
|
143
141
|
remoteFile: PathLike,
|
|
144
|
-
givenSftp?:
|
|
145
|
-
transferOptions?:
|
|
142
|
+
givenSftp?: null | SFTPWrapper,
|
|
143
|
+
transferOptions?: null | TransferOptions,
|
|
146
144
|
) {
|
|
147
145
|
try {
|
|
148
146
|
await this.#nodeSsh.putFile(localFile.toString(), remoteFile.toString(), givenSftp, transferOptions);
|
package/src/crypto-hash.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
1
2
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import type {
|
|
3
|
-
BinaryLike,
|
|
4
|
-
BinaryToTextEncoding,
|
|
5
|
-
} from 'node:crypto';
|
|
3
|
+
import type { BinaryLike } from 'node:crypto';
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Computes the MD5 hash of the given data.
|
|
9
7
|
*
|
|
10
8
|
* @param {BinaryLike} data - The input data to hash
|
|
11
|
-
* @param {
|
|
9
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
12
10
|
*
|
|
13
11
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
14
12
|
*
|
|
@@ -19,8 +17,8 @@ import type {
|
|
|
19
17
|
* console.log(cryptoMd5('test')); // 098f6bcd4621d373cade4e832627b4f6
|
|
20
18
|
* ```
|
|
21
19
|
*/
|
|
22
|
-
export function cryptoMd5(data: BinaryLike, outputEncoding:
|
|
23
|
-
return createHash('md5').update(data).digest(outputEncoding);
|
|
20
|
+
export function cryptoMd5(data: BinaryLike, outputEncoding: BufferEncoding = 'hex') {
|
|
21
|
+
return createHash('md5').update(normalizeHashData(data)).digest(outputEncoding);
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
/**
|
|
@@ -38,14 +36,14 @@ export function cryptoMd5(data: BinaryLike, outputEncoding: BinaryToTextEncoding
|
|
|
38
36
|
* ```
|
|
39
37
|
*/
|
|
40
38
|
export function cryptoMd5ToBuffer(data: BinaryLike) {
|
|
41
|
-
return createHash('md5').update(data).digest();
|
|
39
|
+
return createHash('md5').update(normalizeHashData(data)).digest();
|
|
42
40
|
}
|
|
43
41
|
|
|
44
42
|
/**
|
|
45
43
|
* Computes the SHA-3 hash of the given data using the 224-bit digest.
|
|
46
44
|
*
|
|
47
45
|
* @param {BinaryLike} data - The input data to hash
|
|
48
|
-
* @param {
|
|
46
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
49
47
|
*
|
|
50
48
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
51
49
|
*
|
|
@@ -56,8 +54,8 @@ export function cryptoMd5ToBuffer(data: BinaryLike) {
|
|
|
56
54
|
* console.log(cryptoSha3224('test')); // 3797bf0afbbfca4a7bbba7602a2b552746876517a7f9b7ce2db0ae7b
|
|
57
55
|
* ```
|
|
58
56
|
*/
|
|
59
|
-
export function cryptoSha3224(data: BinaryLike, outputEncoding:
|
|
60
|
-
return createHash('sha3-224').update(data).digest(outputEncoding);
|
|
57
|
+
export function cryptoSha3224(data: BinaryLike, outputEncoding: BufferEncoding = 'hex') {
|
|
58
|
+
return createHash('sha3-224').update(normalizeHashData(data)).digest(outputEncoding);
|
|
61
59
|
}
|
|
62
60
|
|
|
63
61
|
/**
|
|
@@ -75,14 +73,14 @@ export function cryptoSha3224(data: BinaryLike, outputEncoding: BinaryToTextEnco
|
|
|
75
73
|
* ```
|
|
76
74
|
*/
|
|
77
75
|
export function cryptoSha3224ToBuffer(data: BinaryLike) {
|
|
78
|
-
return createHash('sha3-224').update(data).digest();
|
|
76
|
+
return createHash('sha3-224').update(normalizeHashData(data)).digest();
|
|
79
77
|
}
|
|
80
78
|
|
|
81
79
|
/**
|
|
82
80
|
* Computes the SHA-3 hash of the given data using the 256-bit digest.
|
|
83
81
|
*
|
|
84
82
|
* @param {BinaryLike} data - The input data to hash
|
|
85
|
-
* @param {
|
|
83
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
86
84
|
*
|
|
87
85
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
88
86
|
*
|
|
@@ -93,8 +91,8 @@ export function cryptoSha3224ToBuffer(data: BinaryLike) {
|
|
|
93
91
|
* console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
|
94
92
|
* ```
|
|
95
93
|
*/
|
|
96
|
-
export function cryptoSha3256(data: BinaryLike, outputEncoding:
|
|
97
|
-
return createHash('sha3-256').update(data).digest(outputEncoding);
|
|
94
|
+
export function cryptoSha3256(data: BinaryLike, outputEncoding: BufferEncoding = 'hex') {
|
|
95
|
+
return createHash('sha3-256').update(normalizeHashData(data)).digest(outputEncoding);
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
/**
|
|
@@ -112,14 +110,14 @@ export function cryptoSha3256(data: BinaryLike, outputEncoding: BinaryToTextEnco
|
|
|
112
110
|
* ```
|
|
113
111
|
*/
|
|
114
112
|
export function cryptoSha3256ToBuffer(data: BinaryLike) {
|
|
115
|
-
return createHash('sha3-256').update(data).digest();
|
|
113
|
+
return createHash('sha3-256').update(normalizeHashData(data)).digest();
|
|
116
114
|
}
|
|
117
115
|
|
|
118
116
|
/**
|
|
119
117
|
* Computes the SHA-3 hash of the given data using the 384-bit digest.
|
|
120
118
|
*
|
|
121
119
|
* @param {BinaryLike} data - The input data to hash
|
|
122
|
-
* @param {
|
|
120
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
123
121
|
*
|
|
124
122
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
125
123
|
*
|
|
@@ -130,8 +128,8 @@ export function cryptoSha3256ToBuffer(data: BinaryLike) {
|
|
|
130
128
|
* console.log(cryptoSha3384('test')); // e516dabb23b6e30026863543282780a3ae0dccf05551cf0295178d7f...
|
|
131
129
|
* ```
|
|
132
130
|
*/
|
|
133
|
-
export function cryptoSha3384(data: BinaryLike, outputEncoding:
|
|
134
|
-
return createHash('sha3-384').update(data).digest(outputEncoding);
|
|
131
|
+
export function cryptoSha3384(data: BinaryLike, outputEncoding: BufferEncoding = 'hex') {
|
|
132
|
+
return createHash('sha3-384').update(normalizeHashData(data)).digest(outputEncoding);
|
|
135
133
|
}
|
|
136
134
|
|
|
137
135
|
/**
|
|
@@ -149,14 +147,14 @@ export function cryptoSha3384(data: BinaryLike, outputEncoding: BinaryToTextEnco
|
|
|
149
147
|
* ```
|
|
150
148
|
*/
|
|
151
149
|
export function cryptoSha3384ToBuffer(data: BinaryLike) {
|
|
152
|
-
return createHash('sha3-384').update(data).digest();
|
|
150
|
+
return createHash('sha3-384').update(normalizeHashData(data)).digest();
|
|
153
151
|
}
|
|
154
152
|
|
|
155
153
|
/**
|
|
156
154
|
* Computes the SHA-3 hash of the given data using the 512-bit digest.
|
|
157
155
|
*
|
|
158
156
|
* @param {BinaryLike} data - The input data to hash
|
|
159
|
-
* @param {
|
|
157
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
160
158
|
*
|
|
161
159
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
162
160
|
*
|
|
@@ -167,8 +165,8 @@ export function cryptoSha3384ToBuffer(data: BinaryLike) {
|
|
|
167
165
|
* console.log(cryptoSha3512('test')); // 9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7...
|
|
168
166
|
* ```
|
|
169
167
|
*/
|
|
170
|
-
export function cryptoSha3512(data: BinaryLike, outputEncoding:
|
|
171
|
-
return createHash('sha3-512').update(data).digest(outputEncoding);
|
|
168
|
+
export function cryptoSha3512(data: BinaryLike, outputEncoding: BufferEncoding = 'hex') {
|
|
169
|
+
return createHash('sha3-512').update(normalizeHashData(data)).digest(outputEncoding);
|
|
172
170
|
}
|
|
173
171
|
|
|
174
172
|
/**
|
|
@@ -186,5 +184,9 @@ export function cryptoSha3512(data: BinaryLike, outputEncoding: BinaryToTextEnco
|
|
|
186
184
|
* ```
|
|
187
185
|
*/
|
|
188
186
|
export function cryptoSha3512ToBuffer(data: BinaryLike) {
|
|
189
|
-
return createHash('sha3-512').update(data).digest();
|
|
187
|
+
return createHash('sha3-512').update(normalizeHashData(data)).digest();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function normalizeHashData(data: BinaryLike): NodeJS.ArrayBufferView | string {
|
|
191
|
+
return typeof data === 'string' || ArrayBuffer.isView(data) ? data : Buffer.from(data);
|
|
190
192
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { Nullable } from '../../types';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Low-level Redis-like adapter interface for raw buffer operations.
|
|
5
3
|
*/
|
|
@@ -12,7 +10,7 @@ export interface RedisLikeAdapter {
|
|
|
12
10
|
/**
|
|
13
11
|
* Gets the raw buffer value for a key.
|
|
14
12
|
*/
|
|
15
|
-
getBuffer: (key: string) => Promise<
|
|
13
|
+
getBuffer: (key: string) => Promise<null | Uint8Array>;
|
|
16
14
|
|
|
17
15
|
/**
|
|
18
16
|
* Checks if a key exists.
|
|
@@ -42,7 +40,7 @@ export interface RedisLikeStorage {
|
|
|
42
40
|
/**
|
|
43
41
|
* Gets a deserialized value by key.
|
|
44
42
|
*/
|
|
45
|
-
getItem: <T = unknown>(key: string) => Promise<
|
|
43
|
+
getItem: <T = unknown>(key: string) => Promise<null | T>;
|
|
46
44
|
|
|
47
45
|
/**
|
|
48
46
|
* Gets the TTL of a key in seconds.
|
package/src/types/index.ts
CHANGED
|
@@ -31,11 +31,6 @@ export type MaybePartial<T> = Partial<T> | T;
|
|
|
31
31
|
*/
|
|
32
32
|
export type MaybeReadonly<T> = Readonly<T> | T;
|
|
33
33
|
|
|
34
|
-
/**
|
|
35
|
-
* Explicitly nullable value helper.
|
|
36
|
-
*/
|
|
37
|
-
export type Nullable<T> = null | T;
|
|
38
|
-
|
|
39
34
|
/**
|
|
40
35
|
* Number-like value represented as a number or a numeric string.
|
|
41
36
|
*/
|