@kikiutils/shared 15.1.1 → 17.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 +0 -1
- package/dist/buffer.d.ts.map +1 -1
- package/dist/classes/path.d.ts +0 -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 +0 -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 -7
- 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/consola.d.ts +2 -4
- package/dist/consola.d.ts.map +1 -1
- package/dist/crypto-hash.d.ts +11 -12
- 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 +0 -1
- package/dist/datetime.d.ts.map +1 -1
- package/dist/element-plus.d.ts +0 -1
- package/dist/element-plus.d.ts.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/event-awaiter.d.ts.map +1 -1
- package/dist/general.d.ts.map +1 -1
- package/dist/hash.d.ts.map +1 -1
- package/dist/math.d.ts +0 -1
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js.map +1 -1
- package/dist/number.d.ts +0 -1
- package/dist/number.d.ts.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 +10 -5
- package/dist/pino.js.map +1 -1
- package/dist/random.d.ts.map +1 -1
- package/dist/storages/lru/keyed-store.d.ts +0 -1
- package/dist/storages/lru/keyed-store.d.ts.map +1 -1
- package/dist/storages/redis/keyed-store.d.ts +2 -3
- package/dist/storages/redis/keyed-store.d.ts.map +1 -1
- package/dist/storages/redis/msgpack.d.ts +0 -1
- package/dist/storages/redis/msgpack.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.d.ts.map +1 -1
- package/dist/string.js +7 -10
- package/dist/string.js.map +1 -1
- package/dist/time.d.ts +29 -7
- package/dist/time.d.ts.map +1 -1
- package/dist/time.js +55 -11
- package/dist/time.js.map +1 -1
- package/dist/types/filtered-key-path.d.ts +1 -2
- package/dist/types/filtered-key-path.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/vue.d.ts +1 -3
- package/dist/types/vue.d.ts.map +1 -1
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js.map +1 -1
- package/dist/vue.d.ts +6 -8
- 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 +2 -1
- package/dist/web.js.map +1 -1
- package/package.json +28 -27
- 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/time.ts +65 -15
- package/src/types/index.ts +0 -5
- package/src/types/vue.ts +1 -3
- 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
CHANGED
package/dist/buffer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.d.ts","names":[],"sources":["../src/buffer.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"buffer.d.ts","names":[],"sources":["../src/buffer.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkCsB,SAAS,OAAO,cAAW,QAAA,OAAA"}
|
package/dist/classes/path.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import * as fsp from "node:fs/promises";
|
|
|
3
3
|
import * as nodePath from "node:path";
|
|
4
4
|
import { Abortable } from "node:events";
|
|
5
5
|
import * as fs from "node:fs";
|
|
6
|
-
|
|
7
6
|
//#region src/classes/path.d.ts
|
|
8
7
|
type DropFirstParameters<T extends (...args: any) => any> = Parameters<T> extends [any, ...infer R] ? R : never;
|
|
9
8
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.d.ts","names":[],"sources":["../../src/classes/path.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"path.d.ts","names":[],"sources":["../../src/classes/path.ts"],"mappings":";;;;;;KAmBK,oBAAoB,cAAc,qBAAqB,WAAW,0BAA0B,KAAK;;;;KAK1F,WAAW,GAAG,WAAW;;;;;;;cAQxB;;;;;;;EAQG,eAAG,OAAO;GASrB,OAAO,aAAa;;;;MAmBjB,UAAM;;;;MAON;;;;SASG,OAAO,YAAY,SAAS,wBAAqB;;;;SAOjD,WAAW,OAAO,aAAU;;;;EASnC,SAAS;;;;EAOT,WAAO;;;;EAOP;;;;EAOA;;;;EAOA,aAAS;;;;EAOT,QAAQ,OAAO,aAAU;;;;EAOzB,SAAK,SAAA;;;;EAOL,SAAS,IAAI,WAAQ;;;;EAOrB,WAAO;EAIP;;;;EAOA;;;;;;EASA;;;;EASA,UAAU,MAAM,2BAA2B,IAAI,UAAO;;;;EAOtD,cAAc,M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
|
-
{"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,KAAK,CAAC;CAChD;CAGA,CAAC,OAAO,IAAI,4BAA4B,KAAK;EACzC,OAAO,KAAKD;CAChB;CAEA,CAAC,OAAO,aAAa,MAAc;EAC/B,IAAI,SAAS,UAAU,MAAM,IAAI,UAAU,mCAAmC;EAC9E,OAAO,KAAKA;CAChB;CAGA,aAAa,GAAG,OAAmB;EAC/B,OA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,UAAU,KAAKA,QAAQ,GAAG,IAAI;CAC7C;AACJ"}
|
|
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,KAAK,CAAC;CAChD;CAGA,CAAC,OAAO,IAAI,4BAA4B,KAAK;EACzC,OAAO,KAAKD;CAChB;CAEA,CAAC,OAAO,aAAa,MAAc;EAC/B,IAAI,SAAS,UAAU,MAAM,IAAI,UAAU,mCAAmC;EAC9E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A,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":";;;;;
|
|
1
|
+
{"version":3,"file":"precision-number.d.ts","names":[],"sources":["../../src/classes/precision-number.ts"],"mappings":";;;;;KAKY,uBAAuB,QAAQ,QAAQ;EAAoB;;;;;;;;;;;;;;;;;;;;;cAqB1D;;;;;;;;;EAcL,YAAA,QAAO,sBACP,wBACA,WAAU,QAAQ;;;;;;GAqBrB,OAAO,aAAa;;;;MAmBjB;;;;MAOA,YAAQ,QAAA;;;;MAOR;;;;;;;;;;SAaG,QACH,OAAO,sBACP,wBACA,WAAU,QAAQ;;;;;;EAYtB;;;;;;;;EAYA;;;;;;;;;;;EAeA,MAAM,KAAK,sBAAsB,KAAK;;;;EAWtC,SAAK;;;;;;;;EAWL,UAAU,OAAO;;;;;;;;EAYjB,OAAO,OAAO;;;;;;;;EAWd;;;;EAQA,GAAG,OAAO;;;;EAOV,IAAI,OAAO;;;;EAOX;;;;EAOA;;;;EAOA;;;;EAOA;;;;EAOA;;;;EAOA;;;;EAOA,GAAG,OAAO;;;;EAOV,IAAI,OAAO;;;;EAOX,MAAM,OAAO;;;;;;;;EAYb,OAAO,OAAO;;;;EAQd;;;;EAQA,KAAK,OAAO;;;;;;;;EAYZ,IAAI,OAAO;;;;EAQX,MAAM,OAAO;;;;EAQb,mBAAe;;;;EAOf,UAAM;;;;;;;;;EAYN,UAAU,KAAK,sBAAsB,KAAK,uBAAoB;;;;EAO9D,YAAY,OAAO,uBAAoB;;;;EAWvC,WAAO;;;;EAOP;;;;EAOA,QAAQ,OAAO,uBAAoB;;;;EAWnC,SAAS,OAAO,uBAAoB;;;;EAWpC,aAAS;;;;EAOT,OAAO,OAAO,uBAAoB;;;;EAOlC,MAAM,OAAO,uBAAoB;;;;;;EASjC;;;;EAOA;;;;EAOA,QAAQ,wBAA6C,WAAU,QAAQ;;;;EAOvE,QAAQ,OAAO,uBAAoB"}
|
|
@@ -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,SAAS,EAAE,KAAK,CAAC,CAAC;CACpF;;;;CAOA,CAAC,OAAO,IAAI,4BAA4B,KAAK;EACzC,OAAO,KAAK;CAChB;;;;;;CAOA,CAAC,OAAO,aAAa,MAAc;EAC/B,IAAI,SAAS,UAAU,OAAO,KAAKD,SAAS,SAAS;EACrD,OAAO,KAAK;CAChB;CAGA,uBAAuB,SAAkB;EACrC,OAAO,QAAQ,gBAAgB,KAAKF,gBAAgB,KAAKC,SAAS;CACtE;CAEA,eAAe,OAA6B;EACxC,OAAO,MAAM,SAAS,EAAE,KAAK;CACjC;;;;CAOA,IAAI,gBAAgB;EAChB,OAAO,KAAKD;CAChB;;;;CAKA,IAAI,WAA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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
|
+
{"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;CA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AAKC,SAAS,OAAO,KAAKE,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,9 +1,6 @@
|
|
|
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
|
-
|
|
7
4
|
//#region src/classes/ssh-client.d.ts
|
|
8
5
|
declare const loggerLevelStringToConsolaLogLevelMap: {
|
|
9
6
|
readonly debug: 4;
|
|
@@ -22,16 +19,16 @@ declare class SshClient {
|
|
|
22
19
|
get nodeSsh(): NodeSSH;
|
|
23
20
|
connect(): Promise<boolean>;
|
|
24
21
|
disconnect(): boolean;
|
|
25
|
-
execCommand(command: string, options?: SSHExecCommandOptions): Promise<void |
|
|
26
|
-
execCommandWithIo(command: string, options?: SSHExecCommandOptions): Promise<void |
|
|
22
|
+
execCommand(command: string, options?: SSHExecCommandOptions): Promise<void | import("node-ssh").SSHExecCommandResponse>;
|
|
23
|
+
execCommandWithIo(command: string, options?: SSHExecCommandOptions): Promise<void | import("node-ssh").SSHExecCommandResponse>;
|
|
27
24
|
getDir: (localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions) => Promise<boolean>;
|
|
28
25
|
getDirectory(localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions): Promise<boolean>;
|
|
29
|
-
getFile(localFile: PathLike, remoteFile: PathLike, givenSftp?:
|
|
26
|
+
getFile(localFile: PathLike, remoteFile: PathLike, givenSftp?: null | SFTPWrapper, transferOptions?: null | TransferOptions): Promise<boolean>;
|
|
30
27
|
isConnected(): boolean;
|
|
31
28
|
mkdir(path: PathLike): Promise<boolean>;
|
|
32
29
|
putDir: (localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions) => Promise<boolean>;
|
|
33
30
|
putDirectory(localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions): Promise<boolean>;
|
|
34
|
-
putFile(localFile: PathLike, remoteFile: PathLike, givenSftp?:
|
|
31
|
+
putFile(localFile: PathLike, remoteFile: PathLike, givenSftp?: null | SFTPWrapper, transferOptions?: null | TransferOptions): Promise<boolean>;
|
|
35
32
|
putFiles(files: {
|
|
36
33
|
local: PathLike;
|
|
37
34
|
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;;;;;;;;;;;cAYO;;EAMG,YAAA,cAAc,kBAAkB,kBAAkB,eAAmB,gBAAgB;MAc7F,WAAO;EAIL,WAAO;EAUb;EAUA,YAAY,iBAAiB,UAAU,wBAAqB,kCAAA;EAI5D,kBAAkB,iBAAiB,UAAU,wBAAqB,kCAAA;EAWlE,SAAM,gBAE6B,UAAQ,iBAAmB,UAAQ,UAAY,8BAAyB;EAArG,aAAa,gBAAgB,UAAU,iBAAiB,UAAU,UAAU,4BAAyB;EASrG,QACF,WAAW,UACX,YAAY,UACZ,mBAAmB,aACnB,yBAAyB,kBAAe;EAW5C;EAIM,MAAM,MAAM,WAAQ;EAU1B,SAAM,gBAE6B,UAAQ,iBAAmB,UAAQ,UAAY,8BAAyB;EAArG,aAAa,gBAAgB,UAAU,iBAAiB,UAAU,UAAU,4BAAyB;EASrG,QACF,WAAW,UACX,YAAY,UACZ,mBAAmB,aACnB,yBAAyB,kBAAe;EAWtC,SAAS;IAAS,OAAO;IAAU,QAAQ;OAAc,UAAU,qBAAkB;EAe3F,eAAe,oBAAoB"}
|
|
@@ -1 +1 @@
|
|
|
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 {
|
|
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;EAC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AI;GACA,MAAM,KAAKA,SAAS,MAAM,KAAK,SAAS,CAAC;GACzC,OAAO;EACX,SAAS,OAAO;GACZ,KAAKD,QAAQ,MAAM,KAAK;GACxB,OAAO;EACX;CACJ;CAEA,SAAS,KAAK;CAEd,MAAM,aAAa,gBAA0B,iBAA2B,SAAqC;EACzG,IAAI;GACA,OAAO,MAAM,KAAKC,SAAS,aAAa,eAAe,SAAS,GAAG,gBAAgB,SAAS,GAAG,OAAO;EAC1G,SAAS,OAAO;GACZ,KAAKD,QAAQ,MAAM,KAAK;GACxB,OAAO;EACX;CACJ;CAEA,MAAM,QACF,WACA,YACA,WACA,iBACF;EACE,IAAI;GACA,MAAM,KAAKC,SAAS,QAAQ,UAAU,SAAS,GAAG,WAAW,SAAS,GAAG,WAAW,eAAe;GACnG,OAAO;EACX,SAAS,OAAO;GACZ,KAAKD,QAAQ,MAAM,KAAK;GACxB,OAAO;EACX;CACJ;CAEA,MAAM,SAAS,OAAgD,SAA8B;EACzF,IAAI;GACA,MAAM,iBAAiB,MAAM,KAAK,EAAE,OAAO,cAAc;IACrD,OAAO,MAAM,SAAS;IACtB,QAAQ,OAAO,SAAS;GAC5B,EAAE;GAEF,MAAM,KAAKC,SAAS,SAAS,gBAAgB,OAAO;GACpD,OAAO;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
|
|
1
|
+
{"version":3,"file":"clipboard.d.ts","names":[],"sources":["../src/clipboard.ts"],"mappings":";KAAK;EACC;EAAgB;;EAChB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8BgB,oBAAoB,MAAM,MAAM,UAAU,uBAAuB,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8CzE,oBAAoB,eAAe,QAAQ"}
|
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":";;;;;;;;;;;;;;;;;;;;;;cAuBa,iCAAa;cACb,0BAAM"}
|
package/dist/crypto-hash.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { BinaryLike
|
|
2
|
-
|
|
1
|
+
import { BinaryLike } from "node:crypto";
|
|
3
2
|
//#region src/crypto-hash.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Computes the MD5 hash of the given data.
|
|
6
5
|
*
|
|
7
6
|
* @param {BinaryLike} data - The input data to hash
|
|
8
|
-
* @param {
|
|
7
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
9
8
|
*
|
|
10
9
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
11
10
|
*
|
|
@@ -16,7 +15,7 @@ import { BinaryLike, BinaryToTextEncoding } from "node:crypto";
|
|
|
16
15
|
* console.log(cryptoMd5('test')); // 098f6bcd4621d373cade4e832627b4f6
|
|
17
16
|
* ```
|
|
18
17
|
*/
|
|
19
|
-
declare function cryptoMd5(data: BinaryLike, outputEncoding?:
|
|
18
|
+
declare function cryptoMd5(data: BinaryLike, outputEncoding?: BufferEncoding): string;
|
|
20
19
|
/**
|
|
21
20
|
* Computes the MD5 hash of the given data and returns the raw buffer.
|
|
22
21
|
*
|
|
@@ -36,7 +35,7 @@ declare function cryptoMd5ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
|
36
35
|
* Computes the SHA-3 hash of the given data using the 224-bit digest.
|
|
37
36
|
*
|
|
38
37
|
* @param {BinaryLike} data - The input data to hash
|
|
39
|
-
* @param {
|
|
38
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
40
39
|
*
|
|
41
40
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
42
41
|
*
|
|
@@ -47,7 +46,7 @@ declare function cryptoMd5ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
|
47
46
|
* console.log(cryptoSha3224('test')); // 3797bf0afbbfca4a7bbba7602a2b552746876517a7f9b7ce2db0ae7b
|
|
48
47
|
* ```
|
|
49
48
|
*/
|
|
50
|
-
declare function cryptoSha3224(data: BinaryLike, outputEncoding?:
|
|
49
|
+
declare function cryptoSha3224(data: BinaryLike, outputEncoding?: BufferEncoding): string;
|
|
51
50
|
/**
|
|
52
51
|
* Computes the SHA-3 hash of the given data using the 224-bit digest and returns the raw buffer.
|
|
53
52
|
*
|
|
@@ -67,7 +66,7 @@ declare function cryptoSha3224ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
|
67
66
|
* Computes the SHA-3 hash of the given data using the 256-bit digest.
|
|
68
67
|
*
|
|
69
68
|
* @param {BinaryLike} data - The input data to hash
|
|
70
|
-
* @param {
|
|
69
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
71
70
|
*
|
|
72
71
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
73
72
|
*
|
|
@@ -78,7 +77,7 @@ declare function cryptoSha3224ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
|
78
77
|
* console.log(cryptoSha3256('test')); // 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
|
79
78
|
* ```
|
|
80
79
|
*/
|
|
81
|
-
declare function cryptoSha3256(data: BinaryLike, outputEncoding?:
|
|
80
|
+
declare function cryptoSha3256(data: BinaryLike, outputEncoding?: BufferEncoding): string;
|
|
82
81
|
/**
|
|
83
82
|
* Computes the SHA-3 hash of the given data using the 256-bit digest and returns the raw buffer.
|
|
84
83
|
*
|
|
@@ -98,7 +97,7 @@ declare function cryptoSha3256ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
|
98
97
|
* Computes the SHA-3 hash of the given data using the 384-bit digest.
|
|
99
98
|
*
|
|
100
99
|
* @param {BinaryLike} data - The input data to hash
|
|
101
|
-
* @param {
|
|
100
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
102
101
|
*
|
|
103
102
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
104
103
|
*
|
|
@@ -109,7 +108,7 @@ declare function cryptoSha3256ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
|
109
108
|
* console.log(cryptoSha3384('test')); // e516dabb23b6e30026863543282780a3ae0dccf05551cf0295178d7f...
|
|
110
109
|
* ```
|
|
111
110
|
*/
|
|
112
|
-
declare function cryptoSha3384(data: BinaryLike, outputEncoding?:
|
|
111
|
+
declare function cryptoSha3384(data: BinaryLike, outputEncoding?: BufferEncoding): string;
|
|
113
112
|
/**
|
|
114
113
|
* Computes the SHA-3 hash of the given data using the 384-bit digest and returns the raw buffer.
|
|
115
114
|
*
|
|
@@ -129,7 +128,7 @@ declare function cryptoSha3384ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
|
129
128
|
* Computes the SHA-3 hash of the given data using the 512-bit digest.
|
|
130
129
|
*
|
|
131
130
|
* @param {BinaryLike} data - The input data to hash
|
|
132
|
-
* @param {
|
|
131
|
+
* @param {BufferEncoding} [outputEncoding] - The output encoding (default: `'hex'`)
|
|
133
132
|
*
|
|
134
133
|
* @returns {string | Buffer} The hash digest in the specified encoding
|
|
135
134
|
*
|
|
@@ -140,7 +139,7 @@ declare function cryptoSha3384ToBuffer(data: BinaryLike): NonSharedBuffer;
|
|
|
140
139
|
* console.log(cryptoSha3512('test')); // 9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7...
|
|
141
140
|
* ```
|
|
142
141
|
*/
|
|
143
|
-
declare function cryptoSha3512(data: BinaryLike, outputEncoding?:
|
|
142
|
+
declare function cryptoSha3512(data: BinaryLike, outputEncoding?: BufferEncoding): string;
|
|
144
143
|
/**
|
|
145
144
|
* Computes the SHA-3 hash of the given data using the 512-bit digest and returns the raw buffer.
|
|
146
145
|
*
|
|
@@ -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":";;;;;;;;;;;;;;;;;iBAmBgB,UAAU,MAAM,YAAY,iBAAgB;;;;;;;;;;;;;;;iBAkB5C,kBAAkB,MAAM,aAAU;;;;;;;;;;;;;;;;iBAmBlC,cAAc,MAAM,YAAY,iBAAgB;;;;;;;;;;;;;;;iBAkBhD,sBAAsB,MAAM,aAAU;;;;;;;;;;;;;;;;iBAmBtC,cAAc,MAAM,YAAY,iBAAgB;;;;;;;;;;;;;;;iBAkBhD,sBAAsB,MAAM,aAAU;;;;;;;;;;;;;;;;iBAmBtC,cAAc,MAAM,YAAY,iBAAgB;;;;;;;;;;;;;;;iBAkBhD,sBAAsB,MAAM,aAAU;;;;;;;;;;;;;;;;iBAmBtC,cAAc,MAAM,YAAY,iBAAgB;;;;;;;;;;;;;;;iBAkBhD,sBAAsB,MAAM,aAAU"}
|
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 };
|