toolbox-x 1.0.1-rc.4 → 1.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 (38) hide show
  1. package/README.md +12 -7
  2. package/dist/{converter-N_3G5KF5.d.cts → area-Cav_1uPb.d.cts} +152 -152
  3. package/dist/{converter-Bj3qKbKV.d.mts → area-DTOvByQG.d.mts} +152 -152
  4. package/dist/basics-1_M7UvCn.mjs +1320 -0
  5. package/dist/basics-K8BDSYD6.cjs +1505 -0
  6. package/dist/converter.d.cts +1 -1
  7. package/dist/converter.d.mts +1 -1
  8. package/dist/dom.cjs +30 -18
  9. package/dist/dom.d.cts +16 -16
  10. package/dist/dom.d.mts +16 -16
  11. package/dist/dom.mjs +29 -16
  12. package/dist/{form-0eq15CfC.d.cts → form-CY3RefN-.d.cts} +4 -6
  13. package/dist/{form-DMBHU578.d.mts → form-zhtuXugI.d.mts} +4 -6
  14. package/dist/{convert-IaWh6Wab.cjs → guards-0VjySrPM.cjs} +89 -1
  15. package/dist/{convert-C8LsoKmI.mjs → guards-DeO4ukiK.mjs} +54 -2
  16. package/dist/guards.cjs +29 -72
  17. package/dist/guards.d.cts +4 -4
  18. package/dist/guards.d.mts +4 -4
  19. package/dist/guards.mjs +3 -54
  20. package/dist/hash.cjs +58 -1262
  21. package/dist/hash.d.cts +2 -95
  22. package/dist/hash.d.mts +2 -95
  23. package/dist/hash.mjs +3 -1207
  24. package/dist/index.cjs +22 -22
  25. package/dist/index.mjs +3 -3
  26. package/dist/{objectify-DrwoO4bJ.cjs → objectify-CRUYlTtI.cjs} +19 -24
  27. package/dist/{objectify-CryKLquR.mjs → objectify-DgkPCH_o.mjs} +20 -25
  28. package/dist/types/converter.d.cts +1 -1
  29. package/dist/types/converter.d.mts +1 -1
  30. package/dist/types/form.d.cts +1 -1
  31. package/dist/types/form.d.mts +1 -1
  32. package/dist/uuid-B5JYv6ao.d.cts +201 -0
  33. package/dist/uuid-DU64TmIe.d.mts +201 -0
  34. package/package.json +1 -1
  35. package/dist/basics-CYqqguZr.cjs +0 -132
  36. package/dist/basics-DQe9mP_M.mjs +0 -115
  37. package/dist/specials-B7y-9nk1.d.mts +0 -108
  38. package/dist/specials-Dmpu2l2b.d.cts +0 -108
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Toolbox-X
1
+ # [Toolbox-X](https://toolbox-x.nazmul-nhb.dev)
2
2
 
3
3
  > “I solve problems you face daily”
4
4
 
@@ -96,7 +96,7 @@ See [Changelog](CHANGELOG.md) for recent updates.
96
96
 
97
97
  ---
98
98
 
99
- ## Signature Utilities
99
+ ## Examples
100
100
 
101
101
  ### 🎨 Professional Color Manipulation
102
102
 
@@ -192,17 +192,22 @@ getColorForInitial('Banana', 50); // '#00376E80' (50% opacity)
192
192
  ```typescript
193
193
  import { createFormData } from 'toolbox-x/dom';
194
194
 
195
- const formData = createFormData({
195
+ const file1 = new File(['file1'], 'file1.txt', { type: 'application/text' });
196
+ const file2 = new File(['file2'], 'file2.txt', { type: 'application/text' });
197
+
198
+ const user = {
196
199
  user: {
197
200
  name: ' John Doe ',
198
201
  age: 30,
199
202
  preferences: { theme: 'dark' }
200
203
  },
201
204
  files: [file1, file2]
202
- }, {
205
+ };
206
+
207
+ const formData = createFormData(user, {
203
208
  trimStrings: true,
204
209
  lowerCaseValues: ['user.name'],
205
- dotNotateNested: ['user.preferences'],
210
+ dotNotateNested: ['user'],
206
211
  breakArray: ['files']
207
212
  });
208
213
 
@@ -230,10 +235,10 @@ const user = {
230
235
  tags: [],
231
236
  };
232
237
 
233
- sanitizeData(user, { ignoreNullish: true, ignoreEmpty: true });
238
+ sanitizeData(user, { ignoreFalsy: true, ignoreEmpty: true });
234
239
  // Returns { name: "John Doe", address: { city: "NYC" } } with exact input type which may cause issue when accessing missing properties
235
240
 
236
- sanitizeData(user, { ignoreNullish: true, ignoreEmpty: true }, 'partial');
241
+ sanitizeData(user, { ignoreFalsy: true, ignoreEmpty: true }, 'partial');
237
242
  // Return type: $DeepPartial<typeof user> safe property access by making all the properties (nested objects/arrays) optional
238
243
  // Returns { name: "John Doe", address: { city: "NYC" } }
239
244
  ```
@@ -17,157 +17,6 @@
17
17
  import { Ar as LooseLiteral, Nr as Mutable, i as $Record, it as Numeric } from "./object-D70hzkoY.cjs";
18
18
  import { t as UNITS } from "./constants-D8RzBjsL.cjs";
19
19
 
20
- //#region src/converter/base.d.ts
21
- /**
22
- * @description Base class providing common mathematical and formatting utilities
23
- * for all unit converters (time, length, data, temperature, etc.).
24
- */
25
- declare class $BaseConverter<Unit extends $Unit> {
26
- protected readonly value: number;
27
- protected readonly unit: Unit;
28
- /**
29
- * Convert value to other units
30
- * @param value Number or numeric string value to convert.
31
- * @param unit Optional base unit for the provided value.
32
- */
33
- constructor(value: Numeric, unit?: Unit);
34
- /** @protected Returns a grammatically correct unit string, prefixed with the number value. */
35
- protected $withPluralUnit(value?: number, unit?: $Unit): string;
36
- /** @protected Rounds a numeric value to given decimal places. */
37
- protected $round(value: number, decimals?: number): number;
38
- /**
39
- * @protected Shared formatter for all converters.
40
- * @param value Converted value (already computed via `.to(target)`).
41
- * @param target Target unit name.
42
- * @param shortLabels Record of compact unit labels.
43
- * @param options Formatting options.
44
- * @returns Formatted string according to style (compact, plural, scientific).
45
- */
46
- protected $formatTo(value: number, target: Unit, shortLabels: Record<Unit, string>, options: FormatToOptions | undefined): string;
47
- /**
48
- * @instance Returns the numeric value.
49
- * @returns The raw numeric value without unit.
50
- */
51
- valueOf(): number;
52
- /**
53
- * @instance Returns the numeric value.
54
- * @returns The raw numeric value without unit.
55
- */
56
- getValue(): number;
57
- /**
58
- * @instance Returns the unit name.
59
- * @returns The current unit.
60
- */
61
- getUnit(): Unit;
62
- /**
63
- * @instance Returns the original value with formatted pluralized unit.
64
- * @returns A string like `"3 hours"` or `"1 minute"` or `"3"` if no unit is provided.
65
- *
66
- * @remarks
67
- * - This method is automatically called when the instance is used in a string context.
68
- * - For complex and versatile pluralization, please refer to {@link https://toolbox-x.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox-x.nazmul-nhb.dev/docs/classes/Pluralizer Pluralizer Class} instead.
69
- */
70
- toString(): string;
71
- /**
72
- * @instance Returns a plain object representation.
73
- * @returns An object with value and unit.
74
- */
75
- toObject(): {
76
- value: number;
77
- unit: Unit;
78
- };
79
- /**
80
- * @instance Converts to JSON representation.
81
- * @returns JSON string of `{ value, unit }`.
82
- */
83
- toJSON(): string;
84
- /** @instance Returns a new instance with the absolute value. */
85
- abs(): this;
86
- /**
87
- * @instance Adds a numeric value (same unit assumed).
88
- * @returns A new instance with updated value.
89
- */
90
- add(n: Numeric): this;
91
- /**
92
- * @instance Subtracts a numeric value (same unit assumed).
93
- * @returns A new instance with updated value.
94
- */
95
- subtract(n: Numeric): this;
96
- /**
97
- * @instance Multiplies the value.
98
- * @returns A new instance with updated value.
99
- */
100
- multiply(n: Numeric): this;
101
- /**
102
- * @instance Divides the value.
103
- * @returns A new instance with updated value.
104
- */
105
- divide(n: Numeric): this;
106
- /**
107
- * @instance Rounds to given decimal places.
108
- * @param decimals Number of decimal places to round. Default is `0`.
109
- * @returns A new instance with rounded value.
110
- */
111
- round(decimals?: number): this;
112
- /** @instance Returns whether this value is greater than another numeric value. */
113
- gt(n: Numeric): boolean;
114
- /** @instance Returns whether this value is less than another numeric value. */
115
- lt(n: Numeric): boolean;
116
- /** @instance Returns whether this value equals another numeric value. */
117
- eq(n: Numeric): boolean;
118
- /**
119
- * @instance Returns a human-friendly formatted string with fixed decimals (if the value is fraction).
120
- * @param decimals Number of decimal places for fractional value.
121
- * @returns Formatted string with proper unit pluralization.
122
- *
123
- * @remarks For complex and versatile pluralization, please refer to {@link https://toolbox-x.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox-x.nazmul-nhb.dev/docs/classes/Pluralizer Pluralizer Class} instead.
124
- */
125
- format(decimals?: number): string;
126
- /**
127
- * @instance Returns all supported units.
128
- * @returns Array of supported unit strings.
129
- */
130
- supportedUnits(): Units;
131
- /**
132
- * @instance Returns all supported units for a specific category.
133
- * @param category Category to filter units by.
134
- * @returns Tuple of supported units for the specified category.
135
- */
136
- supportedUnits<Cat extends Category>(category: Cat): UnitsTuple<Cat>;
137
- }
138
- //#endregion
139
- //#region src/converter/area.d.ts
140
- /**
141
- * @class AreaConverter
142
- * @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
143
- */
144
- declare class $Area extends $BaseConverter<$AreaUnit> {
145
- #private;
146
- /**
147
- * Convert area value to other area units
148
- * @param value Number or numeric string value to convert.
149
- * @param unit Base area unit for the provided value.
150
- */
151
- constructor(value: Numeric, unit: $AreaUnit);
152
- /**
153
- * @instance Converts to target area unit.
154
- * @param target Target area unit.
155
- */
156
- to(target: $AreaUnit): number;
157
- /**
158
- * @instance Converts to all area units.
159
- * @returns Object with all unit conversions.
160
- */
161
- toAll(): $Record<$AreaUnit, number>;
162
- /**
163
- * @instance Formats the converted value and unit.
164
- * @param target Target unit to format to.
165
- * @param options Formatting options.
166
- * @returns Formatted string like "5km²", "5.02 square-miles", or "5e+3 meter".
167
- */
168
- formatTo(target: $AreaUnit, options?: FormatToOptions): string;
169
- }
170
- //#endregion
171
20
  //#region src/converter/data.d.ts
172
21
  /**
173
22
  * @class DataConverter
@@ -399,4 +248,155 @@ type $TimeUnit = UnitMap['time'];
399
248
  /** Union type for all the volume units */
400
249
  type $VolumeUnit = UnitMap['volume'];
401
250
  //#endregion
402
- export { $Data as C, $Length as S, UnitsTuple as _, $TempUnit as a, $Temperature as b, $VolumeUnit as c, Converted as d, FormatToOptions as f, UnitsRecord as g, Units as h, $MassUnit as i, Category as l, UnitMap as m, $DataUnit as n, $TimeUnit as o, InferCategory as p, $LengthUnit as r, $Unit as s, $AreaUnit as t, CategoryUnits as u, $Volume as v, $Area as w, $Mass as x, $Time as y };
251
+ //#region src/converter/base.d.ts
252
+ /**
253
+ * @description Base class providing common mathematical and formatting utilities
254
+ * for all unit converters (time, length, data, temperature, etc.).
255
+ */
256
+ declare class $BaseConverter<Unit extends $Unit> {
257
+ protected readonly value: number;
258
+ protected readonly unit: Unit;
259
+ /**
260
+ * Convert value to other units
261
+ * @param value Number or numeric string value to convert.
262
+ * @param unit Optional base unit for the provided value.
263
+ */
264
+ constructor(value: Numeric, unit?: Unit);
265
+ /** @protected Returns a grammatically correct unit string, prefixed with the number value. */
266
+ protected $withPluralUnit(value?: number, unit?: $Unit): string;
267
+ /** @protected Rounds a numeric value to given decimal places. */
268
+ protected $round(value: number, decimals?: number): number;
269
+ /**
270
+ * @protected Shared formatter for all converters.
271
+ * @param value Converted value (already computed via `.to(target)`).
272
+ * @param target Target unit name.
273
+ * @param shortLabels Record of compact unit labels.
274
+ * @param options Formatting options.
275
+ * @returns Formatted string according to style (compact, plural, scientific).
276
+ */
277
+ protected $formatTo(value: number, target: Unit, shortLabels: Record<Unit, string>, options: FormatToOptions | undefined): string;
278
+ /**
279
+ * @instance Returns the numeric value.
280
+ * @returns The raw numeric value without unit.
281
+ */
282
+ valueOf(): number;
283
+ /**
284
+ * @instance Returns the numeric value.
285
+ * @returns The raw numeric value without unit.
286
+ */
287
+ getValue(): number;
288
+ /**
289
+ * @instance Returns the unit name.
290
+ * @returns The current unit.
291
+ */
292
+ getUnit(): Unit;
293
+ /**
294
+ * @instance Returns the original value with formatted pluralized unit.
295
+ * @returns A string like `"3 hours"` or `"1 minute"` or `"3"` if no unit is provided.
296
+ *
297
+ * @remarks
298
+ * - This method is automatically called when the instance is used in a string context.
299
+ * - For complex and versatile pluralization, please refer to {@link https://toolbox-x.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox-x.nazmul-nhb.dev/docs/classes/Pluralizer Pluralizer Class} instead.
300
+ */
301
+ toString(): string;
302
+ /**
303
+ * @instance Returns a plain object representation.
304
+ * @returns An object with value and unit.
305
+ */
306
+ toObject(): {
307
+ value: number;
308
+ unit: Unit;
309
+ };
310
+ /**
311
+ * @instance Converts to JSON representation.
312
+ * @returns JSON string of `{ value, unit }`.
313
+ */
314
+ toJSON(): string;
315
+ /** @instance Returns a new instance with the absolute value. */
316
+ abs(): this;
317
+ /**
318
+ * @instance Adds a numeric value (same unit assumed).
319
+ * @returns A new instance with updated value.
320
+ */
321
+ add(n: Numeric): this;
322
+ /**
323
+ * @instance Subtracts a numeric value (same unit assumed).
324
+ * @returns A new instance with updated value.
325
+ */
326
+ subtract(n: Numeric): this;
327
+ /**
328
+ * @instance Multiplies the value.
329
+ * @returns A new instance with updated value.
330
+ */
331
+ multiply(n: Numeric): this;
332
+ /**
333
+ * @instance Divides the value.
334
+ * @returns A new instance with updated value.
335
+ */
336
+ divide(n: Numeric): this;
337
+ /**
338
+ * @instance Rounds to given decimal places.
339
+ * @param decimals Number of decimal places to round. Default is `0`.
340
+ * @returns A new instance with rounded value.
341
+ */
342
+ round(decimals?: number): this;
343
+ /** @instance Returns whether this value is greater than another numeric value. */
344
+ gt(n: Numeric): boolean;
345
+ /** @instance Returns whether this value is less than another numeric value. */
346
+ lt(n: Numeric): boolean;
347
+ /** @instance Returns whether this value equals another numeric value. */
348
+ eq(n: Numeric): boolean;
349
+ /**
350
+ * @instance Returns a human-friendly formatted string with fixed decimals (if the value is fraction).
351
+ * @param decimals Number of decimal places for fractional value.
352
+ * @returns Formatted string with proper unit pluralization.
353
+ *
354
+ * @remarks For complex and versatile pluralization, please refer to {@link https://toolbox-x.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox-x.nazmul-nhb.dev/docs/classes/Pluralizer Pluralizer Class} instead.
355
+ */
356
+ format(decimals?: number): string;
357
+ /**
358
+ * @instance Returns all supported units.
359
+ * @returns Array of supported unit strings.
360
+ */
361
+ supportedUnits(): Units;
362
+ /**
363
+ * @instance Returns all supported units for a specific category.
364
+ * @param category Category to filter units by.
365
+ * @returns Tuple of supported units for the specified category.
366
+ */
367
+ supportedUnits<Cat extends Category>(category: Cat): UnitsTuple<Cat>;
368
+ }
369
+ //#endregion
370
+ //#region src/converter/area.d.ts
371
+ /**
372
+ * @class AreaConverter
373
+ * @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
374
+ */
375
+ declare class $Area extends $BaseConverter<$AreaUnit> {
376
+ #private;
377
+ /**
378
+ * Convert area value to other area units
379
+ * @param value Number or numeric string value to convert.
380
+ * @param unit Base area unit for the provided value.
381
+ */
382
+ constructor(value: Numeric, unit: $AreaUnit);
383
+ /**
384
+ * @instance Converts to target area unit.
385
+ * @param target Target area unit.
386
+ */
387
+ to(target: $AreaUnit): number;
388
+ /**
389
+ * @instance Converts to all area units.
390
+ * @returns Object with all unit conversions.
391
+ */
392
+ toAll(): $Record<$AreaUnit, number>;
393
+ /**
394
+ * @instance Formats the converted value and unit.
395
+ * @param target Target unit to format to.
396
+ * @param options Formatting options.
397
+ * @returns Formatted string like "5km²", "5.02 square-miles", or "5e+3 meter".
398
+ */
399
+ formatTo(target: $AreaUnit, options?: FormatToOptions): string;
400
+ }
401
+ //#endregion
402
+ export { $Length as C, $Mass as S, UnitsRecord as _, $MassUnit as a, $Time as b, $Unit as c, CategoryUnits as d, Converted as f, Units as g, UnitMap as h, $LengthUnit as i, $VolumeUnit as l, InferCategory as m, $AreaUnit as n, $TempUnit as o, FormatToOptions as p, $DataUnit as r, $TimeUnit as s, $Area as t, Category as u, UnitsTuple as v, $Data as w, $Temperature as x, $Volume as y };
@@ -17,157 +17,6 @@
17
17
  import { Ar as LooseLiteral, Nr as Mutable, i as $Record, it as Numeric } from "./object-D70hzkoY.mjs";
18
18
  import { t as UNITS } from "./constants-D8RzBjsL.mjs";
19
19
 
20
- //#region src/converter/base.d.ts
21
- /**
22
- * @description Base class providing common mathematical and formatting utilities
23
- * for all unit converters (time, length, data, temperature, etc.).
24
- */
25
- declare class $BaseConverter<Unit extends $Unit> {
26
- protected readonly value: number;
27
- protected readonly unit: Unit;
28
- /**
29
- * Convert value to other units
30
- * @param value Number or numeric string value to convert.
31
- * @param unit Optional base unit for the provided value.
32
- */
33
- constructor(value: Numeric, unit?: Unit);
34
- /** @protected Returns a grammatically correct unit string, prefixed with the number value. */
35
- protected $withPluralUnit(value?: number, unit?: $Unit): string;
36
- /** @protected Rounds a numeric value to given decimal places. */
37
- protected $round(value: number, decimals?: number): number;
38
- /**
39
- * @protected Shared formatter for all converters.
40
- * @param value Converted value (already computed via `.to(target)`).
41
- * @param target Target unit name.
42
- * @param shortLabels Record of compact unit labels.
43
- * @param options Formatting options.
44
- * @returns Formatted string according to style (compact, plural, scientific).
45
- */
46
- protected $formatTo(value: number, target: Unit, shortLabels: Record<Unit, string>, options: FormatToOptions | undefined): string;
47
- /**
48
- * @instance Returns the numeric value.
49
- * @returns The raw numeric value without unit.
50
- */
51
- valueOf(): number;
52
- /**
53
- * @instance Returns the numeric value.
54
- * @returns The raw numeric value without unit.
55
- */
56
- getValue(): number;
57
- /**
58
- * @instance Returns the unit name.
59
- * @returns The current unit.
60
- */
61
- getUnit(): Unit;
62
- /**
63
- * @instance Returns the original value with formatted pluralized unit.
64
- * @returns A string like `"3 hours"` or `"1 minute"` or `"3"` if no unit is provided.
65
- *
66
- * @remarks
67
- * - This method is automatically called when the instance is used in a string context.
68
- * - For complex and versatile pluralization, please refer to {@link https://toolbox-x.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox-x.nazmul-nhb.dev/docs/classes/Pluralizer Pluralizer Class} instead.
69
- */
70
- toString(): string;
71
- /**
72
- * @instance Returns a plain object representation.
73
- * @returns An object with value and unit.
74
- */
75
- toObject(): {
76
- value: number;
77
- unit: Unit;
78
- };
79
- /**
80
- * @instance Converts to JSON representation.
81
- * @returns JSON string of `{ value, unit }`.
82
- */
83
- toJSON(): string;
84
- /** @instance Returns a new instance with the absolute value. */
85
- abs(): this;
86
- /**
87
- * @instance Adds a numeric value (same unit assumed).
88
- * @returns A new instance with updated value.
89
- */
90
- add(n: Numeric): this;
91
- /**
92
- * @instance Subtracts a numeric value (same unit assumed).
93
- * @returns A new instance with updated value.
94
- */
95
- subtract(n: Numeric): this;
96
- /**
97
- * @instance Multiplies the value.
98
- * @returns A new instance with updated value.
99
- */
100
- multiply(n: Numeric): this;
101
- /**
102
- * @instance Divides the value.
103
- * @returns A new instance with updated value.
104
- */
105
- divide(n: Numeric): this;
106
- /**
107
- * @instance Rounds to given decimal places.
108
- * @param decimals Number of decimal places to round. Default is `0`.
109
- * @returns A new instance with rounded value.
110
- */
111
- round(decimals?: number): this;
112
- /** @instance Returns whether this value is greater than another numeric value. */
113
- gt(n: Numeric): boolean;
114
- /** @instance Returns whether this value is less than another numeric value. */
115
- lt(n: Numeric): boolean;
116
- /** @instance Returns whether this value equals another numeric value. */
117
- eq(n: Numeric): boolean;
118
- /**
119
- * @instance Returns a human-friendly formatted string with fixed decimals (if the value is fraction).
120
- * @param decimals Number of decimal places for fractional value.
121
- * @returns Formatted string with proper unit pluralization.
122
- *
123
- * @remarks For complex and versatile pluralization, please refer to {@link https://toolbox-x.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox-x.nazmul-nhb.dev/docs/classes/Pluralizer Pluralizer Class} instead.
124
- */
125
- format(decimals?: number): string;
126
- /**
127
- * @instance Returns all supported units.
128
- * @returns Array of supported unit strings.
129
- */
130
- supportedUnits(): Units;
131
- /**
132
- * @instance Returns all supported units for a specific category.
133
- * @param category Category to filter units by.
134
- * @returns Tuple of supported units for the specified category.
135
- */
136
- supportedUnits<Cat extends Category>(category: Cat): UnitsTuple<Cat>;
137
- }
138
- //#endregion
139
- //#region src/converter/area.d.ts
140
- /**
141
- * @class AreaConverter
142
- * @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
143
- */
144
- declare class $Area extends $BaseConverter<$AreaUnit> {
145
- #private;
146
- /**
147
- * Convert area value to other area units
148
- * @param value Number or numeric string value to convert.
149
- * @param unit Base area unit for the provided value.
150
- */
151
- constructor(value: Numeric, unit: $AreaUnit);
152
- /**
153
- * @instance Converts to target area unit.
154
- * @param target Target area unit.
155
- */
156
- to(target: $AreaUnit): number;
157
- /**
158
- * @instance Converts to all area units.
159
- * @returns Object with all unit conversions.
160
- */
161
- toAll(): $Record<$AreaUnit, number>;
162
- /**
163
- * @instance Formats the converted value and unit.
164
- * @param target Target unit to format to.
165
- * @param options Formatting options.
166
- * @returns Formatted string like "5km²", "5.02 square-miles", or "5e+3 meter".
167
- */
168
- formatTo(target: $AreaUnit, options?: FormatToOptions): string;
169
- }
170
- //#endregion
171
20
  //#region src/converter/data.d.ts
172
21
  /**
173
22
  * @class DataConverter
@@ -399,4 +248,155 @@ type $TimeUnit = UnitMap['time'];
399
248
  /** Union type for all the volume units */
400
249
  type $VolumeUnit = UnitMap['volume'];
401
250
  //#endregion
402
- export { $Data as C, $Length as S, UnitsTuple as _, $TempUnit as a, $Temperature as b, $VolumeUnit as c, Converted as d, FormatToOptions as f, UnitsRecord as g, Units as h, $MassUnit as i, Category as l, UnitMap as m, $DataUnit as n, $TimeUnit as o, InferCategory as p, $LengthUnit as r, $Unit as s, $AreaUnit as t, CategoryUnits as u, $Volume as v, $Area as w, $Mass as x, $Time as y };
251
+ //#region src/converter/base.d.ts
252
+ /**
253
+ * @description Base class providing common mathematical and formatting utilities
254
+ * for all unit converters (time, length, data, temperature, etc.).
255
+ */
256
+ declare class $BaseConverter<Unit extends $Unit> {
257
+ protected readonly value: number;
258
+ protected readonly unit: Unit;
259
+ /**
260
+ * Convert value to other units
261
+ * @param value Number or numeric string value to convert.
262
+ * @param unit Optional base unit for the provided value.
263
+ */
264
+ constructor(value: Numeric, unit?: Unit);
265
+ /** @protected Returns a grammatically correct unit string, prefixed with the number value. */
266
+ protected $withPluralUnit(value?: number, unit?: $Unit): string;
267
+ /** @protected Rounds a numeric value to given decimal places. */
268
+ protected $round(value: number, decimals?: number): number;
269
+ /**
270
+ * @protected Shared formatter for all converters.
271
+ * @param value Converted value (already computed via `.to(target)`).
272
+ * @param target Target unit name.
273
+ * @param shortLabels Record of compact unit labels.
274
+ * @param options Formatting options.
275
+ * @returns Formatted string according to style (compact, plural, scientific).
276
+ */
277
+ protected $formatTo(value: number, target: Unit, shortLabels: Record<Unit, string>, options: FormatToOptions | undefined): string;
278
+ /**
279
+ * @instance Returns the numeric value.
280
+ * @returns The raw numeric value without unit.
281
+ */
282
+ valueOf(): number;
283
+ /**
284
+ * @instance Returns the numeric value.
285
+ * @returns The raw numeric value without unit.
286
+ */
287
+ getValue(): number;
288
+ /**
289
+ * @instance Returns the unit name.
290
+ * @returns The current unit.
291
+ */
292
+ getUnit(): Unit;
293
+ /**
294
+ * @instance Returns the original value with formatted pluralized unit.
295
+ * @returns A string like `"3 hours"` or `"1 minute"` or `"3"` if no unit is provided.
296
+ *
297
+ * @remarks
298
+ * - This method is automatically called when the instance is used in a string context.
299
+ * - For complex and versatile pluralization, please refer to {@link https://toolbox-x.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox-x.nazmul-nhb.dev/docs/classes/Pluralizer Pluralizer Class} instead.
300
+ */
301
+ toString(): string;
302
+ /**
303
+ * @instance Returns a plain object representation.
304
+ * @returns An object with value and unit.
305
+ */
306
+ toObject(): {
307
+ value: number;
308
+ unit: Unit;
309
+ };
310
+ /**
311
+ * @instance Converts to JSON representation.
312
+ * @returns JSON string of `{ value, unit }`.
313
+ */
314
+ toJSON(): string;
315
+ /** @instance Returns a new instance with the absolute value. */
316
+ abs(): this;
317
+ /**
318
+ * @instance Adds a numeric value (same unit assumed).
319
+ * @returns A new instance with updated value.
320
+ */
321
+ add(n: Numeric): this;
322
+ /**
323
+ * @instance Subtracts a numeric value (same unit assumed).
324
+ * @returns A new instance with updated value.
325
+ */
326
+ subtract(n: Numeric): this;
327
+ /**
328
+ * @instance Multiplies the value.
329
+ * @returns A new instance with updated value.
330
+ */
331
+ multiply(n: Numeric): this;
332
+ /**
333
+ * @instance Divides the value.
334
+ * @returns A new instance with updated value.
335
+ */
336
+ divide(n: Numeric): this;
337
+ /**
338
+ * @instance Rounds to given decimal places.
339
+ * @param decimals Number of decimal places to round. Default is `0`.
340
+ * @returns A new instance with rounded value.
341
+ */
342
+ round(decimals?: number): this;
343
+ /** @instance Returns whether this value is greater than another numeric value. */
344
+ gt(n: Numeric): boolean;
345
+ /** @instance Returns whether this value is less than another numeric value. */
346
+ lt(n: Numeric): boolean;
347
+ /** @instance Returns whether this value equals another numeric value. */
348
+ eq(n: Numeric): boolean;
349
+ /**
350
+ * @instance Returns a human-friendly formatted string with fixed decimals (if the value is fraction).
351
+ * @param decimals Number of decimal places for fractional value.
352
+ * @returns Formatted string with proper unit pluralization.
353
+ *
354
+ * @remarks For complex and versatile pluralization, please refer to {@link https://toolbox-x.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox-x.nazmul-nhb.dev/docs/classes/Pluralizer Pluralizer Class} instead.
355
+ */
356
+ format(decimals?: number): string;
357
+ /**
358
+ * @instance Returns all supported units.
359
+ * @returns Array of supported unit strings.
360
+ */
361
+ supportedUnits(): Units;
362
+ /**
363
+ * @instance Returns all supported units for a specific category.
364
+ * @param category Category to filter units by.
365
+ * @returns Tuple of supported units for the specified category.
366
+ */
367
+ supportedUnits<Cat extends Category>(category: Cat): UnitsTuple<Cat>;
368
+ }
369
+ //#endregion
370
+ //#region src/converter/area.d.ts
371
+ /**
372
+ * @class AreaConverter
373
+ * @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
374
+ */
375
+ declare class $Area extends $BaseConverter<$AreaUnit> {
376
+ #private;
377
+ /**
378
+ * Convert area value to other area units
379
+ * @param value Number or numeric string value to convert.
380
+ * @param unit Base area unit for the provided value.
381
+ */
382
+ constructor(value: Numeric, unit: $AreaUnit);
383
+ /**
384
+ * @instance Converts to target area unit.
385
+ * @param target Target area unit.
386
+ */
387
+ to(target: $AreaUnit): number;
388
+ /**
389
+ * @instance Converts to all area units.
390
+ * @returns Object with all unit conversions.
391
+ */
392
+ toAll(): $Record<$AreaUnit, number>;
393
+ /**
394
+ * @instance Formats the converted value and unit.
395
+ * @param target Target unit to format to.
396
+ * @param options Formatting options.
397
+ * @returns Formatted string like "5km²", "5.02 square-miles", or "5e+3 meter".
398
+ */
399
+ formatTo(target: $AreaUnit, options?: FormatToOptions): string;
400
+ }
401
+ //#endregion
402
+ export { $Length as C, $Mass as S, UnitsRecord as _, $MassUnit as a, $Time as b, $Unit as c, CategoryUnits as d, Converted as f, Units as g, UnitMap as h, $LengthUnit as i, $VolumeUnit as l, InferCategory as m, $AreaUnit as n, $TempUnit as o, FormatToOptions as p, $DataUnit as r, $TimeUnit as s, $Area as t, Category as u, UnitsTuple as v, $Data as w, $Temperature as x, $Volume as y };