@kikiutils/shared 15.0.2 → 15.1.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.
Files changed (56) hide show
  1. package/README.md +137 -67
  2. package/dist/buffer.js.map +1 -1
  3. package/dist/classes/path.d.ts +8 -0
  4. package/dist/classes/path.d.ts.map +1 -1
  5. package/dist/classes/path.js +5 -0
  6. package/dist/classes/path.js.map +1 -1
  7. package/dist/classes/precision-number.d.ts +215 -11
  8. package/dist/classes/precision-number.d.ts.map +1 -1
  9. package/dist/classes/precision-number.js +268 -25
  10. package/dist/classes/precision-number.js.map +1 -1
  11. package/dist/classes/ssh-client.js.map +1 -1
  12. package/dist/clipboard.js.map +1 -1
  13. package/dist/consola.js.map +1 -1
  14. package/dist/crypto-hash.d.ts +7 -7
  15. package/dist/crypto-hash.js +7 -7
  16. package/dist/crypto-hash.js.map +1 -1
  17. package/dist/datetime.js.map +1 -1
  18. package/dist/element-plus.js.map +1 -1
  19. package/dist/enum.js.map +1 -1
  20. package/dist/env.js.map +1 -1
  21. package/dist/event-awaiter.js.map +1 -1
  22. package/dist/general.js.map +1 -1
  23. package/dist/hash.d.ts +3 -3
  24. package/dist/hash.js +3 -3
  25. package/dist/hash.js.map +1 -1
  26. package/dist/math.js.map +1 -1
  27. package/dist/number.js.map +1 -1
  28. package/dist/object.js.map +1 -1
  29. package/dist/pino.js.map +1 -1
  30. package/dist/random.js.map +1 -1
  31. package/dist/storages/lru/keyed-store.d.ts +3 -3
  32. package/dist/storages/lru/keyed-store.js +11 -3
  33. package/dist/storages/lru/keyed-store.js.map +1 -1
  34. package/dist/storages/redis/keyed-store.d.ts +1 -1
  35. package/dist/storages/redis/keyed-store.js +1 -1
  36. package/dist/storages/redis/keyed-store.js.map +1 -1
  37. package/dist/storages/redis/msgpack.js.map +1 -1
  38. package/dist/string.d.ts +12 -6
  39. package/dist/string.d.ts.map +1 -1
  40. package/dist/string.js +9 -6
  41. package/dist/string.js.map +1 -1
  42. package/dist/time.js.map +1 -1
  43. package/dist/types/index.d.ts +30 -0
  44. package/dist/types/index.d.ts.map +1 -1
  45. package/dist/url.js.map +1 -1
  46. package/dist/vue.js.map +1 -1
  47. package/dist/web.js.map +1 -1
  48. package/package.json +15 -24
  49. package/src/classes/path.ts +9 -0
  50. package/src/classes/precision-number.ts +300 -25
  51. package/src/crypto-hash.ts +7 -7
  52. package/src/hash.ts +3 -3
  53. package/src/storages/lru/keyed-store.ts +3 -3
  54. package/src/storages/redis/keyed-store.ts +1 -1
  55. package/src/string.ts +12 -6
  56. package/src/types/index.ts +39 -0
package/README.md CHANGED
@@ -5,30 +5,34 @@
5
5
  [![codecov][codecov-src]][codecov-href]
6
6
  [![License][license-src]][license-href]
7
7
 
8
- A lightweight and modular utility library for modern JavaScript and TypeScript — includes secure hashing, flexible logging, datetime tools, Vue/web helpers, storage abstraction, and more.
8
+ A lightweight, modular TypeScript utility library for Node.js and browser projects. It groups small, focused helpers for binary conversion, hashing, logging, dates, enum extraction, environment variables, numeric formatting, strings, URLs, Vue, web redirects, and typed storage wrappers.
9
9
 
10
10
  - [✨ Release Notes](./CHANGELOG.md)
11
11
 
12
12
  ## Features
13
13
 
14
- - 📋 Clipboard utilities — copy text and blobs using the modern Clipboard API (Browser only)
15
- - 📜 Logging utilities — simple and extensible logging via Consola and Pino
16
- - 🔒 Crypto utilities — secure hashing functions: MD5, SHA3-224/256/384/512
17
- - 📅 Datetime utilities — manipulate, format, and offset dates and ranges
18
- - 🔢 Enum utilities — extract enum keys and values (number or string)
19
- - 🌱 Environment helpers — safe env var access with error handling (Node only)
20
- - 📈 Math utilities — rounding, formatting percentages, and ratios
21
- - 💎 Number utilities — number padding, compact display, currency formatting
22
- - 🔤 String utilities — casing, trimming, random string generation, etc.
23
- - 🌐 URL utilities — parse and construct query strings and redirect URLs
24
- - 🧩 Vue 3 utilities — composables like scroll preservation and key handling
25
- - 🖥️ Web utilities — browser DOM helpers (e.g. scroll to top, key matching)
26
- - 🗄️ Storage utilities — enhanced localStorage, Redis, and LRU abstractions
27
- - 📦 Modular by design — import only what you need via `@kikiutils/shared/<module>`
14
+ - 📦 Modular imports — import only the modules you use via `@kikiutils/shared/<module>`.
15
+ - 🧱 TypeScript-first — ships source and declaration output for strongly typed utility APIs.
16
+ - 🔁 General helpers — normalize single-or-array values with `extractFirstValue`.
17
+ - 🧬 Binary helpers — convert `Blob`, `File`, `ArrayBuffer`, `Uint8Array`, and `Buffer` to Node `Buffer`.
18
+ - 🔒 Hashing helpers — SHA-3 helpers for universal usage and Node `crypto` MD5/SHA-3 helpers.
19
+ - 📜 Logging helpers — preconfigured Consola and Pino logger instances with env-based levels.
20
+ - 📅 Date helpers — format dates and compute common ranges such as today, this week, and last month.
21
+ - 🔢 Number and math helpers — compact number display, precise percentages, and fixed-decimal arithmetic.
22
+ - 🔤 String/random helpers — random strings and randomized-length value generation.
23
+ - 🧾 Object helpers — deterministic nested object serialization for signatures and cache keys.
24
+ - 🧭 URL helpers — append or replace redirect query parameters safely.
25
+ - 🌱 Environment helpers — read required environment variables with a dedicated missing-env error.
26
+ - 🧩 Vue/web helpers — Vue Router redirects, timer ref cleanup, scroll preservation, and browser redirects.
27
+ - 🗄️ Storage helpers — typed keyed-store facades for LRU cache and Redis-like storage.
28
+ - 🛤️ Class utilities — immutable `Path` wrapper and chainable `PrecisionNumber` arithmetic.
29
+ - 🧰 Shared types — reusable nullable, readonly, partial-record, binary-input, and filtered-key-path types.
28
30
 
29
31
  ## Requirements
30
32
 
31
33
  - **Node.js** `>=22.12.0`
34
+ - **ESM** package (`"type": "module"`)
35
+ - Optional peer dependencies are installed only when you use the modules that need them.
32
36
 
33
37
  ## Installation
34
38
 
@@ -38,70 +42,136 @@ Using [pnpm](https://pnpm.io):
38
42
  pnpm add @kikiutils/shared
39
43
  ```
40
44
 
41
- You can also use `yarn`, `npm`, or `bun`.
45
+ You can also use `npm`, `yarn`, or `bun`.
42
46
 
43
47
  > [!NOTE]
44
- > This package is modular. It does not install all dependencies by default.
45
- >
46
- > If a utility depends on a third-party package (e.g. `date-fns`), you must install it manually.
48
+ > This package is intentionally modular. Imports such as `@kikiutils/shared/datetime` or `@kikiutils/shared/vue` may require their peer dependencies (`date-fns`, `vue`, and so on). Install only the peers used by your chosen modules.
47
49
 
48
- ## Modules
50
+ ## Usage and import style
49
51
 
50
- ```
51
- src/
52
- ├── classes/ # Class-based utilities
53
- │ ├── path.ts # Path manipulation
54
- │ ├── precision-number.ts # Decimal.js wrapper
55
- │ └── ssh-client.ts # SSH client
56
- │
57
- ├── storages/
58
- │ ├── lru/keyed-store.ts # LRU cache wrapper
59
- │ └── redis/
60
- │ ├── keyed-store.ts # Redis keyed store
61
- │ ├── msgpack.ts # Redis + msgpack
62
- │ └── types.ts # Storage interfaces
63
- │
64
- └── *.ts # Utility functions (see table)
65
- ```
66
-
67
- | File | Description |
68
- |------|-------------|
69
- | `buffer.ts` | Binary → Node.js Buffer |
70
- | `clipboard.ts` | Clipboard API (browser) |
71
- | `consola.ts` | Consola logger |
72
- | `crypto-hash.ts` | MD5, SHA3 (Node) |
73
- | `datetime.ts` | date-fns wrappers |
74
- | `element-plus.ts` | Element Plus form rules |
75
- | `enum.ts` | Enum value extractors |
76
- | `env.ts` | Env var accessor |
77
- | `event-awaiter.ts` | Async event wait |
78
- | `general.ts` | extractFirstValue |
79
- | `hash.ts` | SHA3 (browser) |
80
- | `math.ts` | toPercentageString |
81
- | `number.ts` | toCompactNumberString |
82
- | `object.ts` | deterministic stringify |
83
- | `pino.ts` | Pino logger |
84
- | `random.ts` | nested random length |
85
- | `string.ts` | randomString |
86
- | `time.ts` | abortableDelay |
87
- | `url.ts` | redirect param |
88
- | `vue.ts` | Vue composables |
89
- | `web.ts` | Web DOM helpers |
90
-
91
- ## Usage
52
+ Import individual modules to keep dependency usage explicit:
92
53
 
93
54
  ```typescript
94
55
  import { logger } from '@kikiutils/shared/consola';
95
56
  import { extractFirstValue } from '@kikiutils/shared/general';
96
57
 
97
- const data = [
58
+ const value = extractFirstValue([
98
59
  0,
99
60
  1,
100
- ];
61
+ ]);
62
+
63
+ logger.info(value); // 0
64
+ ```
65
+
66
+ ## Module guide
67
+
68
+ | Module | Runtime | Main exports | Use case |
69
+ | --- | --- | --- | --- |
70
+ | `buffer` | Node/browser-compatible inputs, Node output | `toBuffer` | Convert `Blob`, `File`, `ArrayBuffer`, `Uint8Array`, or `Buffer` to Node `Buffer`. |
71
+ | `clipboard` | Browser | `copyTextToClipboard`, `copyBlobToClipboard` | Safe result wrappers around the modern Clipboard API. |
72
+ | `consola` | Node/browser | `consolaLogger`, `logger` | Shared Consola instance with env-based log level. |
73
+ | `crypto-hash` | Node | `cryptoMd5`, `cryptoSha3*`, `*ToBuffer` | Node `crypto` MD5/SHA-3 helpers with text or raw-buffer output. |
74
+ | `datetime` | Node/browser | `formatDate`, `getDateRangeFromDate`, `getMidnightDateFromToday` | Date formatting and common date-range calculations via `date-fns`. |
75
+ | `element-plus` | Vue/browser | `createElFormItemRuleWithDefaults` | Create Element Plus form rules with default `required`, `trigger`, and `type`. |
76
+ | `enum` | Any | `getEnumValues`, `getEnumNumberValues`, `getEnumStringValues` | Extract TypeScript enum values while ignoring numeric reverse mappings. |
77
+ | `env` | Node | `checkAndGetEnvValue`, `EnvironmentNotFoundError` | Read required env vars without treating empty strings as missing. |
78
+ | `event-awaiter` | Any | `EventAwaiter` | Wait/trigger keyed asynchronous events with timeout, abort, strict, and override modes. |
79
+ | `general` | Any | `extractFirstValue` | Normalize a single value or array into the first resolved value. |
80
+ | `hash` | Any | `sha3224`, `sha3256`, `sha3384`, `sha3512` | SHA-3 helpers backed by `@noble/hashes`; returns hex strings. |
81
+ | `math` | Any | `toPercentageString` | Precise percentage strings using `decimal.js`. |
82
+ | `number` | Any | `toCompactNumberString` | Compact display strings using `millify`. |
83
+ | `object` | Any | `stringifyObjectDeterministically` | Stable flattened object serialization for signatures/cache keys. |
84
+ | `pino` | Node | `pinoLogger`, `logger` | Shared Pino logger with pretty output and env-based level. |
85
+ | `random` | Any | `generateWithNestedRandomLength` | Generate values with a two-step randomized length. |
86
+ | `string` | Any | `randomString` | Random strings from preset character sets. |
87
+ | `time` | Any | `abortableDelay` | Promise delay that resolves early on abort. |
88
+ | `url` | Any | `appendRedirectParamToUrl` | Add or replace a `redirect` query parameter. |
89
+ | `vue` | Vue/browser | `appendRedirectParamFromCurrentRouteToUrl`, `clearIntervalRef`, `clearTimeoutRef`, `usePreserveScroll` | Vue Router redirect and ref cleanup helpers. |
90
+ | `web` | Browser | `appendRedirectParamFromCurrentLocationToUrl`, `assignUrlWithRedirectParamFromCurrentLocation` | Browser redirect helpers based on `window.location`. |
91
+ | `classes/path` | Node | `Path` | Immutable path wrapper plus common `fs/promises` delegations. |
92
+ | `classes/precision-number` | Any | `PrecisionNumber` | Chainable fixed-decimal arithmetic powered by `decimal.js`. |
93
+ | `storages/lru/keyed-store` | Any | `createLruKeyedStore` | Typed key resolver wrapper around `lru-cache`. |
94
+ | `storages/redis/keyed-store` | Node | `createRedisKeyedStore` | Typed key resolver wrapper around Redis-like storage. |
95
+ | `storages/redis/msgpack` | Node | `createRedisMsgpackStorage` | Redis-like storage facade with MessagePack serialization. |
96
+ | `types` | TypeScript | Common utility types | Shared utility and path-filtering types. |
97
+
98
+ ## Examples
99
+
100
+ ### Required environment variable
101
+
102
+ ```typescript
103
+ import { checkAndGetEnvValue } from '@kikiutils/shared/env';
104
+
105
+ const apiKey = checkAndGetEnvValue('API_KEY');
106
+ ```
107
+
108
+ ### Date ranges
109
+
110
+ ```typescript
111
+ import { getDateRangeFromDate } from '@kikiutils/shared/datetime';
112
+
113
+ const range = getDateRangeFromDate(new Date(), 'thisWeek', { weekStartsOn: 1 });
114
+ console.log(range.startDate, range.endDate);
115
+ ```
116
+
117
+ ### Precise numeric display
118
+
119
+ ```typescript
120
+ import { PrecisionNumber } from '@kikiutils/shared/classes/precision-number';
121
+ import { toPercentageString } from '@kikiutils/shared/math';
101
122
 
102
- const value = extractFirstValue(data);
103
- console.log(value); // 0
104
- logger.info(value);
123
+ const amount = new PrecisionNumber('1.239', 2).plus('2.111');
124
+ console.log(amount.toString()); // 3.35
125
+ console.log(toPercentageString(1, 3, { decimalPlaces: 2 })); // 33.33%
126
+ ```
127
+
128
+ ### Browser redirect preservation
129
+
130
+ ```typescript
131
+ import { appendRedirectParamToUrl } from '@kikiutils/shared/url';
132
+
133
+ const loginUrl = appendRedirectParamToUrl('/login', '/dashboard?tab=home');
134
+ // /login?redirect=%2Fdashboard%3Ftab%3Dhome
135
+ ```
136
+
137
+ ### LRU keyed store
138
+
139
+ ```typescript
140
+ import { createLruKeyedStore } from '@kikiutils/shared/storages/lru/keyed-store';
141
+ import { LRUCache } from 'lru-cache';
142
+
143
+ const cache = new LRUCache<string, { name: string }>({ max: 100 });
144
+ const users = createLruKeyedStore<{ name: string }>(cache)((id: string) => `user:${id}`);
145
+
146
+ users.setItem({ name: 'Alice' }, '1');
147
+ console.log(users.getItem('1')); // { name: 'Alice' }
148
+ ```
149
+
150
+ ## Optional peer dependencies
151
+
152
+ Most modules are tiny wrappers around platform APIs or optional peers. If your package manager does not auto-install peers, add the ones you import:
153
+
154
+ | Module | Peer dependency |
155
+ | --- | --- |
156
+ | `crypto-hash` / `hash` | `@noble/hashes` for `hash`; Node `crypto` for `crypto-hash` |
157
+ | `datetime` | `date-fns` |
158
+ | `element-plus` | `async-validator`, `element-plus` |
159
+ | `classes/precision-number`, `math` | `decimal.js` |
160
+ | `number` | `millify` |
161
+ | `consola` | `consola` |
162
+ | `pino` | `pino`, `pino-pretty` |
163
+ | `storages/lru/keyed-store` | `lru-cache` |
164
+ | `storages/redis/msgpack` | `msgpackr` |
165
+ | `vue` | `vue`, `vue-router` |
166
+
167
+ ## Development
168
+
169
+ ```bash
170
+ pnpm install
171
+ pnpm run lint
172
+ pnpm run typecheck
173
+ pnpm test
174
+ pnpm run build
105
175
  ```
106
176
 
107
177
  ## License
@@ -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;AAC/C,KAAI,OAAO,SAAS,MAAM,CAAE,QAAO;AACnC,KAAI,iBAAiB,YAAa,QAAO,OAAO,KAAK,MAAM;AAC3D,KAAI,iBAAiB,WAAY,QAAO,OAAO,KAAK,MAAM,QAAQ,MAAM,YAAY,MAAM,WAAW;AACrG,KAAI,OAAO,MAAM,gBAAgB,WAAY,QAAO,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAE1F,OAAM,IAAI,UAAU,sGAAsG"}
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,MAAM,EAAE,OAAO;CACnC,IAAI,iBAAiB,aAAa,OAAO,OAAO,KAAK,MAAM;CAC3D,IAAI,iBAAiB,YAAY,OAAO,OAAO,KAAK,MAAM,QAAQ,MAAM,YAAY,MAAM,WAAW;CACrG,IAAI,OAAO,MAAM,gBAAgB,YAAY,OAAO,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;CAE1F,MAAM,IAAI,UAAU,sGAAsG"}
@@ -6,6 +6,9 @@ import * as fs from "node:fs";
6
6
 
7
7
  //#region src/classes/path.d.ts
8
8
  type DropFirstParameters<T extends (...args: any) => any> = Parameters<T> extends [any, ...infer R] ? R : never;
9
+ /**
10
+ * Values accepted by the `Path` constructor and path-composition methods.
11
+ */
9
12
  type PathLike = fs.PathLike | Path;
10
13
  /**
11
14
  * Class representing a file system path with various utility methods for path operations.
@@ -15,6 +18,11 @@ type PathLike = fs.PathLike | Path;
15
18
  */
16
19
  declare class Path {
17
20
  #private;
21
+ /**
22
+ * Creates a normalized path value by joining the provided path segments.
23
+ *
24
+ * @param {PathLike[]} paths - Path segments accepted by Node.js `path.join` or another `Path` instance
25
+ */
18
26
  constructor(...paths: PathLike[]);
19
27
  [Symbol.toPrimitive](hint: string): string;
20
28
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"path.d.ts","names":[],"sources":["../../src/classes/path.ts"],"mappings":";;;;;;;KAmBK,mBAAA,eAAkC,IAAA,iBAAqB,UAAA,CAAW,CAAA,8BAA+B,CAAA;AAAA,KAC1F,QAAA,GAAW,EAAA,CAAG,QAAA,GAAW,IAAA;AAHM;;;;;;AAAA,cAW9B,IAAA;EAAA;iBAGM,KAAA,EAAO,QAAA;EAAA,CASrB,MAAA,CAAO,WAAA,EAAa,IAAA;EArB8E;;AACvG;EADuG,IAwC/F,MAAA,CAAA,GAAM,IAAA;;;;MAON,KAAA,CAAA;EA9C6B;;;EAAA,OAuD1B,MAAA,CAAO,UAAA,EAAY,QAAA,CAAS,qBAAA,GAAqB,IAAA;EA/C3C;;;EAAA,OAsDN,OAAA,CAAA,GAAW,KAAA,EAAO,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A;EAtMC;;;EA6MzB,EAAA,CAAA,GAAM,IAAA,EAAM,mBAAA,QAA2B,GAAA,CAAI,EAAA,IAAG,OAAA;EA/L9C;;;EAsMA,KAAA,CAAA,GAAS,IAAA,EAAM,mBAAA,QAA2B,GAAA,CAAI,KAAA,IAAM,OAAA;EA/LpD;;;EAsMA,IAAA,CACI,IAAA,GAAO,EAAA,CAAG,WAAA;IACN,MAAA;EAAA,IAEL,OAAA,CAAQ,EAAA,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,CAAA,GAAY,IAAA,EAAM,mBAAA,QAA2B,GAAA,CAAI,QAAA,IAAS,OAAA;EApLX;;;EA2L/C,MAAA,CAAA,GAAM,OAAA;EApLG;;;EA2LT,SAAA,CAAA,GAAa,IAAA,EAAM,mBAAA,QAA2B,GAAA,CAAI,SAAA,IAAU,OAAA;AAAA"}
@@ -9,6 +9,11 @@ import { basename, dirname, extname, format, isAbsolute, join, normalize, parse,
9
9
  */
10
10
  var Path = class Path {
11
11
  #value;
12
+ /**
13
+ * Creates a normalized path value by joining the provided path segments.
14
+ *
15
+ * @param {PathLike[]} paths - Path segments accepted by Node.js `path.join` or another `Path` instance
16
+ */
12
17
  constructor(...paths) {
13
18
  this.#value = join(...this.#toStrings(paths));
14
19
  }
@@ -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;\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 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":";;;;;;;;;AA4BA,IAAa,OAAb,MAAa,KAAK;CACd;CAEA,YAAY,GAAG,OAAmB;AAC9B,QAAA,QAAc,KAAK,GAAG,MAAA,UAAgB,MAAM,CAAC;;CAIjD,CAAC,OAAO,IAAI,6BAA6B,IAAI;AACzC,SAAO,MAAA;;CAGX,CAAC,OAAO,aAAa,MAAc;AAC/B,MAAI,SAAS,SAAU,OAAM,IAAI,UAAU,oCAAoC;AAC/E,SAAO,MAAA;;CAIX,aAAa,GAAG,OAAmB;AAC/B,SAAO,IAAI,KAAK,GAAG,MAAM;;CAG7B,WAAW,OAAmB;AAC1B,SAAO,MAAM,KAAK,SAAS,KAAK,UAAU,CAAC;;;;;CAQ/C,IAAI,SAAS;AACT,SAAO,KAAK,SAAS;;;;;CAMzB,IAAI,QAAQ;AACR,SAAO,MAAA;;;;;CAQX,OAAO,OAAO,YAA4C;AACtD,SAAO,IAAI,KAAK,OAAO,WAAW,CAAC;;;;;CAMvC,OAAO,QAAQ,GAAG,OAAmB;AACjC,SAAO,IAAI,KAAK,GAAG,MAAM,CAAC,SAAS;;;;;CAQvC,SAAS,QAAiB;AAC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AAG,KAAK;;CAmDzC,QAAQ,GAAG,MAAgB;AACvB,SAAO,IAAI,QAAQ,MAAA,OAAa,GAAG,KAAK;;CAgC5C,SAAS,GAAG,MAAgB;AACxB,SAAO,IAAI,SAAS,MAAA,OAAa,GAAG,KAAK;;;;;CAM7C,OAAO,SAAmB;AACtB,SAAO,IAAI,OAAO,MAAA,OAAa,QAAQ,UAAU,CAAC;;;;;CAMtD,GAAG,GAAG,MAA0C;AAC5C,SAAO,IAAI,GAAG,MAAA,OAAa,GAAG,KAAK;;;;;CAMvC,MAAM,GAAG,MAA6C;AAClD,SAAO,IAAI,MAAM,MAAA,OAAa,GAAG,KAAK;;CAiB1C,KAAK,GAAG,MAAgB;AACpB,SAAO,IAAI,KAAK,MAAA,OAAa,GAAG,KAAK;;;;;CAMzC,SAAS,GAAG,MAAgD;AACxD,SAAO,IAAI,SAAS,MAAA,OAAa,GAAG,KAAK;;;;;CAM7C,SAAS;AACL,SAAO,IAAI,OAAO,MAAA,MAAY;;;;;CAMlC,UAAU,GAAG,MAAiD;AAC1D,SAAO,IAAI,UAAU,MAAA,OAAa,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.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,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AAO,IAAI,SAAS,KAAKA,QAAQ,GAAG,KAAK;;;;;CAM7C,OAAO,SAAmB;EACtB,OAAO,IAAI,OAAO,KAAKA,QAAQ,QAAQ,UAAU,CAAC;;;;;CAMtD,GAAG,GAAG,MAA0C;EAC5C,OAAO,IAAI,GAAG,KAAKA,QAAQ,GAAG,KAAK;;;;;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,56 +1,260 @@
1
1
  import { Decimal } from "decimal.js";
2
2
 
3
3
  //#region src/classes/precision-number.d.ts
4
+ /**
5
+ * Values accepted by `PrecisionNumber` constructors and arithmetic methods.
6
+ */
4
7
  type PrecisionNumberValue = Decimal.Value | PrecisionNumber | {
5
8
  toString: () => string;
6
9
  };
7
10
  /**
8
- * Class representing a precision number with configurable decimal places and rounding.
11
+ * Chainable fixed-decimal wrapper around `decimal.js`.
9
12
  *
10
- * This class leverages the Decimal.js library to ensure accurate arithmetic operations
11
- * with floating point numbers. It provides methods for various arithmetic operations
12
- * (addition, subtraction, multiplication, division) as well as comparison and utility
13
- * methods to check the state of the number (e.g., if it is finite, an integer, zero, etc.).
13
+ * `PrecisionNumber` stores values as `Decimal`, rounds every mutating operation to
14
+ * the configured decimal places, and exposes both mutable and immutable arithmetic
15
+ * methods. Mutable methods (`plus`, `minus`, `times`, `dividedBy`, `modulo`,
16
+ * `pow`, `clamp`, `ceil`, `floor`, `negate`, `absoluteValue`) update the current
17
+ * instance and return `this`; immutable methods prefixed with `to` return a new
18
+ * `PrecisionNumber` with the same precision settings.
14
19
  *
15
- * The class also includes custom symbol methods to support Node.js inspection and primitive
16
- * type conversion.
20
+ * @example
21
+ * ```typescript
22
+ * import { PrecisionNumber } from '@kikiutils/shared/classes/precision-number';
17
23
  *
18
- * The class supports in-place modification methods that alter the current instance's value,
19
- * such as `plus`, `minus`, `times`, `dividedBy`, and others. Additionally, methods prefixed
20
- * with `to` (e.g., `toPlus`, `toMinus`) return a new instance of `PrecisionNumber` with the
21
- * modified value, leaving the original instance unchanged.
24
+ * const value = new PrecisionNumber('1.239', 2).plus('2.111');
25
+ * value.toString(); // '3.35'
26
+ * value.toMinus('1').toString(); // '2.35' (original value remains '3.35')
27
+ * ```
22
28
  */
23
29
  declare class PrecisionNumber {
24
30
  #private;
31
+ /**
32
+ * Creates a fixed-decimal number.
33
+ *
34
+ * @param {PrecisionNumberValue} [value] - Initial value (default: `'0'`)
35
+ * @param {number} [decimalPlaces] - Decimal places retained after operations (default: `2`)
36
+ * @param {Decimal.Rounding} [rounding] - Decimal.js rounding mode (default: `Decimal.ROUND_DOWN`)
37
+ */
25
38
  constructor(value?: PrecisionNumberValue, decimalPlaces?: number, rounding?: Decimal.Rounding);
39
+ /**
40
+ * Converts to a number for numeric coercion and to the fixed string otherwise.
41
+ *
42
+ * @param {string} hint - JavaScript primitive-conversion hint
43
+ */
26
44
  [Symbol.toPrimitive](hint: string): string | number;
45
+ /**
46
+ * Decimal places retained by mutating operations and default formatting.
47
+ */
48
+ get decimalPlaces(): number;
49
+ /**
50
+ * Decimal.js rounding mode used by mutating operations and default formatting.
51
+ */
52
+ get rounding(): Decimal.Rounding;
53
+ /**
54
+ * Fixed-decimal string using the instance precision and rounding mode.
55
+ */
27
56
  get value(): string;
57
+ /**
58
+ * Formats a value with decimal.js without creating a reusable instance.
59
+ *
60
+ * @param {PrecisionNumberValue} value - Value to format
61
+ * @param {number} [decimalPlaces] - Decimal places to output (default: `2`)
62
+ * @param {Decimal.Rounding} [rounding] - Decimal.js rounding mode (default: `Decimal.ROUND_DOWN`)
63
+ *
64
+ * @returns {string} Fixed-decimal string
65
+ */
28
66
  static toFixed(value: PrecisionNumberValue, decimalPlaces?: number, rounding?: Decimal.Rounding): string;
67
+ /**
68
+ * Replaces the current value with its absolute value.
69
+ *
70
+ * @returns {this} The current instance for chaining
71
+ */
29
72
  absoluteValue(): this;
73
+ /**
74
+ * Rounds the current value up to the nearest integer in place.
75
+ *
76
+ * The stored value still uses this instance's configured decimal places for output.
77
+ *
78
+ * @returns {this} The current instance for chaining
79
+ */
80
+ ceil(): this;
81
+ /**
82
+ * Restricts the current value to the inclusive range `[min, max]` in place.
83
+ *
84
+ * @param {PrecisionNumberValue} min - Lower bound
85
+ * @param {PrecisionNumberValue} max - Upper bound
86
+ *
87
+ * @returns {this} The current instance for chaining
88
+ *
89
+ * @throws {Error} If `min` is greater than `max`
90
+ */
91
+ clamp(min: PrecisionNumberValue, max: PrecisionNumberValue): this;
92
+ /**
93
+ * Returns a new instance with the same value, decimal places, and rounding mode.
94
+ */
95
+ clone(): PrecisionNumber;
96
+ /**
97
+ * Divides the current value by another value in place.
98
+ *
99
+ * @param {PrecisionNumberValue} value - Divisor
100
+ *
101
+ * @returns {this} The current instance for chaining
102
+ */
30
103
  dividedBy(value: PrecisionNumberValue): this;
104
+ /**
105
+ * Checks whether the current value equals another value.
106
+ *
107
+ * @param {PrecisionNumberValue} value - Value to compare
108
+ *
109
+ * @returns {boolean} `true` when both numeric values are equal
110
+ */
31
111
  equals(value: PrecisionNumberValue): boolean;
112
+ /**
113
+ * Rounds the current value down to the nearest integer in place.
114
+ *
115
+ * The stored value still uses this instance's configured decimal places for output.
116
+ *
117
+ * @returns {this} The current instance for chaining
118
+ */
119
+ floor(): this;
120
+ /**
121
+ * Checks whether the current value is greater than another value.
122
+ */
32
123
  gt(value: PrecisionNumberValue): boolean;
124
+ /**
125
+ * Checks whether the current value is greater than or equal to another value.
126
+ */
33
127
  gte(value: PrecisionNumberValue): boolean;
128
+ /**
129
+ * Checks whether the current value is finite.
130
+ */
34
131
  isFinite(): boolean;
132
+ /**
133
+ * Checks whether the current value is an integer.
134
+ */
35
135
  isInteger(): boolean;
136
+ /**
137
+ * Checks whether the current value is `NaN`.
138
+ */
36
139
  isNaN(): boolean;
140
+ /**
141
+ * Checks whether the current value is negative.
142
+ */
37
143
  isNegative(): boolean;
144
+ /**
145
+ * Checks whether the current value is positive.
146
+ */
38
147
  isPositive(): boolean;
148
+ /**
149
+ * Checks whether the current value is zero.
150
+ */
39
151
  isZero(): boolean;
152
+ /**
153
+ * Checks whether the current value is less than another value.
154
+ */
40
155
  lt(value: PrecisionNumberValue): boolean;
156
+ /**
157
+ * Checks whether the current value is less than or equal to another value.
158
+ */
41
159
  lte(value: PrecisionNumberValue): boolean;
160
+ /**
161
+ * Subtracts another value from the current value in place.
162
+ */
42
163
  minus(value: PrecisionNumberValue): this;
164
+ /**
165
+ * Replaces the current value with the remainder after division by another value.
166
+ *
167
+ * @param {PrecisionNumberValue} value - Divisor used to compute the remainder
168
+ *
169
+ * @returns {this} The current instance for chaining
170
+ */
171
+ modulo(value: PrecisionNumberValue): this;
172
+ /**
173
+ * Negates the current value in place.
174
+ */
43
175
  negate(): this;
176
+ /**
177
+ * Adds another value to the current value in place.
178
+ */
44
179
  plus(value: PrecisionNumberValue): this;
180
+ /**
181
+ * Raises the current value to an exponent in place.
182
+ *
183
+ * @param {PrecisionNumberValue} value - Exponent
184
+ *
185
+ * @returns {this} The current instance for chaining
186
+ */
187
+ pow(value: PrecisionNumberValue): this;
188
+ /**
189
+ * Multiplies the current value by another value in place.
190
+ */
45
191
  times(value: PrecisionNumberValue): this;
192
+ /**
193
+ * Returns a new instance with the absolute value.
194
+ */
46
195
  toAbsoluteValue(): PrecisionNumber;
196
+ /**
197
+ * Returns a new instance rounded up to the nearest integer.
198
+ */
199
+ toCeil(): PrecisionNumber;
200
+ /**
201
+ * Returns a new instance restricted to the inclusive range `[min, max]`.
202
+ *
203
+ * @param {PrecisionNumberValue} min - Lower bound
204
+ * @param {PrecisionNumberValue} max - Upper bound
205
+ *
206
+ * @throws {Error} If `min` is greater than `max`
207
+ */
208
+ toClamped(min: PrecisionNumberValue, max: PrecisionNumberValue): PrecisionNumber;
209
+ /**
210
+ * Returns a new instance divided by another value.
211
+ */
47
212
  toDividedBy(value: PrecisionNumberValue): PrecisionNumber;
213
+ /**
214
+ * Returns a new instance rounded down to the nearest integer.
215
+ */
216
+ toFloor(): PrecisionNumber;
217
+ /**
218
+ * Serializes to the fixed-decimal string.
219
+ */
48
220
  toJSON(): string;
221
+ /**
222
+ * Returns a new instance with another value subtracted.
223
+ */
49
224
  toMinus(value: PrecisionNumberValue): PrecisionNumber;
225
+ /**
226
+ * Returns a new instance with the remainder after division by another value.
227
+ */
228
+ toModulo(value: PrecisionNumberValue): PrecisionNumber;
229
+ /**
230
+ * Returns a new instance with the value negated.
231
+ */
50
232
  toNegated(): PrecisionNumber;
233
+ /**
234
+ * Returns a new instance with another value added.
235
+ */
51
236
  toPlus(value: PrecisionNumberValue): PrecisionNumber;
237
+ /**
238
+ * Returns a new instance raised to an exponent.
239
+ */
240
+ toPow(value: PrecisionNumberValue): PrecisionNumber;
241
+ /**
242
+ * Converts the current value to a JavaScript number.
243
+ *
244
+ * Use `toString`/`value` when preserving decimal precision is more important than native-number ergonomics.
245
+ */
246
+ toNumber(): number;
247
+ /**
248
+ * Converts the current value to its fixed-decimal string.
249
+ */
52
250
  toString(): string;
251
+ /**
252
+ * Formats the current value with custom precision and rounding for this call only.
253
+ */
53
254
  toFixed(decimalPlaces?: number, rounding?: Decimal.Rounding): string;
255
+ /**
256
+ * Returns a new instance multiplied by another value.
257
+ */
54
258
  toTimes(value: PrecisionNumberValue): PrecisionNumber;
55
259
  }
56
260
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"precision-number.d.ts","names":[],"sources":["../../src/classes/precision-number.ts"],"mappings":";;;KAEY,oBAAA,GAAuB,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