@kikiutils/shared 15.1.0 → 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/buffer.d.ts.map +1 -1
- package/dist/buffer.js.map +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/clipboard.d.ts.map +1 -1
- package/dist/clipboard.js.map +1 -1
- package/dist/consola.d.ts +2 -4
- package/dist/consola.d.ts.map +1 -1
- package/dist/consola.js.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/datetime.d.ts.map +1 -1
- package/dist/datetime.js.map +1 -1
- package/dist/element-plus.d.ts.map +1 -1
- package/dist/element-plus.js.map +1 -1
- package/dist/enum.d.ts.map +1 -1
- package/dist/enum.js.map +1 -1
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js.map +1 -1
- package/dist/event-awaiter.d.ts.map +1 -1
- package/dist/event-awaiter.js.map +1 -1
- package/dist/general.d.ts.map +1 -1
- package/dist/general.js.map +1 -1
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js.map +1 -1
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js.map +1 -1
- package/dist/number.d.ts.map +1 -1
- package/dist/number.js.map +1 -1
- package/dist/object.d.ts.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/pino.js.map +1 -1
- package/dist/random.d.ts.map +1 -1
- package/dist/random.js.map +1 -1
- package/dist/storages/lru/keyed-store.d.ts.map +1 -1
- package/dist/storages/lru/keyed-store.js.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/keyed-store.js.map +1 -1
- package/dist/storages/redis/msgpack.d.ts.map +1 -1
- package/dist/storages/redis/msgpack.js.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.d.ts.map +1 -1
- package/dist/string.js +7 -10
- package/dist/string.js.map +1 -1
- package/dist/time.d.ts.map +1 -1
- package/dist/time.js.map +1 -1
- package/dist/types/filtered-key-path.d.ts.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.d.ts +27 -3
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js +37 -4
- 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/dist/web.d.ts.map +1 -1
- package/dist/web.js.map +1 -1
- package/package.json +24 -23
- 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/url.ts +39 -7
- package/src/vue.ts +6 -7
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ A lightweight, modular TypeScript utility library for Node.js and browser projec
|
|
|
26
26
|
- 🧩 Vue/web helpers — Vue Router redirects, timer ref cleanup, scroll preservation, and browser redirects.
|
|
27
27
|
- 🗄️ Storage helpers — typed keyed-store facades for LRU cache and Redis-like storage.
|
|
28
28
|
- 🛤️ Class utilities — immutable `Path` wrapper and chainable `PrecisionNumber` arithmetic.
|
|
29
|
-
- 🧰 Shared types — reusable
|
|
29
|
+
- 🧰 Shared types — reusable readonly, partial-record, binary-input, and filtered-key-path types.
|
|
30
30
|
|
|
31
31
|
## Requirements
|
|
32
32
|
|
package/dist/buffer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.d.ts","names":[],"sources":["../src/buffer.ts"],"mappings":";;;;;;AAkCA
|
|
1
|
+
{"version":3,"file":"buffer.d.ts","names":[],"sources":["../src/buffer.ts"],"mappings":";;;;;;AAkCA;;;;;;;;;;;;;;;AAAiD;;;;;;;;;;;;;iBAA3B,QAAA,CAAS,KAAA,EAAO,WAAA,GAAW,OAAA,CAAA,MAAA,CAAA,eAAA"}
|
package/dist/buffer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.js","names":[],"sources":["../src/buffer.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\n\nimport type { BinaryInput } from './types';\n\n/**\n * Converts various binary data types to a Node.js Buffer.\n *\n * This function provides a unified, efficient way to convert different binary formats\n * (Blob, Buffer, File, ArrayBuffer, or Uint8Array) into a Node.js Buffer.\n * It prioritizes zero-copy conversions for TypedArrays and ArrayBuffers to ensure\n * optimal performance.\n *\n * @param {ArrayBuffer | Blob | Buffer | File | Uint8Array} input - The binary data input to convert.\n * Supports Blob, Buffer, File, ArrayBuffer, and Uint8Array.\n *\n * @returns {Promise<Buffer>} A promise that resolves to a Node.js Buffer.\n *\n * @example\n * ```typescript\n * import { toBuffer } from '@kikiutils/shared/buffer';\n *\n * // From ArrayBuffer\n * const ab = new ArrayBuffer(8);\n * const bufferFromAB = await toBuffer(ab);\n *\n * // From Uint8Array (Zero-copy)\n * const u8 = new Uint8Array([10, 20, 30]);\n * const bufferFromU8 = await toBuffer(u8);\n *\n * // From Blob or File\n * const blob = new Blob(['data'], { type: 'text/plain' });\n * const bufferFromBlob = await toBuffer(blob);\n * ```\n */\nexport async function toBuffer(input: BinaryInput) {\n if (Buffer.isBuffer(input)) return input;\n if (input instanceof ArrayBuffer) return Buffer.from(input);\n if (input instanceof Uint8Array) return Buffer.from(input.buffer, input.byteOffset, input.byteLength);\n if (typeof input.arrayBuffer === 'function') return Buffer.from(await input.arrayBuffer());\n // eslint-disable-next-line style/max-len\n throw new TypeError('The provided input is not a supported binary type (Blob, Buffer, File, ArrayBuffer, or Uint8Array).');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,eAAsB,SAAS,OAAoB;CAC/C,IAAI,OAAO,SAAS,
|
|
1
|
+
{"version":3,"file":"buffer.js","names":[],"sources":["../src/buffer.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\n\nimport type { BinaryInput } from './types';\n\n/**\n * Converts various binary data types to a Node.js Buffer.\n *\n * This function provides a unified, efficient way to convert different binary formats\n * (Blob, Buffer, File, ArrayBuffer, or Uint8Array) into a Node.js Buffer.\n * It prioritizes zero-copy conversions for TypedArrays and ArrayBuffers to ensure\n * optimal performance.\n *\n * @param {ArrayBuffer | Blob | Buffer | File | Uint8Array} input - The binary data input to convert.\n * Supports Blob, Buffer, File, ArrayBuffer, and Uint8Array.\n *\n * @returns {Promise<Buffer>} A promise that resolves to a Node.js Buffer.\n *\n * @example\n * ```typescript\n * import { toBuffer } from '@kikiutils/shared/buffer';\n *\n * // From ArrayBuffer\n * const ab = new ArrayBuffer(8);\n * const bufferFromAB = await toBuffer(ab);\n *\n * // From Uint8Array (Zero-copy)\n * const u8 = new Uint8Array([10, 20, 30]);\n * const bufferFromU8 = await toBuffer(u8);\n *\n * // From Blob or File\n * const blob = new Blob(['data'], { type: 'text/plain' });\n * const bufferFromBlob = await toBuffer(blob);\n * ```\n */\nexport async function toBuffer(input: BinaryInput) {\n if (Buffer.isBuffer(input)) return input;\n if (input instanceof ArrayBuffer) return Buffer.from(input);\n if (input instanceof Uint8Array) return Buffer.from(input.buffer, input.byteOffset, input.byteLength);\n if (typeof input.arrayBuffer === 'function') return Buffer.from(await input.arrayBuffer());\n // eslint-disable-next-line style/max-len\n throw new TypeError('The provided input is not a supported binary type (Blob, Buffer, File, ArrayBuffer, or Uint8Array).');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,eAAsB,SAAS,OAAoB;CAC/C,IAAI,OAAO,SAAS,KAAK,GAAG,OAAO;CACnC,IAAI,iBAAiB,aAAa,OAAO,OAAO,KAAK,KAAK;CAC1D,IAAI,iBAAiB,YAAY,OAAO,OAAO,KAAK,MAAM,QAAQ,MAAM,YAAY,MAAM,UAAU;CACpG,IAAI,OAAO,MAAM,gBAAgB,YAAY,OAAO,OAAO,KAAK,MAAM,MAAM,YAAY,CAAC;CAEzF,MAAM,IAAI,UAAU,qGAAqG;AAC7H"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.d.ts","names":[],"sources":["../../src/classes/path.ts"],"mappings":";;;;;;;KAmBK,mBAAA,eAAkC,IAAA,iBAAqB,
|
|
1
|
+
{"version":3,"file":"path.d.ts","names":[],"sources":["../../src/classes/path.ts"],"mappings":";;;;;;;KAmBK,mBAAA,eAAkC,IAAA,iBAAqB,UAAU,CAAC,CAAA,8BAA+B,CAAA;;AAF3D;;KAO/B,QAAA,GAAW,EAAA,CAAG,QAAA,GAAW,IAAI;;;;;;;cAQ5B,IAAA;EAAA;EAb0F;AAKvG;;;;iBAgBmB,KAAA,EAAO,QAAA;EAAA,CASrB,MAAA,CAAO,WAAA,EAAa,IAAA;EAzBY;;AAAI;EAAJ,IA4C7B,MAAA,IAAM,IAAA;EApCG;;;EAAA,IA2CT,KAAA;EAPM;;;EAAA,OAgBH,MAAA,CAAO,UAAA,EAAY,QAAA,CAAS,qBAAA,GAAqB,IAAA;EAOrB;;;EAAA,OAA5B,OAAA,IAAW,KAAA,EAAO,QAAA,KAAU,IAAA;EA4CV;;;EAnCzB,QAAA,CAAS,MAAA;EAwDF;;;EAjDP,OAAA,IAAO,IAAA;EAqFwC;;;EA9E/C,OAAA;EAqFe;;;EA9Ef,UAAA;EAqFoD;;;EA9EpD,SAA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CAAG,KAAA;EACd,IAAA,CACI,IAAA,EAAM,EAAA,CAAG,WAAA;IACL,MAAA;EAAA,IAEL,OAAA,CAAQ,EAAA,CAAG,WAAA;EACd,IAAA,CAAK,IAAA,GAAO,EAAA,CAAG,WAAA,GAAc,OAAA,CAAQ,EAAA,CAAG,WAAA,GAAc,EAAA,CAAG,KAAA;EAnLH;;;EA2LtD,QAAA,IAAY,IAAA,EAAM,mBAAA,QAA2B,GAAA,CAAI,QAAA,IAAS,OAAA;EApLX;;;EA2L/C,MAAA,IAAM,OAAA;EApLG;;;EA2LT,SAAA,IAAa,IAAA,EAAM,mBAAA,QAA2B,GAAA,CAAI,SAAA,IAAU,OAAA;AAAA"}
|
package/dist/classes/path.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.js","names":["#value","#toStrings","#newInstance"],"sources":["../../src/classes/path.ts"],"sourcesContent":["import type { Buffer } from 'node:buffer';\nimport type { Abortable } from 'node:events';\nimport type * as fs from 'node:fs';\nimport * as fsp from 'node:fs/promises';\nimport {\n basename,\n dirname,\n extname,\n format,\n isAbsolute,\n join,\n normalize,\n parse,\n relative,\n resolve,\n toNamespacedPath,\n} from 'node:path';\nimport type * as nodePath from 'node:path';\n\ntype DropFirstParameters<T extends (...args: any) => any> = Parameters<T> extends [any, ...infer R] ? R : never;\n\n/**\n * Values accepted by the `Path` constructor and path-composition methods.\n */\nexport type PathLike = fs.PathLike | Path;\n\n/**\n * Class representing a file system path with various utility methods for path operations.\n *\n * All methods in the `Path` class are immutable, returning new instances with modified values\n * and leaving the original instance unchanged.\n */\nexport class Path {\n readonly #value: string;\n\n /**\n * Creates a normalized path value by joining the provided path segments.\n *\n * @param {PathLike[]} paths - Path segments accepted by Node.js `path.join` or another `Path` instance\n */\n constructor(...paths: PathLike[]) {\n this.#value = join(...this.#toStrings(paths));\n }\n\n // Symbols\n [Symbol.for('nodejs.util.inspect.custom')]() {\n return this.#value;\n }\n\n [Symbol.toPrimitive](hint: string) {\n if (hint === 'number') throw new TypeError('Cannot convert a Path to a number');\n return this.#value;\n }\n\n // Private methods\n #newInstance(...paths: PathLike[]) {\n return new Path(...paths);\n }\n\n #toStrings(paths: PathLike[]) {\n return paths.map((path) => path.toString());\n }\n\n // Public getters\n\n /**\n * @see {@link nodePath.dirname}\n */\n get parent() {\n return this.dirname();\n }\n\n /**\n * Returns the internal path string value.\n */\n get value() {\n return this.#value;\n }\n\n // Public static methods\n\n /**\n * @see {@link nodePath.format}\n */\n static format(pathObject: nodePath.FormatInputPathObject) {\n return new Path(format(pathObject));\n }\n\n /**\n * @see {@link nodePath.resolve}\n */\n static resolve(...paths: PathLike[]) {\n return new this(...paths).resolve();\n }\n\n // Public base methods\n\n /**\n * @see {@link nodePath.basename}\n */\n basename(suffix?: string) {\n return basename(this.#value, suffix);\n }\n\n /**\n * @see {@link nodePath.dirname}\n */\n dirname() {\n return this.#newInstance(dirname(this.#value));\n }\n\n /**\n * @see {@link nodePath.extname}\n */\n extname() {\n return extname(this.#value);\n }\n\n /**\n * @see {@link nodePath.isAbsolute}\n */\n isAbsolute() {\n return isAbsolute(this.#value);\n }\n\n /**\n * @see {@link nodePath.normalize}\n */\n normalize() {\n return this.#newInstance(normalize(this.#value));\n }\n\n /**\n * @see {@link nodePath.join}\n */\n join(...paths: PathLike[]) {\n return this.#newInstance(this.#value, ...this.#toStrings(paths));\n }\n\n /**\n * @see {@link nodePath.parse}\n */\n parse() {\n return parse(this.#value);\n }\n\n /**\n * @see {@link nodePath.relative}\n */\n relative(to: PathLike) {\n return this.#newInstance(relative(this.#value, to.toString()));\n }\n\n /**\n * @see {@link nodePath.resolve}\n */\n resolve() {\n return this.#newInstance(resolve(this.#value));\n }\n\n toJSON() {\n return this.#value;\n }\n\n /**\n * @see {@link nodePath.toNamespacedPath}\n */\n toNamespacedPath() {\n return toNamespacedPath(this.#value);\n }\n\n /**\n * Converts the Path instance to a string.\n * This method returns the internal path string value,\n * making it useful for implicit and explicit string conversions.\n */\n toString() {\n return this.#value;\n }\n\n // Some commonly used promise fs methods\n\n /**\n * @see {@link fsp.access}\n */\n access(...args: DropFirstParameters<typeof fsp.access>) {\n return fsp.access(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.appendFile}\n */\n appendFile(...args: DropFirstParameters<typeof fsp.appendFile>) {\n return fsp.appendFile(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.chmod}\n */\n chmod(...args: DropFirstParameters<typeof fsp.chmod>) {\n return fsp.chmod(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.chown}\n */\n chown(...args: DropFirstParameters<typeof fsp.chown>) {\n return fsp.chown(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.copyFile}\n */\n copyFile(...args: DropFirstParameters<typeof fsp.copyFile>) {\n return fsp.copyFile(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.mkdir}\n */\n mkdir(\n options: fs.MakeDirectoryOptions & {\n recursive: true;\n },\n ): Promise<string>;\n mkdir(\n options?:\n | (fs.MakeDirectoryOptions & {\n recursive?: false;\n })\n | fs.Mode\n | null,\n ): Promise<void>;\n mkdir(options?: fs.MakeDirectoryOptions | fs.Mode | null): Promise<string | undefined>;\n mkdir(...args: any): any {\n return fsp.mkdir(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.open}\n */\n open(...args: DropFirstParameters<typeof fsp.open>) {\n return fsp.open(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.readdir}\n */\n readdir(\n path: PathLike,\n options?:\n | BufferEncoding\n | (fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes?: false;\n })\n | null,\n ): Promise<string[]>;\n readdir(\n path: PathLike,\n options:\n | 'buffer'\n | {\n encoding: 'buffer';\n recursive?: boolean;\n withFileTypes?: false;\n },\n ): Promise<Buffer[]>;\n readdir(\n path: PathLike,\n options?:\n | BufferEncoding\n | (fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes?: false;\n })\n | null,\n ): Promise<Buffer[] | string[]>;\n readdir(\n path: PathLike,\n options: fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes: true;\n },\n ): Promise<fs.Dirent[]>;\n readdir(\n path: PathLike,\n options: {\n encoding: 'buffer';\n recursive?: boolean;\n withFileTypes: true;\n },\n ): Promise<fs.Dirent<Buffer>[]>;\n readdir(...args: any): any {\n return fsp.readdir(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.readFile}\n */\n readFile(\n options?:\n | (Abortable & {\n encoding?: null;\n flag?: fs.OpenMode;\n })\n | null,\n ): Promise<Buffer>;\n readFile(\n options:\n | (Abortable & {\n encoding: BufferEncoding;\n flag?: fs.OpenMode;\n })\n | BufferEncoding,\n ): Promise<string>;\n readFile(\n options?:\n | (\n & Abortable\n & fs.ObjectEncodingOptions\n & { flag?: fs.OpenMode }\n )\n | BufferEncoding\n | null,\n ): Promise<Buffer | string>;\n readFile(...args: any): any {\n return fsp.readFile(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.rename}\n */\n rename(newPath: PathLike) {\n return fsp.rename(this.#value, newPath.toString());\n }\n\n /**\n * @see {@link fsp.rm}\n */\n rm(...args: DropFirstParameters<typeof fsp.rm>) {\n return fsp.rm(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.rmdir}\n */\n rmdir(...args: DropFirstParameters<typeof fsp.rmdir>) {\n return fsp.rmdir(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.stat}\n */\n stat(\n opts?: fs.StatOptions & {\n bigint?: false;\n },\n ): Promise<fs.Stats>;\n stat(\n opts: fs.StatOptions & {\n bigint: true;\n },\n ): Promise<fs.BigIntStats>;\n stat(opts?: fs.StatOptions): Promise<fs.BigIntStats | fs.Stats>;\n stat(...args: any): any {\n return fsp.stat(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.truncate}\n */\n truncate(...args: DropFirstParameters<typeof fsp.truncate>) {\n return fsp.truncate(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.unlink}\n */\n unlink() {\n return fsp.unlink(this.#value);\n }\n\n /**\n * @see {@link fsp.writeFile}\n */\n writeFile(...args: DropFirstParameters<typeof fsp.writeFile>) {\n return fsp.writeFile(this.#value, ...args);\n }\n}\n"],"mappings":";;;;;;;;;AAgCA,IAAa,OAAb,MAAa,KAAK;CACd;;;;;;CAOA,YAAY,GAAG,OAAmB;EAC9B,KAAKA,SAAS,KAAK,GAAG,KAAKC,WAAW,MAAM,CAAC;;CAIjD,CAAC,OAAO,IAAI,6BAA6B,IAAI;EACzC,OAAO,KAAKD;;CAGhB,CAAC,OAAO,aAAa,MAAc;EAC/B,IAAI,SAAS,UAAU,MAAM,IAAI,UAAU,oCAAoC;EAC/E,OAAO,KAAKA;;CAIhB,aAAa,GAAG,OAAmB;EAC/B,OAAO,IAAI,KAAK,GAAG,MAAM;;CAG7B,WAAW,OAAmB;EAC1B,OAAO,MAAM,KAAK,SAAS,KAAK,UAAU,CAAC;;;;;CAQ/C,IAAI,SAAS;EACT,OAAO,KAAK,SAAS;;;;;CAMzB,IAAI,QAAQ;EACR,OAAO,KAAKA;;;;;CAQhB,OAAO,OAAO,YAA4C;EACtD,OAAO,IAAI,KAAK,OAAO,WAAW,CAAC;;;;;CAMvC,OAAO,QAAQ,GAAG,OAAmB;EACjC,OAAO,IAAI,KAAK,GAAG,MAAM,CAAC,SAAS;;;;;CAQvC,SAAS,QAAiB;EACtB,OAAO,SAAS,KAAKA,QAAQ,OAAO;;;;;CAMxC,UAAU;EACN,OAAO,KAAKE,aAAa,QAAQ,KAAKF,OAAO,CAAC;;;;;CAMlD,UAAU;EACN,OAAO,QAAQ,KAAKA,OAAO;;;;;CAM/B,aAAa;EACT,OAAO,WAAW,KAAKA,OAAO;;;;;CAMlC,YAAY;EACR,OAAO,KAAKE,aAAa,UAAU,KAAKF,OAAO,CAAC;;;;;CAMpD,KAAK,GAAG,OAAmB;EACvB,OAAO,KAAKE,aAAa,KAAKF,QAAQ,GAAG,KAAKC,WAAW,MAAM,CAAC;;;;;CA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;CAMvC,MAAM,GAAG,MAA6C;EAClD,OAAO,IAAI,MAAM,KAAKA,QAAQ,GAAG,KAAK;;CAiB1C,KAAK,GAAG,MAAgB;EACpB,OAAO,IAAI,KAAK,KAAKA,QAAQ,GAAG,KAAK;;;;;CAMzC,SAAS,GAAG,MAAgD;EACxD,OAAO,IAAI,SAAS,KAAKA,QAAQ,GAAG,KAAK;;;;;CAM7C,SAAS;EACL,OAAO,IAAI,OAAO,KAAKA,OAAO;;;;;CAMlC,UAAU,GAAG,MAAiD;EAC1D,OAAO,IAAI,UAAU,KAAKA,QAAQ,GAAG,KAAK"}
|
|
1
|
+
{"version":3,"file":"path.js","names":["#value","#toStrings","#newInstance"],"sources":["../../src/classes/path.ts"],"sourcesContent":["import type { Buffer } from 'node:buffer';\nimport type { Abortable } from 'node:events';\nimport type * as fs from 'node:fs';\nimport * as fsp from 'node:fs/promises';\nimport {\n basename,\n dirname,\n extname,\n format,\n isAbsolute,\n join,\n normalize,\n parse,\n relative,\n resolve,\n toNamespacedPath,\n} from 'node:path';\nimport type * as nodePath from 'node:path';\n\ntype DropFirstParameters<T extends (...args: any) => any> = Parameters<T> extends [any, ...infer R] ? R : never;\n\n/**\n * Values accepted by the `Path` constructor and path-composition methods.\n */\nexport type PathLike = fs.PathLike | Path;\n\n/**\n * Class representing a file system path with various utility methods for path operations.\n *\n * All methods in the `Path` class are immutable, returning new instances with modified values\n * and leaving the original instance unchanged.\n */\nexport class Path {\n readonly #value: string;\n\n /**\n * Creates a normalized path value by joining the provided path segments.\n *\n * @param {PathLike[]} paths - Path segments accepted by Node.js `path.join` or another `Path` instance\n */\n constructor(...paths: PathLike[]) {\n this.#value = join(...this.#toStrings(paths));\n }\n\n // Symbols\n [Symbol.for('nodejs.util.inspect.custom')]() {\n return this.#value;\n }\n\n [Symbol.toPrimitive](hint: string) {\n if (hint === 'number') throw new TypeError('Cannot convert a Path to a number');\n return this.#value;\n }\n\n // Private methods\n #newInstance(...paths: PathLike[]) {\n return new Path(...paths);\n }\n\n #toStrings(paths: PathLike[]) {\n return paths.map((path) => path.toString());\n }\n\n // Public getters\n\n /**\n * @see {@link nodePath.dirname}\n */\n get parent() {\n return this.dirname();\n }\n\n /**\n * Returns the internal path string value.\n */\n get value() {\n return this.#value;\n }\n\n // Public static methods\n\n /**\n * @see {@link nodePath.format}\n */\n static format(pathObject: nodePath.FormatInputPathObject) {\n return new Path(format(pathObject));\n }\n\n /**\n * @see {@link nodePath.resolve}\n */\n static resolve(...paths: PathLike[]) {\n return new this(...paths).resolve();\n }\n\n // Public base methods\n\n /**\n * @see {@link nodePath.basename}\n */\n basename(suffix?: string) {\n return basename(this.#value, suffix);\n }\n\n /**\n * @see {@link nodePath.dirname}\n */\n dirname() {\n return this.#newInstance(dirname(this.#value));\n }\n\n /**\n * @see {@link nodePath.extname}\n */\n extname() {\n return extname(this.#value);\n }\n\n /**\n * @see {@link nodePath.isAbsolute}\n */\n isAbsolute() {\n return isAbsolute(this.#value);\n }\n\n /**\n * @see {@link nodePath.normalize}\n */\n normalize() {\n return this.#newInstance(normalize(this.#value));\n }\n\n /**\n * @see {@link nodePath.join}\n */\n join(...paths: PathLike[]) {\n return this.#newInstance(this.#value, ...this.#toStrings(paths));\n }\n\n /**\n * @see {@link nodePath.parse}\n */\n parse() {\n return parse(this.#value);\n }\n\n /**\n * @see {@link nodePath.relative}\n */\n relative(to: PathLike) {\n return this.#newInstance(relative(this.#value, to.toString()));\n }\n\n /**\n * @see {@link nodePath.resolve}\n */\n resolve() {\n return this.#newInstance(resolve(this.#value));\n }\n\n toJSON() {\n return this.#value;\n }\n\n /**\n * @see {@link nodePath.toNamespacedPath}\n */\n toNamespacedPath() {\n return toNamespacedPath(this.#value);\n }\n\n /**\n * Converts the Path instance to a string.\n * This method returns the internal path string value,\n * making it useful for implicit and explicit string conversions.\n */\n toString() {\n return this.#value;\n }\n\n // Some commonly used promise fs methods\n\n /**\n * @see {@link fsp.access}\n */\n access(...args: DropFirstParameters<typeof fsp.access>) {\n return fsp.access(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.appendFile}\n */\n appendFile(...args: DropFirstParameters<typeof fsp.appendFile>) {\n return fsp.appendFile(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.chmod}\n */\n chmod(...args: DropFirstParameters<typeof fsp.chmod>) {\n return fsp.chmod(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.chown}\n */\n chown(...args: DropFirstParameters<typeof fsp.chown>) {\n return fsp.chown(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.copyFile}\n */\n copyFile(...args: DropFirstParameters<typeof fsp.copyFile>) {\n return fsp.copyFile(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.mkdir}\n */\n mkdir(\n options: fs.MakeDirectoryOptions & {\n recursive: true;\n },\n ): Promise<string>;\n mkdir(\n options?:\n | (fs.MakeDirectoryOptions & {\n recursive?: false;\n })\n | fs.Mode\n | null,\n ): Promise<void>;\n mkdir(options?: fs.MakeDirectoryOptions | fs.Mode | null): Promise<string | undefined>;\n mkdir(...args: any): any {\n return fsp.mkdir(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.open}\n */\n open(...args: DropFirstParameters<typeof fsp.open>) {\n return fsp.open(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.readdir}\n */\n readdir(\n path: PathLike,\n options?:\n | BufferEncoding\n | (fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes?: false;\n })\n | null,\n ): Promise<string[]>;\n readdir(\n path: PathLike,\n options:\n | 'buffer'\n | {\n encoding: 'buffer';\n recursive?: boolean;\n withFileTypes?: false;\n },\n ): Promise<Buffer[]>;\n readdir(\n path: PathLike,\n options?:\n | BufferEncoding\n | (fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes?: false;\n })\n | null,\n ): Promise<Buffer[] | string[]>;\n readdir(\n path: PathLike,\n options: fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes: true;\n },\n ): Promise<fs.Dirent[]>;\n readdir(\n path: PathLike,\n options: {\n encoding: 'buffer';\n recursive?: boolean;\n withFileTypes: true;\n },\n ): Promise<fs.Dirent<Buffer>[]>;\n readdir(...args: any): any {\n return fsp.readdir(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.readFile}\n */\n readFile(\n options?:\n | (Abortable & {\n encoding?: null;\n flag?: fs.OpenMode;\n })\n | null,\n ): Promise<Buffer>;\n readFile(\n options:\n | (Abortable & {\n encoding: BufferEncoding;\n flag?: fs.OpenMode;\n })\n | BufferEncoding,\n ): Promise<string>;\n readFile(\n options?:\n | (\n & Abortable\n & fs.ObjectEncodingOptions\n & { flag?: fs.OpenMode }\n )\n | BufferEncoding\n | null,\n ): Promise<Buffer | string>;\n readFile(...args: any): any {\n return fsp.readFile(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.rename}\n */\n rename(newPath: PathLike) {\n return fsp.rename(this.#value, newPath.toString());\n }\n\n /**\n * @see {@link fsp.rm}\n */\n rm(...args: DropFirstParameters<typeof fsp.rm>) {\n return fsp.rm(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.rmdir}\n */\n rmdir(...args: DropFirstParameters<typeof fsp.rmdir>) {\n return fsp.rmdir(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.stat}\n */\n stat(\n opts?: fs.StatOptions & {\n bigint?: false;\n },\n ): Promise<fs.Stats>;\n stat(\n opts: fs.StatOptions & {\n bigint: true;\n },\n ): Promise<fs.BigIntStats>;\n stat(opts?: fs.StatOptions): Promise<fs.BigIntStats | fs.Stats>;\n stat(...args: any): any {\n return fsp.stat(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.truncate}\n */\n truncate(...args: DropFirstParameters<typeof fsp.truncate>) {\n return fsp.truncate(this.#value, ...args);\n }\n\n /**\n * @see {@link fsp.unlink}\n */\n unlink() {\n return fsp.unlink(this.#value);\n }\n\n /**\n * @see {@link fsp.writeFile}\n */\n writeFile(...args: DropFirstParameters<typeof fsp.writeFile>) {\n return fsp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AAKA,QAAQ,GAAG,IAAI;CACtC;;;;CAKA,MAAM,GAAG,MAA6C;EAClD,OAAO,IAAI,MAAM,KAAKA,QAAQ,GAAG,IAAI;CACzC;CAgBA,KAAK,GAAG,MAAgB;EACpB,OAAO,IAAI,KAAK,KAAKA,QAAQ,GAAG,IAAI;CACxC;;;;CAKA,SAAS,GAAG,MAAgD;EACxD,OAAO,IAAI,SAAS,KAAKA,QAAQ,GAAG,IAAI;CAC5C;;;;CAKA,SAAS;EACL,OAAO,IAAI,OAAO,KAAKA,MAAM;CACjC;;;;CAKA,UAAU,GAAG,MAAiD;EAC1D,OAAO,IAAI,UAAU,KAAKA,QAAQ,GAAG,IAAI;CAC7C;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"precision-number.d.ts","names":[],"sources":["../../src/classes/precision-number.ts"],"mappings":";;;;;AAKA;KAAY,oBAAA,GAAuB,OAAA,CAAQ,KAAA,GAAQ,
|
|
1
|
+
{"version":3,"file":"precision-number.d.ts","names":[],"sources":["../../src/classes/precision-number.ts"],"mappings":";;;;;AAKA;KAAY,oBAAA,GAAuB,OAAA,CAAQ,KAAA,GAAQ,eAAe;EAAK,QAAA;AAAA;;;;;;AAAQ;AAqB/E;;;;;;;;;;;;;cAAa,eAAA;EAAA;EAyLE;;;;;;;cA3KP,KAAA,GAAO,oBAAA,EACP,aAAA,WACA,QAAA,GAAU,OAAA,CAAQ,QAAA;EAgSP;;;;;EAAA,CA3Qd,MAAA,CAAO,WAAA,EAAa,IAAA;EAqSkB;;;EAAA,IAlRnC,aAAA;EAsTY;;;EAAA,IA/SZ,QAAA,IAAQ,OAAA,CAAA,QAAA;EAiUsB;;;EAAA,IA1T9B,KAAA;EA+VW;;;;;;;;;EAAA,OAlVR,OAAA,CACH,KAAA,EAAO,oBAAA,EACP,aAAA,WACA,QAAA,GAAU,OAAA,CAAQ,QAAA;EAtEA;;;;;EAkFtB,aAAA;EAnCI;;;;;;;EA+CJ,IAAA;EAx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;;;EAOT,MAAA,CAAO,KAAA,EAAO,oBAAA,GAAoB,eAAA;;;;EAOlC,KAAA,CAAM,KAAA,EAAO,oBAAA,GAAoB,eAAA;;;;;;EASjC,QAAA;;;;EAOA,QAAA;;;;EAOA,OAAA,CAAQ,aAAA,WAA6C,QAAA,GAAU,OAAA,CAAQ,QAAA;;;;EAOvE,OAAA,CAAQ,KAAA,EAAO,oBAAA,GAAoB,eAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"precision-number.js","names":["#decimalPlaces","#rounding","#decimal","#decimalToFixedDecimal","#valueToString"],"sources":["../../src/classes/precision-number.ts"],"sourcesContent":["import { Decimal } from 'decimal.js';\n\n/**\n * Values accepted by `PrecisionNumber` constructors and arithmetic methods.\n */\nexport type PrecisionNumberValue = Decimal.Value | PrecisionNumber | { toString: () => string };\n\n/**\n * Chainable fixed-decimal wrapper around `decimal.js`.\n *\n * `PrecisionNumber` stores values as `Decimal`, rounds every mutating operation to\n * the configured decimal places, and exposes both mutable and immutable arithmetic\n * methods. Mutable methods (`plus`, `minus`, `times`, `dividedBy`, `modulo`,\n * `pow`, `clamp`, `ceil`, `floor`, `negate`, `absoluteValue`) update the current\n * instance and return `this`; immutable methods prefixed with `to` return a new\n * `PrecisionNumber` with the same precision settings.\n *\n * @example\n * ```typescript\n * import { PrecisionNumber } from '@kikiutils/shared/classes/precision-number';\n *\n * const value = new PrecisionNumber('1.239', 2).plus('2.111');\n * value.toString(); // '3.35'\n * value.toMinus('1').toString(); // '2.35' (original value remains '3.35')\n * ```\n */\nexport class PrecisionNumber {\n // Private properties\n readonly #decimalPlaces: number;\n readonly #rounding: Decimal.Rounding;\n #decimal: Decimal;\n\n /**\n * Creates a fixed-decimal number.\n *\n * @param {PrecisionNumberValue} [value] - Initial value (default: `'0'`)\n * @param {number} [decimalPlaces] - Decimal places retained after operations (default: `2`)\n * @param {Decimal.Rounding} [rounding] - Decimal.js rounding mode (default: `Decimal.ROUND_DOWN`)\n */\n constructor(\n value: PrecisionNumberValue = '0',\n decimalPlaces: number = 2,\n rounding: Decimal.Rounding = Decimal.ROUND_DOWN,\n ) {\n this.#decimalPlaces = decimalPlaces;\n this.#rounding = rounding;\n this.#decimal = this.#decimalToFixedDecimal(new Decimal(value.toString().trim()));\n }\n\n // Symbols\n\n /**\n * Returns the formatted value when inspected by Node.js utilities.\n */\n [Symbol.for('nodejs.util.inspect.custom')]() {\n return this.value;\n }\n\n /**\n * Converts to a number for numeric coercion and to the fixed string otherwise.\n *\n * @param {string} hint - JavaScript primitive-conversion hint\n */\n [Symbol.toPrimitive](hint: string) {\n if (hint === 'number') return this.#decimal.toNumber();\n return this.value;\n }\n\n // Private methods\n #decimalToFixedDecimal(decimal: Decimal) {\n return decimal.toDecimalPlaces(this.#decimalPlaces, this.#rounding);\n }\n\n #valueToString(value: PrecisionNumberValue) {\n return value.toString().trim();\n }\n\n // Public getters\n\n /**\n * Decimal places retained by mutating operations and default formatting.\n */\n get decimalPlaces() {\n return this.#decimalPlaces;\n }\n\n /**\n * Decimal.js rounding mode used by mutating operations and default formatting.\n */\n get rounding() {\n return this.#rounding;\n }\n\n /**\n * Fixed-decimal string using the instance precision and rounding mode.\n */\n get value() {\n return this.#decimal.toFixed(this.#decimalPlaces, this.#rounding);\n }\n\n /**\n * Formats a value with decimal.js without creating a reusable instance.\n *\n * @param {PrecisionNumberValue} value - Value to format\n * @param {number} [decimalPlaces] - Decimal places to output (default: `2`)\n * @param {Decimal.Rounding} [rounding] - Decimal.js rounding mode (default: `Decimal.ROUND_DOWN`)\n *\n * @returns {string} Fixed-decimal string\n */\n static toFixed(\n value: PrecisionNumberValue,\n decimalPlaces: number = 2,\n rounding: Decimal.Rounding = Decimal.ROUND_DOWN,\n ) {\n return new Decimal(value.toString().trim()).toFixed(decimalPlaces, rounding);\n }\n\n // Public methods\n\n /**\n * Replaces the current value with its absolute value.\n *\n * @returns {this} The current instance for chaining\n */\n absoluteValue() {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.absoluteValue());\n return this;\n }\n\n /**\n * Rounds the current value up to the nearest integer in place.\n *\n * The stored value still uses this instance's configured decimal places for output.\n *\n * @returns {this} The current instance for chaining\n */\n ceil() {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.ceil());\n return this;\n }\n\n /**\n * Restricts the current value to the inclusive range `[min, max]` in place.\n *\n * @param {PrecisionNumberValue} min - Lower bound\n * @param {PrecisionNumberValue} max - Upper bound\n *\n * @returns {this} The current instance for chaining\n *\n * @throws {Error} If `min` is greater than `max`\n */\n clamp(min: PrecisionNumberValue, max: PrecisionNumberValue) {\n const minDecimal = new Decimal(this.#valueToString(min));\n const maxDecimal = new Decimal(this.#valueToString(max));\n if (minDecimal.gt(maxDecimal)) throw new Error('Invalid clamp range: min cannot be greater than max');\n this.#decimal = this.#decimalToFixedDecimal(Decimal.min(Decimal.max(this.#decimal, minDecimal), maxDecimal));\n return this;\n }\n\n /**\n * Returns a new instance with the same value, decimal places, and rounding mode.\n */\n clone() {\n return new PrecisionNumber(this.#decimal, this.#decimalPlaces, this.#rounding);\n }\n\n /**\n * Divides the current value by another value in place.\n *\n * @param {PrecisionNumberValue} value - Divisor\n *\n * @returns {this} The current instance for chaining\n */\n dividedBy(value: PrecisionNumberValue) {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.dividedBy(this.#valueToString(value)));\n return this;\n }\n\n /**\n * Checks whether the current value equals another value.\n *\n * @param {PrecisionNumberValue} value - Value to compare\n *\n * @returns {boolean} `true` when both numeric values are equal\n */\n equals(value: PrecisionNumberValue) {\n return this.#decimal.equals(this.#valueToString(value));\n }\n\n /**\n * Rounds the current value down to the nearest integer in place.\n *\n * The stored value still uses this instance's configured decimal places for output.\n *\n * @returns {this} The current instance for chaining\n */\n floor() {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.floor());\n return this;\n }\n\n /**\n * Checks whether the current value is greater than another value.\n */\n gt(value: PrecisionNumberValue) {\n return this.#decimal.gt(this.#valueToString(value));\n }\n\n /**\n * Checks whether the current value is greater than or equal to another value.\n */\n gte(value: PrecisionNumberValue) {\n return this.#decimal.gte(this.#valueToString(value));\n }\n\n /**\n * Checks whether the current value is finite.\n */\n isFinite() {\n return this.#decimal.isFinite();\n }\n\n /**\n * Checks whether the current value is an integer.\n */\n isInteger() {\n return this.#decimal.isInteger();\n }\n\n /**\n * Checks whether the current value is `NaN`.\n */\n isNaN() {\n return this.#decimal.isNaN();\n }\n\n /**\n * Checks whether the current value is negative.\n */\n isNegative() {\n return this.#decimal.isNegative();\n }\n\n /**\n * Checks whether the current value is positive.\n */\n isPositive() {\n return this.#decimal.isPositive();\n }\n\n /**\n * Checks whether the current value is zero.\n */\n isZero() {\n return this.#decimal.isZero();\n }\n\n /**\n * Checks whether the current value is less than another value.\n */\n lt(value: PrecisionNumberValue) {\n return this.#decimal.lt(this.#valueToString(value));\n }\n\n /**\n * Checks whether the current value is less than or equal to another value.\n */\n lte(value: PrecisionNumberValue) {\n return this.#decimal.lte(this.#valueToString(value));\n }\n\n /**\n * Subtracts another value from the current value in place.\n */\n minus(value: PrecisionNumberValue) {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.minus(this.#valueToString(value)));\n return this;\n }\n\n /**\n * Replaces the current value with the remainder after division by another value.\n *\n * @param {PrecisionNumberValue} value - Divisor used to compute the remainder\n *\n * @returns {this} The current instance for chaining\n */\n modulo(value: PrecisionNumberValue) {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.modulo(this.#valueToString(value)));\n return this;\n }\n\n /**\n * Negates the current value in place.\n */\n negate() {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.negated());\n return this;\n }\n\n /**\n * Adds another value to the current value in place.\n */\n plus(value: PrecisionNumberValue) {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.plus(this.#valueToString(value)));\n return this;\n }\n\n /**\n * Raises the current value to an exponent in place.\n *\n * @param {PrecisionNumberValue} value - Exponent\n *\n * @returns {this} The current instance for chaining\n */\n pow(value: PrecisionNumberValue) {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.pow(this.#valueToString(value)));\n return this;\n }\n\n /**\n * Multiplies the current value by another value in place.\n */\n times(value: PrecisionNumberValue) {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.times(this.#valueToString(value)));\n return this;\n }\n\n /**\n * Returns a new instance with the absolute value.\n */\n toAbsoluteValue() {\n return new PrecisionNumber(this.#decimal.absoluteValue(), this.#decimalPlaces, this.#rounding);\n }\n\n /**\n * Returns a new instance rounded up to the nearest integer.\n */\n toCeil() {\n return new PrecisionNumber(this.#decimal.ceil(), this.#decimalPlaces, this.#rounding);\n }\n\n /**\n * Returns a new instance restricted to the inclusive range `[min, max]`.\n *\n * @param {PrecisionNumberValue} min - Lower bound\n * @param {PrecisionNumberValue} max - Upper bound\n *\n * @throws {Error} If `min` is greater than `max`\n */\n toClamped(min: PrecisionNumberValue, max: PrecisionNumberValue) {\n return this.clone().clamp(min, max);\n }\n\n /**\n * Returns a new instance divided by another value.\n */\n toDividedBy(value: PrecisionNumberValue) {\n return new PrecisionNumber(\n this.#decimal.dividedBy(this.#valueToString(value)),\n this.#decimalPlaces,\n this.#rounding,\n );\n }\n\n /**\n * Returns a new instance rounded down to the nearest integer.\n */\n toFloor() {\n return new PrecisionNumber(this.#decimal.floor(), this.#decimalPlaces, this.#rounding);\n }\n\n /**\n * Serializes to the fixed-decimal string.\n */\n toJSON() {\n return this.value;\n }\n\n /**\n * Returns a new instance with another value subtracted.\n */\n toMinus(value: PrecisionNumberValue) {\n return new PrecisionNumber(\n this.#decimal.minus(this.#valueToString(value)),\n this.#decimalPlaces,\n this.#rounding,\n );\n }\n\n /**\n * Returns a new instance with the remainder after division by another value.\n */\n toModulo(value: PrecisionNumberValue) {\n return new PrecisionNumber(\n this.#decimal.modulo(this.#valueToString(value)),\n this.#decimalPlaces,\n this.#rounding,\n );\n }\n\n /**\n * Returns a new instance with the value negated.\n */\n toNegated() {\n return new PrecisionNumber(this.#decimal.negated(), this.#decimalPlaces, this.#rounding);\n }\n\n /**\n * Returns a new instance with another value added.\n */\n toPlus(value: PrecisionNumberValue) {\n return new PrecisionNumber(this.#decimal.plus(this.#valueToString(value)), this.#decimalPlaces, this.#rounding);\n }\n\n /**\n * Returns a new instance raised to an exponent.\n */\n toPow(value: PrecisionNumberValue) {\n return new PrecisionNumber(this.#decimal.pow(this.#valueToString(value)), this.#decimalPlaces, this.#rounding);\n }\n\n /**\n * Converts the current value to a JavaScript number.\n *\n * Use `toString`/`value` when preserving decimal precision is more important than native-number ergonomics.\n */\n toNumber() {\n return this.#decimal.toNumber();\n }\n\n /**\n * Converts the current value to its fixed-decimal string.\n */\n toString() {\n return this.value;\n }\n\n /**\n * Formats the current value with custom precision and rounding for this call only.\n */\n toFixed(decimalPlaces: number = this.#decimalPlaces, rounding: Decimal.Rounding = this.#rounding) {\n return this.#decimal.toFixed(decimalPlaces, rounding);\n }\n\n /**\n * Returns a new instance multiplied by another value.\n */\n toTimes(value: PrecisionNumberValue) {\n return new PrecisionNumber(\n this.#decimal.times(this.#valueToString(value)),\n this.#decimalPlaces,\n this.#rounding,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,kBAAb,MAAa,gBAAgB;CAEzB;CACA;CACA;;;;;;;;CASA,YACI,QAA8B,KAC9B,gBAAwB,GACxB,WAA6B,QAAQ,YACvC;EACE,KAAKA,iBAAiB;EACtB,KAAKC,YAAY;EACjB,KAAKC,WAAW,KAAKC,uBAAuB,IAAI,QAAQ,MAAM,UAAU,CAAC,MAAM,CAAC,CAAC;;;;;CAQrF,CAAC,OAAO,IAAI,6BAA6B,IAAI;EACzC,OAAO,KAAK;;;;;;;CAQhB,CAAC,OAAO,aAAa,MAAc;EAC/B,IAAI,SAAS,UAAU,OAAO,KAAKD,SAAS,UAAU;EACtD,OAAO,KAAK;;CAIhB,uBAAuB,SAAkB;EACrC,OAAO,QAAQ,gBAAgB,KAAKF,gBA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EAC/B,OAAO,IAAI,gBAAgB,KAAKC,SAAS,IAAI,KAAKE,eAAe,MAAM,CAAC,EAAE,KAAKJ,gBAAgB,KAAKC,UAAU;;;;;;;CAQlH,WAAW;EACP,OAAO,KAAKC,SAAS,UAAU;;;;;CAMnC,WAAW;EACP,OAAO,KAAK;;;;;CAMhB,QAAQ,gBAAwB,KAAKF,gBAAgB,WAA6B,KAAKC,WAAW;EAC9F,OAAO,KAAKC,SAAS,QAAQ,eAAe,SAAS;;;;;CAMzD,QAAQ,OAA6B;EACjC,OAAO,IAAI,gBACP,KAAKA,SAAS,MAAM,KAAKE,eAAe,MAAM,CAAC,EAC/C,KAAKJ,gBACL,KAAKC,UACR"}
|
|
1
|
+
{"version":3,"file":"precision-number.js","names":["#decimalPlaces","#rounding","#decimal","#decimalToFixedDecimal","#valueToString"],"sources":["../../src/classes/precision-number.ts"],"sourcesContent":["import { Decimal } from 'decimal.js';\n\n/**\n * Values accepted by `PrecisionNumber` constructors and arithmetic methods.\n */\nexport type PrecisionNumberValue = Decimal.Value | PrecisionNumber | { toString: () => string };\n\n/**\n * Chainable fixed-decimal wrapper around `decimal.js`.\n *\n * `PrecisionNumber` stores values as `Decimal`, rounds every mutating operation to\n * the configured decimal places, and exposes both mutable and immutable arithmetic\n * methods. Mutable methods (`plus`, `minus`, `times`, `dividedBy`, `modulo`,\n * `pow`, `clamp`, `ceil`, `floor`, `negate`, `absoluteValue`) update the current\n * instance and return `this`; immutable methods prefixed with `to` return a new\n * `PrecisionNumber` with the same precision settings.\n *\n * @example\n * ```typescript\n * import { PrecisionNumber } from '@kikiutils/shared/classes/precision-number';\n *\n * const value = new PrecisionNumber('1.239', 2).plus('2.111');\n * value.toString(); // '3.35'\n * value.toMinus('1').toString(); // '2.35' (original value remains '3.35')\n * ```\n */\nexport class PrecisionNumber {\n // Private properties\n readonly #decimalPlaces: number;\n readonly #rounding: Decimal.Rounding;\n #decimal: Decimal;\n\n /**\n * Creates a fixed-decimal number.\n *\n * @param {PrecisionNumberValue} [value] - Initial value (default: `'0'`)\n * @param {number} [decimalPlaces] - Decimal places retained after operations (default: `2`)\n * @param {Decimal.Rounding} [rounding] - Decimal.js rounding mode (default: `Decimal.ROUND_DOWN`)\n */\n constructor(\n value: PrecisionNumberValue = '0',\n decimalPlaces: number = 2,\n rounding: Decimal.Rounding = Decimal.ROUND_DOWN,\n ) {\n this.#decimalPlaces = decimalPlaces;\n this.#rounding = rounding;\n this.#decimal = this.#decimalToFixedDecimal(new Decimal(value.toString().trim()));\n }\n\n // Symbols\n\n /**\n * Returns the formatted value when inspected by Node.js utilities.\n */\n [Symbol.for('nodejs.util.inspect.custom')]() {\n return this.value;\n }\n\n /**\n * Converts to a number for numeric coercion and to the fixed string otherwise.\n *\n * @param {string} hint - JavaScript primitive-conversion hint\n */\n [Symbol.toPrimitive](hint: string) {\n if (hint === 'number') return this.#decimal.toNumber();\n return this.value;\n }\n\n // Private methods\n #decimalToFixedDecimal(decimal: Decimal) {\n return decimal.toDecimalPlaces(this.#decimalPlaces, this.#rounding);\n }\n\n #valueToString(value: PrecisionNumberValue) {\n return value.toString().trim();\n }\n\n // Public getters\n\n /**\n * Decimal places retained by mutating operations and default formatting.\n */\n get decimalPlaces() {\n return this.#decimalPlaces;\n }\n\n /**\n * Decimal.js rounding mode used by mutating operations and default formatting.\n */\n get rounding() {\n return this.#rounding;\n }\n\n /**\n * Fixed-decimal string using the instance precision and rounding mode.\n */\n get value() {\n return this.#decimal.toFixed(this.#decimalPlaces, this.#rounding);\n }\n\n /**\n * Formats a value with decimal.js without creating a reusable instance.\n *\n * @param {PrecisionNumberValue} value - Value to format\n * @param {number} [decimalPlaces] - Decimal places to output (default: `2`)\n * @param {Decimal.Rounding} [rounding] - Decimal.js rounding mode (default: `Decimal.ROUND_DOWN`)\n *\n * @returns {string} Fixed-decimal string\n */\n static toFixed(\n value: PrecisionNumberValue,\n decimalPlaces: number = 2,\n rounding: Decimal.Rounding = Decimal.ROUND_DOWN,\n ) {\n return new Decimal(value.toString().trim()).toFixed(decimalPlaces, rounding);\n }\n\n // Public methods\n\n /**\n * Replaces the current value with its absolute value.\n *\n * @returns {this} The current instance for chaining\n */\n absoluteValue() {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.absoluteValue());\n return this;\n }\n\n /**\n * Rounds the current value up to the nearest integer in place.\n *\n * The stored value still uses this instance's configured decimal places for output.\n *\n * @returns {this} The current instance for chaining\n */\n ceil() {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.ceil());\n return this;\n }\n\n /**\n * Restricts the current value to the inclusive range `[min, max]` in place.\n *\n * @param {PrecisionNumberValue} min - Lower bound\n * @param {PrecisionNumberValue} max - Upper bound\n *\n * @returns {this} The current instance for chaining\n *\n * @throws {Error} If `min` is greater than `max`\n */\n clamp(min: PrecisionNumberValue, max: PrecisionNumberValue) {\n const minDecimal = new Decimal(this.#valueToString(min));\n const maxDecimal = new Decimal(this.#valueToString(max));\n if (minDecimal.gt(maxDecimal)) throw new Error('Invalid clamp range: min cannot be greater than max');\n this.#decimal = this.#decimalToFixedDecimal(Decimal.min(Decimal.max(this.#decimal, minDecimal), maxDecimal));\n return this;\n }\n\n /**\n * Returns a new instance with the same value, decimal places, and rounding mode.\n */\n clone() {\n return new PrecisionNumber(this.#decimal, this.#decimalPlaces, this.#rounding);\n }\n\n /**\n * Divides the current value by another value in place.\n *\n * @param {PrecisionNumberValue} value - Divisor\n *\n * @returns {this} The current instance for chaining\n */\n dividedBy(value: PrecisionNumberValue) {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.dividedBy(this.#valueToString(value)));\n return this;\n }\n\n /**\n * Checks whether the current value equals another value.\n *\n * @param {PrecisionNumberValue} value - Value to compare\n *\n * @returns {boolean} `true` when both numeric values are equal\n */\n equals(value: PrecisionNumberValue) {\n return this.#decimal.equals(this.#valueToString(value));\n }\n\n /**\n * Rounds the current value down to the nearest integer in place.\n *\n * The stored value still uses this instance's configured decimal places for output.\n *\n * @returns {this} The current instance for chaining\n */\n floor() {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.floor());\n return this;\n }\n\n /**\n * Checks whether the current value is greater than another value.\n */\n gt(value: PrecisionNumberValue) {\n return this.#decimal.gt(this.#valueToString(value));\n }\n\n /**\n * Checks whether the current value is greater than or equal to another value.\n */\n gte(value: PrecisionNumberValue) {\n return this.#decimal.gte(this.#valueToString(value));\n }\n\n /**\n * Checks whether the current value is finite.\n */\n isFinite() {\n return this.#decimal.isFinite();\n }\n\n /**\n * Checks whether the current value is an integer.\n */\n isInteger() {\n return this.#decimal.isInteger();\n }\n\n /**\n * Checks whether the current value is `NaN`.\n */\n isNaN() {\n return this.#decimal.isNaN();\n }\n\n /**\n * Checks whether the current value is negative.\n */\n isNegative() {\n return this.#decimal.isNegative();\n }\n\n /**\n * Checks whether the current value is positive.\n */\n isPositive() {\n return this.#decimal.isPositive();\n }\n\n /**\n * Checks whether the current value is zero.\n */\n isZero() {\n return this.#decimal.isZero();\n }\n\n /**\n * Checks whether the current value is less than another value.\n */\n lt(value: PrecisionNumberValue) {\n return this.#decimal.lt(this.#valueToString(value));\n }\n\n /**\n * Checks whether the current value is less than or equal to another value.\n */\n lte(value: PrecisionNumberValue) {\n return this.#decimal.lte(this.#valueToString(value));\n }\n\n /**\n * Subtracts another value from the current value in place.\n */\n minus(value: PrecisionNumberValue) {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.minus(this.#valueToString(value)));\n return this;\n }\n\n /**\n * Replaces the current value with the remainder after division by another value.\n *\n * @param {PrecisionNumberValue} value - Divisor used to compute the remainder\n *\n * @returns {this} The current instance for chaining\n */\n modulo(value: PrecisionNumberValue) {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.modulo(this.#valueToString(value)));\n return this;\n }\n\n /**\n * Negates the current value in place.\n */\n negate() {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.negated());\n return this;\n }\n\n /**\n * Adds another value to the current value in place.\n */\n plus(value: PrecisionNumberValue) {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.plus(this.#valueToString(value)));\n return this;\n }\n\n /**\n * Raises the current value to an exponent in place.\n *\n * @param {PrecisionNumberValue} value - Exponent\n *\n * @returns {this} The current instance for chaining\n */\n pow(value: PrecisionNumberValue) {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.pow(this.#valueToString(value)));\n return this;\n }\n\n /**\n * Multiplies the current value by another value in place.\n */\n times(value: PrecisionNumberValue) {\n this.#decimal = this.#decimalToFixedDecimal(this.#decimal.times(this.#valueToString(value)));\n return this;\n }\n\n /**\n * Returns a new instance with the absolute value.\n */\n toAbsoluteValue() {\n return new PrecisionNumber(this.#decimal.absoluteValue(), this.#decimalPlaces, this.#rounding);\n }\n\n /**\n * Returns a new instance rounded up to the nearest integer.\n */\n toCeil() {\n return new PrecisionNumber(this.#decimal.ceil(), this.#decimalPlaces, this.#rounding);\n }\n\n /**\n * Returns a new instance restricted to the inclusive range `[min, max]`.\n *\n * @param {PrecisionNumberValue} min - Lower bound\n * @param {PrecisionNumberValue} max - Upper bound\n *\n * @throws {Error} If `min` is greater than `max`\n */\n toClamped(min: PrecisionNumberValue, max: PrecisionNumberValue) {\n return this.clone().clamp(min, max);\n }\n\n /**\n * Returns a new instance divided by another value.\n */\n toDividedBy(value: PrecisionNumberValue) {\n return new PrecisionNumber(\n this.#decimal.dividedBy(this.#valueToString(value)),\n this.#decimalPlaces,\n this.#rounding,\n );\n }\n\n /**\n * Returns a new instance rounded down to the nearest integer.\n */\n toFloor() {\n return new PrecisionNumber(this.#decimal.floor(), this.#decimalPlaces, this.#rounding);\n }\n\n /**\n * Serializes to the fixed-decimal string.\n */\n toJSON() {\n return this.value;\n }\n\n /**\n * Returns a new instance with another value subtracted.\n */\n toMinus(value: PrecisionNumberValue) {\n return new PrecisionNumber(\n this.#decimal.minus(this.#valueToString(value)),\n this.#decimalPlaces,\n this.#rounding,\n );\n }\n\n /**\n * Returns a new instance with the remainder after division by another value.\n */\n toModulo(value: PrecisionNumberValue) {\n return new PrecisionNumber(\n this.#decimal.modulo(this.#valueToString(value)),\n this.#decimalPlaces,\n this.#rounding,\n );\n }\n\n /**\n * Returns a new instance with the value negated.\n */\n toNegated() {\n return new PrecisionNumber(this.#decimal.negated(), this.#decimalPlaces, this.#rounding);\n }\n\n /**\n * Returns a new instance with another value added.\n */\n toPlus(value: PrecisionNumberValue) {\n return new PrecisionNumber(this.#decimal.plus(this.#valueToString(value)), this.#decimalPlaces, this.#rounding);\n }\n\n /**\n * Returns a new instance raised to an exponent.\n */\n toPow(value: PrecisionNumberValue) {\n return new PrecisionNumber(this.#decimal.pow(this.#valueToString(value)), this.#decimalPlaces, this.#rounding);\n }\n\n /**\n * Converts the current value to a JavaScript number.\n *\n * Use `toString`/`value` when preserving decimal precision is more important than native-number ergonomics.\n */\n toNumber() {\n return this.#decimal.toNumber();\n }\n\n /**\n * Converts the current value to its fixed-decimal string.\n */\n toString() {\n return this.value;\n }\n\n /**\n * Formats the current value with custom precision and rounding for this call only.\n */\n toFixed(decimalPlaces: number = this.#decimalPlaces, rounding: Decimal.Rounding = this.#rounding) {\n return this.#decimal.toFixed(decimalPlaces, rounding);\n }\n\n /**\n * Returns a new instance multiplied by another value.\n */\n toTimes(value: PrecisionNumberValue) {\n return new PrecisionNumber(\n this.#decimal.times(this.#valueToString(value)),\n this.#decimalPlaces,\n this.#rounding,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,kBAAb,MAAa,gBAAgB;CAEzB;CACA;CACA;;;;;;;;CASA,YACI,QAA8B,KAC9B,gBAAwB,GACxB,WAA6B,QAAQ,YACvC;EACE,KAAKA,iBAAiB;EACtB,KAAKC,YAAY;EACjB,KAAKC,WAAW,KAAKC,uBAAuB,IAAI,QAAQ,MAAM,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;CACpF;;;;CAOA,CAAC,OAAO,IAAI,4BAA4B,KAAK;EACzC,OAAO,KAAK;CAChB;;;;;;CAOA,CAAC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AKE,eAAe,KAAK,CAAC,GAC/C,KAAKJ,gBACL,KAAKC,SACT;CACJ;;;;CAKA,YAAY;EACR,OAAO,IAAI,gBAAgB,KAAKC,SAAS,QAAQ,GAAG,KAAKF,gBAAgB,KAAKC,SAAS;CAC3F;;;;CAKA,OAAO,OAA6B;EAChC,OAAO,IAAI,gBAAgB,KAAKC,SAAS,KAAK,KAAKE,eAAe,KAAK,CAAC,GAAG,KAAKJ,gBAAgB,KAAKC,SAAS;CAClH;;;;CAKA,MAAM,OAA6B;EAC/B,OAAO,IAAI,gBAAgB,KAAKC,SAAS,IAAI,KAAKE,eAAe,KAAK,CAAC,GAAG,KAAKJ,gBAAgB,KAAKC,SAAS;CACjH;;;;;;CAOA,WAAW;EACP,OAAO,KAAKC,SAAS,SAAS;CAClC;;;;CAKA,WAAW;EACP,OAAO,KAAK;CAChB;;;;CAKA,QAAQ,gBAAwB,KAAKF,gBAAgB,WAA6B,KAAKC,WAAW;EAC9F,OAAO,KAAKC,SAAS,QAAQ,eAAe,QAAQ;CACxD;;;;CAKA,QAAQ,OAA6B;EACjC,OAAO,IAAI,gBACP,KAAKA,SAAS,MAAM,KAAKE,eAAe,KAAK,CAAC,GAC9C,KAAKJ,gBACL,KAAKC,SACT;CACJ;AACJ"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { Nullable } from "../types/index.js";
|
|
2
1
|
import { PathLike } from "./path.js";
|
|
3
|
-
import * as _$node_ssh0 from "node-ssh";
|
|
4
2
|
import { Config, NodeSSH, SSHExecCommandOptions, SSHGetPutDirectoryOptions, SSHPutFilesOptions } from "node-ssh";
|
|
5
3
|
import { SFTPWrapper, TransferOptions } from "ssh2";
|
|
6
4
|
|
|
@@ -22,16 +20,16 @@ declare class SshClient {
|
|
|
22
20
|
get nodeSsh(): NodeSSH;
|
|
23
21
|
connect(): Promise<boolean>;
|
|
24
22
|
disconnect(): boolean;
|
|
25
|
-
execCommand(command: string, options?: SSHExecCommandOptions): Promise<void |
|
|
26
|
-
execCommandWithIo(command: string, options?: SSHExecCommandOptions): Promise<void |
|
|
23
|
+
execCommand(command: string, options?: SSHExecCommandOptions): Promise<void | import("node-ssh").SSHExecCommandResponse>;
|
|
24
|
+
execCommandWithIo(command: string, options?: SSHExecCommandOptions): Promise<void | import("node-ssh").SSHExecCommandResponse>;
|
|
27
25
|
getDir: (localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions) => Promise<boolean>;
|
|
28
26
|
getDirectory(localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions): Promise<boolean>;
|
|
29
|
-
getFile(localFile: PathLike, remoteFile: PathLike, givenSftp?:
|
|
27
|
+
getFile(localFile: PathLike, remoteFile: PathLike, givenSftp?: null | SFTPWrapper, transferOptions?: null | TransferOptions): Promise<boolean>;
|
|
30
28
|
isConnected(): boolean;
|
|
31
29
|
mkdir(path: PathLike): Promise<boolean>;
|
|
32
30
|
putDir: (localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions) => Promise<boolean>;
|
|
33
31
|
putDirectory(localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions): Promise<boolean>;
|
|
34
|
-
putFile(localFile: PathLike, remoteFile: PathLike, givenSftp?:
|
|
32
|
+
putFile(localFile: PathLike, remoteFile: PathLike, givenSftp?: null | SFTPWrapper, transferOptions?: null | TransferOptions): Promise<boolean>;
|
|
35
33
|
putFiles(files: {
|
|
36
34
|
local: PathLike;
|
|
37
35
|
remote: PathLike;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssh-client.d.ts","names":[],"sources":["../../src/classes/ssh-client.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ssh-client.d.ts","names":[],"sources":["../../src/classes/ssh-client.ts"],"mappings":";;;;;cAgBM,qCAAA;EAAA;;;;;;;;;;cAYO,SAAA;EAAA;cAMG,IAAA,UAAc,QAAA,UAAkB,QAAA,UAAkB,IAA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classes/ssh-client.ts"],"sourcesContent":["import { createConsola } from 'consola';\nimport type { ConsolaInstance } from 'consola';\nimport { NodeSSH } from 'node-ssh';\nimport type {\n Config,\n SSHExecCommandOptions,\n SSHGetPutDirectoryOptions,\n SSHPutFilesOptions,\n} from 'node-ssh';\nimport type {\n SFTPWrapper,\n TransferOptions,\n} from 'ssh2';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"ssh-client.js","names":["#connectConfig","#logger","#nodeSsh"],"sources":["../../src/classes/ssh-client.ts"],"sourcesContent":["import { createConsola } from 'consola';\nimport type { ConsolaInstance } from 'consola';\nimport { NodeSSH } from 'node-ssh';\nimport type {\n Config,\n SSHExecCommandOptions,\n SSHGetPutDirectoryOptions,\n SSHPutFilesOptions,\n} from 'node-ssh';\nimport type {\n SFTPWrapper,\n TransferOptions,\n} from 'ssh2';\n\nimport type { PathLike } from './path';\n\nconst loggerLevelStringToConsolaLogLevelMap = {\n debug: 4,\n error: 0,\n fatal: 0,\n info: 3,\n normal: 2,\n silent: -999,\n trace: 5,\n verbose: 999,\n warn: 1,\n} as const;\n\nexport class SshClient {\n readonly #connectConfig: Config;\n readonly #logger: ConsolaInstance;\n\n #nodeSsh: NodeSSH;\n\n constructor(host: string, username: string, password: string, port: number = 22, connectConfig?: Config) {\n this.#connectConfig = {\n ...connectConfig,\n host,\n password,\n port,\n username,\n };\n\n this.#logger = createConsola();\n this.#nodeSsh = new NodeSSH();\n if (process.env.NODE_ENV === 'production') this.setLoggerLevel('error');\n }\n\n get nodeSsh() {\n return this.#nodeSsh;\n }\n\n async connect() {\n try {\n this.#nodeSsh = await this.#nodeSsh.connect(this.#connectConfig);\n return true;\n } catch (error) {\n this.#logger.error(error);\n return false;\n }\n }\n\n disconnect() {\n try {\n this.#nodeSsh.dispose();\n return true;\n } catch (error) {\n this.#logger.error(error);\n return false;\n }\n }\n\n execCommand(command: string, options?: SSHExecCommandOptions) {\n return this.#nodeSsh.execCommand(command, options).catch(() => {});\n }\n\n execCommandWithIo(command: string, options?: SSHExecCommandOptions) {\n return this.execCommand(\n command,\n {\n ...options,\n onStderr: (data) => process.stderr.write(data.toString()),\n onStdout: (data) => process.stdout.write(data.toString()),\n },\n );\n }\n\n getDir = this.getDirectory;\n\n async getDirectory(localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions) {\n try {\n return await this.#nodeSsh.getDirectory(localDirectory.toString(), remoteDirectory.toString(), options);\n } catch (error) {\n this.#logger.error(error);\n return false;\n }\n }\n\n async getFile(\n localFile: PathLike,\n remoteFile: PathLike,\n givenSftp?: null | SFTPWrapper,\n transferOptions?: null | TransferOptions,\n ) {\n try {\n await this.#nodeSsh.getFile(localFile.toString(), remoteFile.toString(), givenSftp, transferOptions);\n return true;\n } catch (error) {\n this.#logger.error(error);\n return false;\n }\n }\n\n isConnected() {\n return this.#nodeSsh.isConnected();\n }\n\n async mkdir(path: PathLike) {\n try {\n await this.#nodeSsh.mkdir(path.toString());\n return true;\n } catch (error) {\n this.#logger.error(error);\n return false;\n }\n }\n\n putDir = this.putDirectory;\n\n async putDirectory(localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions) {\n try {\n return await this.#nodeSsh.putDirectory(localDirectory.toString(), remoteDirectory.toString(), options);\n } catch (error) {\n this.#logger.error(error);\n return false;\n }\n }\n\n async putFile(\n localFile: PathLike,\n remoteFile: PathLike,\n givenSftp?: null | SFTPWrapper,\n transferOptions?: null | TransferOptions,\n ) {\n try {\n await this.#nodeSsh.putFile(localFile.toString(), remoteFile.toString(), givenSftp, transferOptions);\n return true;\n } catch (error) {\n this.#logger.error(error);\n return false;\n }\n }\n\n async putFiles(files: { local: PathLike; remote: PathLike }[], options?: SSHPutFilesOptions) {\n try {\n const convertedFiles = files.map(({ local, remote }) => ({\n local: local.toString(),\n remote: remote.toString(),\n }));\n\n await this.#nodeSsh.putFiles(convertedFiles, options);\n return true;\n } catch (error) {\n this.#logger.error(error);\n return false;\n }\n }\n\n setLoggerLevel(level: keyof typeof loggerLevelStringToConsolaLogLevelMap) {\n this.#logger.level = loggerLevelStringToConsolaLogLevelMap[level];\n }\n}\n"],"mappings":";;;AAgBA,MAAM,wCAAwC;CAC1C,OAAO;CACP,OAAO;CACP,OAAO;CACP,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,OAAO;CACP,SAAS;CACT,MAAM;AACV;AAEA,IAAa,YAAb,MAAuB;CACnB;CACA;CAEA;CAEA,YAAY,MAAc,UAAkB,UAAkB,OAAe,IAAI,eAAwB;EACrG,KAAKA,iBAAiB;GAClB,GAAG;GACH;GACA;GACA;GACA;EACJ;EAEA,KAAKC,UAAU,cAAc;EAC7B,KAAKC,WAAW,IAAI,QAAQ;EAC5B,IAAI,QAAQ,IAAI,aAAa,cAAc,KAAK,eAAe,OAAO;CAC1E;CAEA,IAAI,UAAU;EACV,OAAO,KAAKA;CAChB;CAEA,MAAM,UAAU;EACZ,IAAI;GACA,KAAKA,WAAW,MAAM,KAAKA,SAAS,QAAQ,KAAKF,cAAc;GAC/D,OAAO;EACX,SAAS,OAAO;GACZ,KAAKC,QAAQ,MAAM,KAAK;GACxB,OAAO;EACX;CACJ;CAEA,aAAa;EACT,IAAI;GACA,KAAKC,SAAS,QAAQ;GACtB,OAAO;EACX,SAAS,OAAO;GACZ,KAAKD,QAAQ,MAAM,KAAK;GACxB,OAAO;EACX;CACJ;CAEA,YAAY,SAAiB,SAAiC;EAC1D,OAAO,KAAKC,SAAS,YAAY,SAAS,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC;CACrE;CAEA,kBAAkB,SAAiB,SAAiC;EAChE,OAAO,KAAK,YACR,SACA;GACI,GAAG;GACH,WAAW,SAAS,QAAQ,OAAO,MAAM,KAAK,SAAS,CAAC;GACxD,WAAW,SAAS,QAAQ,OAAO,MAAM,KAAK,SAAS,CAAC;EAC5D,CACJ;CACJ;CAEA,SAAS,KAAK;CAEd,MAAM,aAAa,gBAA0B,iBAA2B,SAAqC;EACzG,IAAI;GAC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AO;EACX,SAAS,OAAO;GACZ,KAAKD,QAAQ,MAAM,KAAK;GACxB,OAAO;EACX;CACJ;CAEA,eAAe,OAA2D;EACtE,KAAKA,QAAQ,QAAQ,sCAAsC;CAC/D;AACJ"}
|
package/dist/clipboard.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clipboard.d.ts","names":[],"sources":["../src/clipboard.ts"],"mappings":";KAAK,UAAA;EACC,KAAA;EAAgB,EAAA;AAAA;EAChB,EAAA;AAAA
|
|
1
|
+
{"version":3,"file":"clipboard.d.ts","names":[],"sources":["../src/clipboard.ts"],"mappings":";KAAK,UAAA;EACC,KAAA;EAAgB,EAAA;AAAA;EAChB,EAAA;AAAA;;;;AAAE;AA8BR;;;;;;;;;;;;;;;;AAAyG;AA8CzG;;;;;;;iBA9CsB,mBAAA,CAAoB,IAAA,EAAM,IAAA,EAAM,OAAA,GAAU,oBAAA,GAAuB,OAAA,CAAQ,UAAA;AA8CpB;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAArD,mBAAA,CAAoB,IAAA,WAAe,OAAO,CAAC,UAAA"}
|
package/dist/clipboard.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clipboard.js","names":[],"sources":["../src/clipboard.ts"],"sourcesContent":["type CopyResult =\n | { error: unknown; ok: false }\n | { ok: true };\n\n/**\n * Attempts to copy a Blob (e.g. image, plain text, HTML) to the user's clipboard using the ClipboardItem API.\n *\n * ⚠️ Usage Notes:\n * - Must be called in a **secure context** (HTTPS or localhost).\n * - Must be called **in response to a user interaction** (e.g. click, input).\n * - Not supported in Safari and some older browsers.\n *\n * @param {Blob} blob - The Blob object to copy (e.g. from a File, image, or text content)\n * @param {ClipboardItemOptions} [options] - Optional options passed to the ClipboardItem constructor\n *\n * @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:\n * - `{ ok: true }` if the copy succeeded\n * - `{ ok: false, error }` if the copy failed, with the error included\n *\n * @example\n * ```typescript\n * import { copyBlobToClipboard } from '@kikiutils/shared/clipboard';\n *\n * const blob = new Blob(['Hello world'], { type: 'text/plain' });\n * const result = await copyBlobToClipboard(blob);\n * if (result.ok) {\n * console.log('Copied blob!');\n * } else {\n * console.error('Copy failed:', result.error);\n * }\n * ```\n */\nexport async function copyBlobToClipboard(blob: Blob, options?: ClipboardItemOptions): Promise<CopyResult> {\n if (!navigator.clipboard?.write) {\n return {\n error: new Error('Clipboard.write is not supported in this browser'),\n ok: false,\n };\n }\n\n try {\n const item = new ClipboardItem({ [blob.type]: blob }, options);\n await navigator.clipboard.write([item]);\n return { ok: true };\n } catch (error) {\n return {\n error,\n ok: false,\n };\n }\n}\n\n/**\n * Attempts to copy the given text to the user's clipboard using the modern Clipboard API.\n *\n * ⚠️ Usage Notes:\n * - Must be called in a **secure context** (HTTPS or localhost).\n * - Must be called **in response to a user interaction** (e.g. click, input).\n * - Not supported in some older browsers (especially legacy Safari).\n *\n * @param {string} text - The string to be copied to the clipboard\n *\n * @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:\n * - `{ ok: true }` if the copy succeeded\n * - `{ ok: false, error }` if the copy failed, with the error included\n *\n * @example\n * ```typescript\n * import { copyTextToClipboard } from '@kikiutils/shared/clipboard';\n *\n * const result = await copyTextToClipboard('Hello!');\n * if (result.ok) {\n * console.log('Copied!');\n * } else {\n * console.error('Copy failed:', result.error);\n * }\n * ```\n */\nexport async function copyTextToClipboard(text: string): Promise<CopyResult> {\n try {\n await navigator.clipboard.writeText(text);\n return { ok: true };\n } catch (error) {\n return {\n error,\n ok: false,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,eAAsB,oBAAoB,MAAY,SAAqD;CACvG,IAAI,CAAC,UAAU,WAAW,OACtB,OAAO;EACH,uBAAO,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"clipboard.js","names":[],"sources":["../src/clipboard.ts"],"sourcesContent":["type CopyResult =\n | { error: unknown; ok: false }\n | { ok: true };\n\n/**\n * Attempts to copy a Blob (e.g. image, plain text, HTML) to the user's clipboard using the ClipboardItem API.\n *\n * ⚠️ Usage Notes:\n * - Must be called in a **secure context** (HTTPS or localhost).\n * - Must be called **in response to a user interaction** (e.g. click, input).\n * - Not supported in Safari and some older browsers.\n *\n * @param {Blob} blob - The Blob object to copy (e.g. from a File, image, or text content)\n * @param {ClipboardItemOptions} [options] - Optional options passed to the ClipboardItem constructor\n *\n * @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:\n * - `{ ok: true }` if the copy succeeded\n * - `{ ok: false, error }` if the copy failed, with the error included\n *\n * @example\n * ```typescript\n * import { copyBlobToClipboard } from '@kikiutils/shared/clipboard';\n *\n * const blob = new Blob(['Hello world'], { type: 'text/plain' });\n * const result = await copyBlobToClipboard(blob);\n * if (result.ok) {\n * console.log('Copied blob!');\n * } else {\n * console.error('Copy failed:', result.error);\n * }\n * ```\n */\nexport async function copyBlobToClipboard(blob: Blob, options?: ClipboardItemOptions): Promise<CopyResult> {\n if (!navigator.clipboard?.write) {\n return {\n error: new Error('Clipboard.write is not supported in this browser'),\n ok: false,\n };\n }\n\n try {\n const item = new ClipboardItem({ [blob.type]: blob }, options);\n await navigator.clipboard.write([item]);\n return { ok: true };\n } catch (error) {\n return {\n error,\n ok: false,\n };\n }\n}\n\n/**\n * Attempts to copy the given text to the user's clipboard using the modern Clipboard API.\n *\n * ⚠️ Usage Notes:\n * - Must be called in a **secure context** (HTTPS or localhost).\n * - Must be called **in response to a user interaction** (e.g. click, input).\n * - Not supported in some older browsers (especially legacy Safari).\n *\n * @param {string} text - The string to be copied to the clipboard\n *\n * @returns {Promise<CopyResult>} A promise resolving to a `CopyResult`:\n * - `{ ok: true }` if the copy succeeded\n * - `{ ok: false, error }` if the copy failed, with the error included\n *\n * @example\n * ```typescript\n * import { copyTextToClipboard } from '@kikiutils/shared/clipboard';\n *\n * const result = await copyTextToClipboard('Hello!');\n * if (result.ok) {\n * console.log('Copied!');\n * } else {\n * console.error('Copy failed:', result.error);\n * }\n * ```\n */\nexport async function copyTextToClipboard(text: string): Promise<CopyResult> {\n try {\n await navigator.clipboard.writeText(text);\n return { ok: true };\n } catch (error) {\n return {\n error,\n ok: false,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,eAAsB,oBAAoB,MAAY,SAAqD;CACvG,IAAI,CAAC,UAAU,WAAW,OACtB,OAAO;EACH,uBAAO,IAAI,MAAM,kDAAkD;EACnE,IAAI;CACR;CAGJ,IAAI;EACA,MAAM,OAAO,IAAI,cAAc,GAAG,KAAK,OAAO,KAAK,GAAG,OAAO;EAC7D,MAAM,UAAU,UAAU,MAAM,CAAC,IAAI,CAAC;EACtC,OAAO,EAAE,IAAI,KAAK;CACtB,SAAS,OAAO;EACZ,OAAO;GACH;GACA,IAAI;EACR;CACJ;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,eAAsB,oBAAoB,MAAmC;CACzE,IAAI;EACA,MAAM,UAAU,UAAU,UAAU,IAAI;EACxC,OAAO,EAAE,IAAI,KAAK;CACtB,SAAS,OAAO;EACZ,OAAO;GACH;GACA,IAAI;EACR;CACJ;AACJ"}
|
package/dist/consola.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import * as _$consola from "consola";
|
|
2
|
-
|
|
3
1
|
//#region src/consola.d.ts
|
|
4
2
|
/**
|
|
5
3
|
* A consola logger instance.
|
|
@@ -22,8 +20,8 @@ import * as _$consola from "consola";
|
|
|
22
20
|
* logger.level = 3;
|
|
23
21
|
* ```
|
|
24
22
|
*/
|
|
25
|
-
declare const consolaLogger:
|
|
26
|
-
declare const logger:
|
|
23
|
+
declare const consolaLogger: import("consola").ConsolaInstance;
|
|
24
|
+
declare const logger: import("consola").ConsolaInstance;
|
|
27
25
|
//#endregion
|
|
28
26
|
export { consolaLogger, logger };
|
|
29
27
|
//# sourceMappingURL=consola.d.ts.map
|
package/dist/consola.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consola.d.ts","names":[],"sources":["../src/consola.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"consola.d.ts","names":[],"sources":["../src/consola.ts"],"mappings":";;AAuBA;;;;AAA4C;AAC5C;;;;AAAmC;;;;;;;;;;;cADtB,aAAA,oBAAa,eAAkB;AAAA,cAC/B,MAAA,oBAAM,eAAgB"}
|
package/dist/consola.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consola.js","names":[],"sources":["../src/consola.ts"],"sourcesContent":["import { createConsola } from 'consola';\n\n/**\n * A consola logger instance.\n *\n * The logger's level is determined based on the `CONSOLA_LOGGER_LEVEL` and `NODE_ENV` environment variables.\n * If `CONSOLA_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,\n * the level will be set to `0`.\n *\n * To manually change the level, assign the desired level to `logger.level`.\n *\n * See available levels [here](https://github.com/unjs/consola?tab=readme-ov-file#log-level).\n *\n * @example\n * ```typescript\n * import { logger } from '@kikiutils/shared/consola';\n *\n * logger.info('test'); // ℹ test 3:56:30 AM\n *\n * // Manually change the level\n * logger.level = 3;\n * ```\n */\nexport const consolaLogger = createConsola();\nexport const logger = consolaLogger;\nif (process.env.CONSOLA_LOGGER_LEVEL !== undefined) consolaLogger.level = +process.env.CONSOLA_LOGGER_LEVEL;\nelse consolaLogger.level = process.env.NODE_ENV === 'production' ? 0 : consolaLogger.level;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,gBAAgB,
|
|
1
|
+
{"version":3,"file":"consola.js","names":[],"sources":["../src/consola.ts"],"sourcesContent":["import { createConsola } from 'consola';\n\n/**\n * A consola logger instance.\n *\n * The logger's level is determined based on the `CONSOLA_LOGGER_LEVEL` and `NODE_ENV` environment variables.\n * If `CONSOLA_LOGGER_LEVEL` is set, it will be used; otherwise, if `NODE_ENV` is `production`,\n * the level will be set to `0`.\n *\n * To manually change the level, assign the desired level to `logger.level`.\n *\n * See available levels [here](https://github.com/unjs/consola?tab=readme-ov-file#log-level).\n *\n * @example\n * ```typescript\n * import { logger } from '@kikiutils/shared/consola';\n *\n * logger.info('test'); // ℹ test 3:56:30 AM\n *\n * // Manually change the level\n * logger.level = 3;\n * ```\n */\nexport const consolaLogger = createConsola();\nexport const logger = consolaLogger;\nif (process.env.CONSOLA_LOGGER_LEVEL !== undefined) consolaLogger.level = +process.env.CONSOLA_LOGGER_LEVEL;\nelse consolaLogger.level = process.env.NODE_ENV === 'production' ? 0 : consolaLogger.level;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,gBAAgB,cAAc;AAC3C,MAAa,SAAS;AACtB,IAAI,QAAQ,IAAI,yBAAyB,KAAA,GAAW,cAAc,QAAQ,CAAC,QAAQ,IAAI;KAClF,cAAc,QAAQ,QAAQ,IAAI,aAAa,eAAe,IAAI,cAAc"}
|
package/dist/crypto-hash.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { BinaryLike
|
|
1
|
+
import { BinaryLike } from "node:crypto";
|
|
2
2
|
|
|
3
3
|
//#region src/crypto-hash.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Computes the MD5 hash of the given data.
|
|
6
6
|
*
|
|
7
7
|
* @param {BinaryLike} data - The input data to hash
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
9
9
|
*
|
|
10
10
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
11
11
|
*
|
|
@@ -16,7 +16,7 @@ import { BinaryLike, BinaryToTextEncoding } from "node:crypto";
|
|
|
16
16
|
* console.log(cryptoMd5('test')); // 098f6bcd4621d373cade4e832627b4f6
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
declare function cryptoMd5(data: BinaryLike, outputEncoding?:
|
|
19
|
+
declare function cryptoMd5(data: BinaryLike, outputEncoding?: BufferEncoding): string;
|
|
20
20
|
/**
|
|
21
21
|
* Computes the MD5 hash of the given data and returns the raw buffer.
|
|
22
22
|
*
|
|
@@ -36,7 +36,7 @@ declare function cryptoMd5ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
|
36
36
|
* Computes the SHA-3 hash of the given data using the 224-bit digest.
|
|
37
37
|
*
|
|
38
38
|
* @param {BinaryLike} data - The input data to hash
|
|
39
|
-
* @param {
|
|
39
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
40
40
|
*
|
|
41
41
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
42
42
|
*
|
|
@@ -47,7 +47,7 @@ declare function cryptoMd5ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
|
47
47
|
* console.log(cryptoSha3224('test')); // 3797bf0afbbfca4a7bbba7602a2b552746876517a7f9b7ce2db0ae7b
|
|
48
48
|
* ```
|
|
49
49
|
*/
|
|
50
|
-
declare function cryptoSha3224(data: BinaryLike, outputEncoding?:
|
|
50
|
+
declare function cryptoSha3224(data: BinaryLike, outputEncoding?: BufferEncoding): string;
|
|
51
51
|
/**
|
|
52
52
|
* Computes the SHA-3 hash of the given data using the 224-bit digest and returns the raw buffer.
|
|
53
53
|
*
|
|
@@ -67,7 +67,7 @@ declare function cryptoSha3224ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
|
67
67
|
* Computes the SHA-3 hash of the given data using the 256-bit digest.
|
|
68
68
|
*
|
|
69
69
|
* @param {BinaryLike} data - The input data to hash
|
|
70
|
-
* @param {
|
|
70
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
71
71
|
*
|
|
72
72
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
73
73
|
*
|
|
@@ -78,7 +78,7 @@ declare function cryptoSha3224ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
|
78
78
|
* console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
|
79
79
|
* ```
|
|
80
80
|
*/
|
|
81
|
-
declare function cryptoSha3256(data: BinaryLike, outputEncoding?:
|
|
81
|
+
declare function cryptoSha3256(data: BinaryLike, outputEncoding?: BufferEncoding): string;
|
|
82
82
|
/**
|
|
83
83
|
* Computes the SHA-3 hash of the given data using the 256-bit digest and returns the raw buffer.
|
|
84
84
|
*
|
|
@@ -98,7 +98,7 @@ declare function cryptoSha3256ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
|
98
98
|
* Computes the SHA-3 hash of the given data using the 384-bit digest.
|
|
99
99
|
*
|
|
100
100
|
* @param {BinaryLike} data - The input data to hash
|
|
101
|
-
* @param {
|
|
101
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
102
102
|
*
|
|
103
103
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
104
104
|
*
|
|
@@ -109,7 +109,7 @@ declare function cryptoSha3256ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
|
109
109
|
* console.log(cryptoSha3384('test')); // e516dabb23b6e30026863543282780a3ae0dccf05551cf0295178d7f...
|
|
110
110
|
* ```
|
|
111
111
|
*/
|
|
112
|
-
declare function cryptoSha3384(data: BinaryLike, outputEncoding?:
|
|
112
|
+
declare function cryptoSha3384(data: BinaryLike, outputEncoding?: BufferEncoding): string;
|
|
113
113
|
/**
|
|
114
114
|
* Computes the SHA-3 hash of the given data using the 384-bit digest and returns the raw buffer.
|
|
115
115
|
*
|
|
@@ -129,7 +129,7 @@ declare function cryptoSha3384ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
|
129
129
|
* Computes the SHA-3 hash of the given data using the 512-bit digest.
|
|
130
130
|
*
|
|
131
131
|
* @param {BinaryLike} data - The input data to hash
|
|
132
|
-
* @param {
|
|
132
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
133
133
|
*
|
|
134
134
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
135
135
|
*
|
|
@@ -140,7 +140,7 @@ declare function cryptoSha3384ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
|
140
140
|
* console.log(cryptoSha3512('test')); // 9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7...
|
|
141
141
|
* ```
|
|
142
142
|
*/
|
|
143
|
-
declare function cryptoSha3512(data: BinaryLike, outputEncoding?:
|
|
143
|
+
declare function cryptoSha3512(data: BinaryLike, outputEncoding?: BufferEncoding): string;
|
|
144
144
|
/**
|
|
145
145
|
* Computes the SHA-3 hash of the given data using the 512-bit digest and returns the raw buffer.
|
|
146
146
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-hash.d.ts","names":[],"sources":["../src/crypto-hash.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"crypto-hash.d.ts","names":[],"sources":["../src/crypto-hash.ts"],"mappings":";;;;;AAmBA;;;;;;;;;AAAkF;AAkBlF;;;iBAlBgB,SAAA,CAAU,IAAA,EAAM,UAAA,EAAY,cAAA,GAAgB,cAAsB;;;;;AAkBhC;AAmBlD;;;;;;;;;iBAnBgB,iBAAA,CAAkB,IAAA,EAAM,UAAA,GAAU,eAAA;AAqClD;;;;;;;;AAAsD;AAmBtD;;;;;;AAnBA,iBAlBgB,aAAA,CAAc,IAAA,EAAM,UAAA,EAAY,cAAA,GAAgB,cAAsB;;;AAqCA;AAkBtF;;;;;;;;AAAsD;AAmBtD;;iBAxDgB,qBAAA,CAAsB,IAAA,EAAM,UAAA,GAAU,eAAA;;;;;;;AAwDgC;AAkBtF;;;;;;;;iBAvDgB,aAAA,CAAc,IAAA,EAAM,UAAA,EAAY,cAAA,GAAgB,cAAsB;AA0EtF;;;;;;;;;AAAsF;AAkBtF;;;;AAlBA,iBAxDgB,qBAAA,CAAsB,IAAA,EAAM,UAAA,GAAU,eAAA;;;;AA0EA;;;;;;;;;;;;iBAvDtC,aAAA,CAAc,IAAA,EAAM,UAAA,EAAY,cAAA,GAAgB,cAAsB;;;;;;;;;;;;;;;iBAkBtE,qBAAA,CAAsB,IAAA,EAAM,UAAA,GAAU,eAAA;;;;;;;;;;;;;;;;iBAmBtC,aAAA,CAAc,IAAA,EAAM,UAAA,EAAY,cAAA,GAAgB,cAAsB;;;;;;;;;;;;;;;iBAkBtE,qBAAA,CAAsB,IAAA,EAAM,UAAA,GAAU,eAAA"}
|
package/dist/crypto-hash.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
1
2
|
import { createHash } from "node:crypto";
|
|
2
3
|
//#region src/crypto-hash.ts
|
|
3
4
|
/**
|
|
4
5
|
* Computes the MD5 hash of the given data.
|
|
5
6
|
*
|
|
6
7
|
* @param {BinaryLike} data - The input data to hash
|
|
7
|
-
* @param {
|
|
8
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
8
9
|
*
|
|
9
10
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
10
11
|
*
|
|
@@ -16,7 +17,7 @@ import { createHash } from "node:crypto";
|
|
|
16
17
|
* ```
|
|
17
18
|
*/
|
|
18
19
|
function cryptoMd5(data, outputEncoding = "hex") {
|
|
19
|
-
return createHash("md5").update(data).digest(outputEncoding);
|
|
20
|
+
return createHash("md5").update(normalizeHashData(data)).digest(outputEncoding);
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
23
|
* Computes the MD5 hash of the given data and returns the raw buffer.
|
|
@@ -33,13 +34,13 @@ function cryptoMd5(data, outputEncoding = "hex") {
|
|
|
33
34
|
* ```
|
|
34
35
|
*/
|
|
35
36
|
function cryptoMd5ToBuffer(data) {
|
|
36
|
-
return createHash("md5").update(data).digest();
|
|
37
|
+
return createHash("md5").update(normalizeHashData(data)).digest();
|
|
37
38
|
}
|
|
38
39
|
/**
|
|
39
40
|
* Computes the SHA-3 hash of the given data using the 224-bit digest.
|
|
40
41
|
*
|
|
41
42
|
* @param {BinaryLike} data - The input data to hash
|
|
42
|
-
* @param {
|
|
43
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
43
44
|
*
|
|
44
45
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
45
46
|
*
|
|
@@ -51,7 +52,7 @@ function cryptoMd5ToBuffer(data) {
|
|
|
51
52
|
* ```
|
|
52
53
|
*/
|
|
53
54
|
function cryptoSha3224(data, outputEncoding = "hex") {
|
|
54
|
-
return createHash("sha3-224").update(data).digest(outputEncoding);
|
|
55
|
+
return createHash("sha3-224").update(normalizeHashData(data)).digest(outputEncoding);
|
|
55
56
|
}
|
|
56
57
|
/**
|
|
57
58
|
* Computes the SHA-3 hash of the given data using the 224-bit digest and returns the raw buffer.
|
|
@@ -68,13 +69,13 @@ function cryptoSha3224(data, outputEncoding = "hex") {
|
|
|
68
69
|
* ```
|
|
69
70
|
*/
|
|
70
71
|
function cryptoSha3224ToBuffer(data) {
|
|
71
|
-
return createHash("sha3-224").update(data).digest();
|
|
72
|
+
return createHash("sha3-224").update(normalizeHashData(data)).digest();
|
|
72
73
|
}
|
|
73
74
|
/**
|
|
74
75
|
* Computes the SHA-3 hash of the given data using the 256-bit digest.
|
|
75
76
|
*
|
|
76
77
|
* @param {BinaryLike} data - The input data to hash
|
|
77
|
-
* @param {
|
|
78
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
78
79
|
*
|
|
79
80
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
80
81
|
*
|
|
@@ -86,7 +87,7 @@ function cryptoSha3224ToBuffer(data) {
|
|
|
86
87
|
* ```
|
|
87
88
|
*/
|
|
88
89
|
function cryptoSha3256(data, outputEncoding = "hex") {
|
|
89
|
-
return createHash("sha3-256").update(data).digest(outputEncoding);
|
|
90
|
+
return createHash("sha3-256").update(normalizeHashData(data)).digest(outputEncoding);
|
|
90
91
|
}
|
|
91
92
|
/**
|
|
92
93
|
* Computes the SHA-3 hash of the given data using the 256-bit digest and returns the raw buffer.
|
|
@@ -103,13 +104,13 @@ function cryptoSha3256(data, outputEncoding = "hex") {
|
|
|
103
104
|
* ```
|
|
104
105
|
*/
|
|
105
106
|
function cryptoSha3256ToBuffer(data) {
|
|
106
|
-
return createHash("sha3-256").update(data).digest();
|
|
107
|
+
return createHash("sha3-256").update(normalizeHashData(data)).digest();
|
|
107
108
|
}
|
|
108
109
|
/**
|
|
109
110
|
* Computes the SHA-3 hash of the given data using the 384-bit digest.
|
|
110
111
|
*
|
|
111
112
|
* @param {BinaryLike} data - The input data to hash
|
|
112
|
-
* @param {
|
|
113
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
113
114
|
*
|
|
114
115
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
115
116
|
*
|
|
@@ -121,7 +122,7 @@ function cryptoSha3256ToBuffer(data) {
|
|
|
121
122
|
* ```
|
|
122
123
|
*/
|
|
123
124
|
function cryptoSha3384(data, outputEncoding = "hex") {
|
|
124
|
-
return createHash("sha3-384").update(data).digest(outputEncoding);
|
|
125
|
+
return createHash("sha3-384").update(normalizeHashData(data)).digest(outputEncoding);
|
|
125
126
|
}
|
|
126
127
|
/**
|
|
127
128
|
* Computes the SHA-3 hash of the given data using the 384-bit digest and returns the raw buffer.
|
|
@@ -138,13 +139,13 @@ function cryptoSha3384(data, outputEncoding = "hex") {
|
|
|
138
139
|
* ```
|
|
139
140
|
*/
|
|
140
141
|
function cryptoSha3384ToBuffer(data) {
|
|
141
|
-
return createHash("sha3-384").update(data).digest();
|
|
142
|
+
return createHash("sha3-384").update(normalizeHashData(data)).digest();
|
|
142
143
|
}
|
|
143
144
|
/**
|
|
144
145
|
* Computes the SHA-3 hash of the given data using the 512-bit digest.
|
|
145
146
|
*
|
|
146
147
|
* @param {BinaryLike} data - The input data to hash
|
|
147
|
-
* @param {
|
|
148
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
148
149
|
*
|
|
149
150
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
150
151
|
*
|
|
@@ -156,7 +157,7 @@ function cryptoSha3384ToBuffer(data) {
|
|
|
156
157
|
* ```
|
|
157
158
|
*/
|
|
158
159
|
function cryptoSha3512(data, outputEncoding = "hex") {
|
|
159
|
-
return createHash("sha3-512").update(data).digest(outputEncoding);
|
|
160
|
+
return createHash("sha3-512").update(normalizeHashData(data)).digest(outputEncoding);
|
|
160
161
|
}
|
|
161
162
|
/**
|
|
162
163
|
* Computes the SHA-3 hash of the given data using the 512-bit digest and returns the raw buffer.
|
|
@@ -173,7 +174,10 @@ function cryptoSha3512(data, outputEncoding = "hex") {
|
|
|
173
174
|
* ```
|
|
174
175
|
*/
|
|
175
176
|
function cryptoSha3512ToBuffer(data) {
|
|
176
|
-
return createHash("sha3-512").update(data).digest();
|
|
177
|
+
return createHash("sha3-512").update(normalizeHashData(data)).digest();
|
|
178
|
+
}
|
|
179
|
+
function normalizeHashData(data) {
|
|
180
|
+
return typeof data === "string" || ArrayBuffer.isView(data) ? data : Buffer.from(data);
|
|
177
181
|
}
|
|
178
182
|
//#endregion
|
|
179
183
|
export { cryptoMd5, cryptoMd5ToBuffer, cryptoSha3224, cryptoSha3224ToBuffer, cryptoSha3256, cryptoSha3256ToBuffer, cryptoSha3384, cryptoSha3384ToBuffer, cryptoSha3512, cryptoSha3512ToBuffer };
|