toolbox-x 1.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.
Files changed (190) hide show
  1. package/LICENSE +201 -0
  2. package/dist/Color-B3mgF9Dh.d.cts +486 -0
  3. package/dist/Color-D38Xrw65.d.mts +486 -0
  4. package/dist/Stylog-Df7eq3-j.d.cts +519 -0
  5. package/dist/Stylog-jvlLcMQq.d.mts +519 -0
  6. package/dist/array-DvW0zIu6.d.mts +130 -0
  7. package/dist/array-rUnEVisO.d.cts +130 -0
  8. package/dist/basics-D_eSv0cu.cjs +132 -0
  9. package/dist/basics-Dp_aEK81.mjs +115 -0
  10. package/dist/basics-WEYWlnRO.d.cts +95 -0
  11. package/dist/basics-uBSfkBEI.d.mts +95 -0
  12. package/dist/case-BWIt8Ash.mjs +449 -0
  13. package/dist/case-C-S-b5YP.d.cts +327 -0
  14. package/dist/case-CS8Ii3A7.cjs +526 -0
  15. package/dist/case-CybASFPD.d.mts +327 -0
  16. package/dist/change-case.cjs +32 -0
  17. package/dist/change-case.d.cts +18 -0
  18. package/dist/change-case.d.mts +18 -0
  19. package/dist/change-case.mjs +19 -0
  20. package/dist/colors.cjs +574 -0
  21. package/dist/colors.d.cts +355 -0
  22. package/dist/colors.d.mts +355 -0
  23. package/dist/colors.mjs +547 -0
  24. package/dist/constants-2gAw23_7.mjs +144 -0
  25. package/dist/constants-B34K0QPi.d.cts +21 -0
  26. package/dist/constants-BIBDKY1u.cjs +924 -0
  27. package/dist/constants-BWT-810U.cjs +158 -0
  28. package/dist/constants-BwbHnXlM.mjs +662 -0
  29. package/dist/constants-BxN9l5el.cjs +74 -0
  30. package/dist/constants-CLS_bgKD.d.mts +847 -0
  31. package/dist/constants-D73iFu8g.mjs +171 -0
  32. package/dist/constants-DAfRxaa8.mjs +62 -0
  33. package/dist/constants-DQYeCjlx.cjs +207 -0
  34. package/dist/constants-Deeie-iH.d.mts +21 -0
  35. package/dist/constants-DpTG9RP6.d.mts +29 -0
  36. package/dist/constants-DqwnkJ_d.cjs +740 -0
  37. package/dist/constants-DvRUY_FY.cjs +150 -0
  38. package/dist/constants-VcRtQu0K.d.cts +29 -0
  39. package/dist/constants-X5hm1UtB.mjs +912 -0
  40. package/dist/constants-eNd-iYsV.mjs +134 -0
  41. package/dist/constants-qm8FafmD.d.cts +847 -0
  42. package/dist/constants.cjs +415 -0
  43. package/dist/constants.d.cts +184 -0
  44. package/dist/constants.d.mts +184 -0
  45. package/dist/constants.mjs +378 -0
  46. package/dist/convert-BOCgUv2D.cjs +252 -0
  47. package/dist/convert-Bn4jFomQ.mjs +169 -0
  48. package/dist/convert-BrzlG-m_.cjs +475 -0
  49. package/dist/convert-DhaUoPVU.mjs +368 -0
  50. package/dist/converter-1P90_RcP.d.mts +402 -0
  51. package/dist/converter-CmkcAppi.d.cts +402 -0
  52. package/dist/converter.cjs +780 -0
  53. package/dist/converter.d.cts +29 -0
  54. package/dist/converter.d.mts +29 -0
  55. package/dist/converter.mjs +771 -0
  56. package/dist/countries-CIpmtEzV.cjs +1469 -0
  57. package/dist/countries-Cy0xiqS3.mjs +1463 -0
  58. package/dist/css-colors-Bx947Ng3.d.cts +179 -0
  59. package/dist/css-colors-CXCDqQbG.cjs +186 -0
  60. package/dist/css-colors-CXTp1vvy.d.mts +179 -0
  61. package/dist/css-colors-DfUW3nTR.mjs +180 -0
  62. package/dist/date.cjs +332 -0
  63. package/dist/date.d.cts +213 -0
  64. package/dist/date.d.mts +213 -0
  65. package/dist/date.mjs +298 -0
  66. package/dist/dom.cjs +461 -0
  67. package/dist/dom.d.cts +228 -0
  68. package/dist/dom.d.mts +228 -0
  69. package/dist/dom.mjs +429 -0
  70. package/dist/form-BMFVGUrN.d.mts +118 -0
  71. package/dist/form-DRFbryvK.d.cts +118 -0
  72. package/dist/guards-3kaUX66g.mjs +157 -0
  73. package/dist/guards-C8gkvIHb.cjs +240 -0
  74. package/dist/guards-DdyU4h4o.mjs +110 -0
  75. package/dist/guards-Efhp1mNy.cjs +151 -0
  76. package/dist/guards.cjs +172 -0
  77. package/dist/guards.d.cts +399 -0
  78. package/dist/guards.d.mts +399 -0
  79. package/dist/guards.mjs +75 -0
  80. package/dist/hash-B6JPEyAz.d.mts +131 -0
  81. package/dist/hash-NTpeKYB_.d.cts +131 -0
  82. package/dist/hash.cjs +2126 -0
  83. package/dist/hash.d.cts +1239 -0
  84. package/dist/hash.d.mts +1239 -0
  85. package/dist/hash.mjs +2095 -0
  86. package/dist/http-status-BAZdtr7-.d.mts +65 -0
  87. package/dist/http-status-U_3MtoGb.d.cts +65 -0
  88. package/dist/http-status.cjs +173 -0
  89. package/dist/http-status.d.cts +142 -0
  90. package/dist/http-status.d.mts +142 -0
  91. package/dist/http-status.mjs +171 -0
  92. package/dist/index.cjs +2551 -0
  93. package/dist/index.d.cts +1493 -0
  94. package/dist/index.d.mts +1493 -0
  95. package/dist/index.mjs +2357 -0
  96. package/dist/object-B0TV3eHx.d.mts +8052 -0
  97. package/dist/object-Blq0Amdv.d.cts +8052 -0
  98. package/dist/objectify-CDs0Fbr1.mjs +417 -0
  99. package/dist/objectify-DIJ-OBmo.cjs +524 -0
  100. package/dist/paginator.cjs +245 -0
  101. package/dist/paginator.d.cts +144 -0
  102. package/dist/paginator.d.mts +144 -0
  103. package/dist/paginator.mjs +243 -0
  104. package/dist/parse-2ubxXZRp.cjs +211 -0
  105. package/dist/parse-N7g942uy.mjs +164 -0
  106. package/dist/pluralizer-BjMIc6uT.d.mts +42 -0
  107. package/dist/pluralizer-Cb6ZmrDl.d.cts +42 -0
  108. package/dist/pluralizer.cjs +678 -0
  109. package/dist/pluralizer.d.cts +152 -0
  110. package/dist/pluralizer.d.mts +152 -0
  111. package/dist/pluralizer.mjs +676 -0
  112. package/dist/primitives-B26uZolQ.cjs +228 -0
  113. package/dist/primitives-KsFUp3kQ.mjs +144 -0
  114. package/dist/specials-D48_IZbd.d.mts +108 -0
  115. package/dist/specials-DzLr1ZgU.cjs +477 -0
  116. package/dist/specials-LVONlKbQ.d.cts +108 -0
  117. package/dist/specials-uhDuRg8H.mjs +292 -0
  118. package/dist/string-CBAbxaG1.d.mts +258 -0
  119. package/dist/string-CsNsm_65.d.cts +258 -0
  120. package/dist/stylog.cjs +621 -0
  121. package/dist/stylog.d.cts +49 -0
  122. package/dist/stylog.d.mts +49 -0
  123. package/dist/stylog.mjs +614 -0
  124. package/dist/timezone-B2OYK6Fh.mjs +5589 -0
  125. package/dist/timezone-Beh9IGpw.cjs +5625 -0
  126. package/dist/types/array.cjs +16 -0
  127. package/dist/types/array.d.cts +18 -0
  128. package/dist/types/array.d.mts +18 -0
  129. package/dist/types/array.mjs +17 -0
  130. package/dist/types/colors.cjs +16 -0
  131. package/dist/types/colors.d.cts +18 -0
  132. package/dist/types/colors.d.mts +18 -0
  133. package/dist/types/colors.mjs +17 -0
  134. package/dist/types/converter.cjs +16 -0
  135. package/dist/types/converter.d.cts +18 -0
  136. package/dist/types/converter.d.mts +18 -0
  137. package/dist/types/converter.mjs +17 -0
  138. package/dist/types/form.cjs +16 -0
  139. package/dist/types/form.d.cts +18 -0
  140. package/dist/types/form.d.mts +18 -0
  141. package/dist/types/form.mjs +17 -0
  142. package/dist/types/hash.cjs +16 -0
  143. package/dist/types/hash.d.cts +18 -0
  144. package/dist/types/hash.d.mts +18 -0
  145. package/dist/types/hash.mjs +17 -0
  146. package/dist/types/http-status.cjs +16 -0
  147. package/dist/types/http-status.d.cts +18 -0
  148. package/dist/types/http-status.d.mts +18 -0
  149. package/dist/types/http-status.mjs +17 -0
  150. package/dist/types/index.cjs +16 -0
  151. package/dist/types/index.d.cts +18 -0
  152. package/dist/types/index.d.mts +18 -0
  153. package/dist/types/index.mjs +17 -0
  154. package/dist/types/number.cjs +16 -0
  155. package/dist/types/number.d.cts +18 -0
  156. package/dist/types/number.d.mts +18 -0
  157. package/dist/types/number.mjs +17 -0
  158. package/dist/types/object.cjs +16 -0
  159. package/dist/types/object.d.cts +18 -0
  160. package/dist/types/object.d.mts +18 -0
  161. package/dist/types/object.mjs +17 -0
  162. package/dist/types/pluralizer.cjs +16 -0
  163. package/dist/types/pluralizer.d.cts +18 -0
  164. package/dist/types/pluralizer.d.mts +18 -0
  165. package/dist/types/pluralizer.mjs +17 -0
  166. package/dist/types/string.cjs +16 -0
  167. package/dist/types/string.d.cts +18 -0
  168. package/dist/types/string.d.mts +18 -0
  169. package/dist/types/string.mjs +17 -0
  170. package/dist/types/stylog.cjs +16 -0
  171. package/dist/types/stylog.d.cts +18 -0
  172. package/dist/types/stylog.d.mts +18 -0
  173. package/dist/types/stylog.mjs +17 -0
  174. package/dist/types/utils.cjs +16 -0
  175. package/dist/types/utils.d.cts +18 -0
  176. package/dist/types/utils.d.mts +18 -0
  177. package/dist/types/utils.mjs +17 -0
  178. package/dist/types/verbalizer.cjs +16 -0
  179. package/dist/types/verbalizer.d.cts +30 -0
  180. package/dist/types/verbalizer.d.mts +30 -0
  181. package/dist/types/verbalizer.mjs +17 -0
  182. package/dist/utilities-CLUmdQeV.cjs +140 -0
  183. package/dist/utilities-m5yFKqLd.mjs +105 -0
  184. package/dist/utils-ClW9LA6f.mjs +449 -0
  185. package/dist/utils-DLFRgXUC.cjs +568 -0
  186. package/dist/verbalizer.cjs +998 -0
  187. package/dist/verbalizer.d.cts +148 -0
  188. package/dist/verbalizer.d.mts +148 -0
  189. package/dist/verbalizer.mjs +996 -0
  190. package/package.json +249 -0
@@ -0,0 +1,780 @@
1
+ /**
2
+ * Copyright 2026 - present Nazmul Hassan
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
18
+ const require_constants = require('./constants-BWT-810U.cjs');
19
+
20
+ //#region src/converter/base.ts
21
+ /**
22
+ * @description Base class providing common mathematical and formatting utilities
23
+ * for all unit converters (time, length, data, temperature, etc.).
24
+ */
25
+ var $BaseConverter = class {
26
+ value;
27
+ 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, unit) {
34
+ this.value = Number(value);
35
+ this.unit = unit ?? "";
36
+ }
37
+ /** @protected Returns a grammatically correct unit string, prefixed with the number value. */
38
+ $withPluralUnit(value, unit) {
39
+ const abs = Math.abs(value ?? this.value);
40
+ const u = unit ?? this.unit;
41
+ if (!u) return String(abs);
42
+ let pluralized;
43
+ if (abs === 1) pluralized = u;
44
+ else if (require_constants.IRREGULAR_PLURALS?.[u]) pluralized = require_constants.IRREGULAR_PLURALS[u];
45
+ else if (require_constants.INVARIANT_UNITS.has(u)) pluralized = u;
46
+ else if (u.endsWith("foot")) pluralized = u.replace(/foot$/, "feet");
47
+ else if (u.endsWith("inch")) pluralized = u.replace(/inch$/, "inches");
48
+ else pluralized = require_constants.Y_TO_IES.has(u) ? u.replace(/y$/, "ies") : `${u}s`;
49
+ return `${abs} ${pluralized}`;
50
+ }
51
+ /** @protected Rounds a numeric value to given decimal places. */
52
+ $round(value, decimals = 2) {
53
+ const factor = 10 ** decimals;
54
+ return Math.round(value * factor) / factor;
55
+ }
56
+ /**
57
+ * @protected Shared formatter for all converters.
58
+ * @param value Converted value (already computed via `.to(target)`).
59
+ * @param target Target unit name.
60
+ * @param shortLabels Record of compact unit labels.
61
+ * @param options Formatting options.
62
+ * @returns Formatted string according to style (compact, plural, scientific).
63
+ */
64
+ $formatTo(value, target, shortLabels, options) {
65
+ const { style = "plural", decimals = 2 } = options ?? {};
66
+ const rounded = this.$round(value, decimals);
67
+ switch (style) {
68
+ case "compact": return `${rounded}${shortLabels[target]}`;
69
+ case "scientific": return `${value.toExponential(decimals)} ${target}`;
70
+ default: return this.$withPluralUnit(rounded, target);
71
+ }
72
+ }
73
+ /**
74
+ * @instance Returns the numeric value.
75
+ * @returns The raw numeric value without unit.
76
+ */
77
+ valueOf() {
78
+ return this.value;
79
+ }
80
+ /**
81
+ * @instance Returns the numeric value.
82
+ * @returns The raw numeric value without unit.
83
+ */
84
+ getValue() {
85
+ return this.value;
86
+ }
87
+ /**
88
+ * @instance Returns the unit name.
89
+ * @returns The current unit.
90
+ */
91
+ getUnit() {
92
+ return this.unit || "unknown";
93
+ }
94
+ /**
95
+ * @instance Returns the original value with formatted pluralized unit.
96
+ * @returns A string like `"3 hours"` or `"1 minute"` or `"3"` if no unit is provided.
97
+ *
98
+ * @remarks
99
+ * - This method is automatically called when the instance is used in a string context.
100
+ * - For complex and versatile pluralization, please refer to {@link https://toolbox.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox.nazmul-nhb.dev/docs/classes/Pluralizer Pluralizer Class} instead.
101
+ */
102
+ toString() {
103
+ return this.$withPluralUnit();
104
+ }
105
+ /**
106
+ * @instance Returns a plain object representation.
107
+ * @returns An object with value and unit.
108
+ */
109
+ toObject() {
110
+ return {
111
+ value: this.value,
112
+ unit: this.unit || "unknown"
113
+ };
114
+ }
115
+ /**
116
+ * @instance Converts to JSON representation.
117
+ * @returns JSON string of `{ value, unit }`.
118
+ */
119
+ toJSON() {
120
+ return JSON.stringify(this.toObject());
121
+ }
122
+ /** @instance Returns a new instance with the absolute value. */
123
+ abs() {
124
+ return new this.constructor(Math.abs(this.value), this.unit);
125
+ }
126
+ /**
127
+ * @instance Adds a numeric value (same unit assumed).
128
+ * @returns A new instance with updated value.
129
+ */
130
+ add(n) {
131
+ return new this.constructor(this.value + Number(n), this.unit);
132
+ }
133
+ /**
134
+ * @instance Subtracts a numeric value (same unit assumed).
135
+ * @returns A new instance with updated value.
136
+ */
137
+ subtract(n) {
138
+ return new this.constructor(this.value - Number(n), this.unit);
139
+ }
140
+ /**
141
+ * @instance Multiplies the value.
142
+ * @returns A new instance with updated value.
143
+ */
144
+ multiply(n) {
145
+ return new this.constructor(this.value * Number(n), this.unit);
146
+ }
147
+ /**
148
+ * @instance Divides the value.
149
+ * @returns A new instance with updated value.
150
+ */
151
+ divide(n) {
152
+ return new this.constructor(this.value / Number(n), this.unit);
153
+ }
154
+ /**
155
+ * @instance Rounds to given decimal places.
156
+ * @param decimals Number of decimal places to round. Default is `0`.
157
+ * @returns A new instance with rounded value.
158
+ */
159
+ round(decimals = 0) {
160
+ const rounded = this.$round(this.value, decimals);
161
+ return new this.constructor(rounded, this.unit);
162
+ }
163
+ /** @instance Returns whether this value is greater than another numeric value. */
164
+ gt(n) {
165
+ return this.value > Number(n);
166
+ }
167
+ /** @instance Returns whether this value is less than another numeric value. */
168
+ lt(n) {
169
+ return this.value < Number(n);
170
+ }
171
+ /** @instance Returns whether this value equals another numeric value. */
172
+ eq(n) {
173
+ return this.value === Number(n);
174
+ }
175
+ /**
176
+ * @instance Returns a human-friendly formatted string with fixed decimals (if the value is fraction).
177
+ * @param decimals Number of decimal places for fractional value.
178
+ * @returns Formatted string with proper unit pluralization.
179
+ *
180
+ * @remarks For complex and versatile pluralization, please refer to {@link https://toolbox.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox.nazmul-nhb.dev/docs/classes/Pluralizer Pluralizer Class} instead.
181
+ */
182
+ format(decimals = 2) {
183
+ return this.$withPluralUnit(this.$round(this.value, decimals));
184
+ }
185
+ /**
186
+ * @instance Returns all supported units, optionally filtered by category.
187
+ * @param category Category to filter units by.
188
+ * @returns Array or tuple of supported unit strings.
189
+ */
190
+ supportedUnits(category) {
191
+ if (category && category in require_constants.UNITS) return [...require_constants.UNITS[category]];
192
+ return Object.values(require_constants.UNITS).flat();
193
+ }
194
+ };
195
+
196
+ //#endregion
197
+ //#region src/converter/area.ts
198
+ /**
199
+ * @class AreaConverter
200
+ * @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
201
+ */
202
+ var $Area = class $Area extends $BaseConverter {
203
+ /** * Conversion factors based on square-meters. */
204
+ static #factors = {
205
+ "square-millimeter": 1e-6,
206
+ "square-centimeter": 1e-4,
207
+ "square-meter": 1,
208
+ "square-kilometer": 1e6,
209
+ "square-millimetre": 1e-6,
210
+ "square-centimetre": 1e-4,
211
+ "square-metre": 1,
212
+ "square-kilometre": 1e6,
213
+ "square-inch": 64516e-8,
214
+ "square-foot": .09290304,
215
+ "square-yard": .83612736,
216
+ "square-mile": 2589988.110336,
217
+ hectare: 1e4,
218
+ acre: 4046.8564224
219
+ };
220
+ /**
221
+ * Convert area value to other area units
222
+ * @param value Number or numeric string value to convert.
223
+ * @param unit Base area unit for the provided value.
224
+ */
225
+ constructor(value, unit) {
226
+ super(value, unit);
227
+ }
228
+ /** @instance Converts to base unit (square meters). */
229
+ #toSquareMeters() {
230
+ return this.value * $Area.#factors[this.unit];
231
+ }
232
+ /**
233
+ * @instance Converts to target area unit.
234
+ * @param target Target area unit.
235
+ */
236
+ to(target) {
237
+ return this.#toSquareMeters() / $Area.#factors[target];
238
+ }
239
+ /**
240
+ * @instance Converts to all area units.
241
+ * @returns Object with all unit conversions.
242
+ */
243
+ toAll() {
244
+ const base = this.#toSquareMeters();
245
+ const result = {};
246
+ for (const unit of require_constants.UNITS.area) result[unit] = base / $Area.#factors[unit];
247
+ return result;
248
+ }
249
+ /**
250
+ * @instance Formats the converted value and unit.
251
+ * @param target Target unit to format to.
252
+ * @param options Formatting options.
253
+ * @returns Formatted string like "5km²", "5.02 square-miles", or "5e+3 meter".
254
+ */
255
+ formatTo(target, options) {
256
+ const value = this.to(target);
257
+ return this.$formatTo(value, target, {
258
+ "square-millimeter": "mm²",
259
+ "square-centimeter": "cm²",
260
+ "square-meter": "m²",
261
+ "square-kilometer": "km²",
262
+ "square-millimetre": "mm²",
263
+ "square-centimetre": "cm²",
264
+ "square-metre": "m²",
265
+ "square-kilometre": "km²",
266
+ "square-inch": "in²",
267
+ "square-foot": "ft²",
268
+ "square-yard": "yd²",
269
+ "square-mile": "mi²",
270
+ hectare: "ha",
271
+ acre: "ac"
272
+ }, options);
273
+ }
274
+ };
275
+
276
+ //#endregion
277
+ //#region src/converter/data.ts
278
+ /**
279
+ * @class DataConverter
280
+ * @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
281
+ */
282
+ var $Data = class $Data extends $BaseConverter {
283
+ /** * Conversion factors based on bytes. */
284
+ static #factors = {
285
+ bit: 1 / 8,
286
+ byte: 1,
287
+ kilobit: 128,
288
+ kilobyte: 1024,
289
+ megabit: 131072,
290
+ megabyte: 1048576,
291
+ gigabit: 134217728,
292
+ gigabyte: 1073741824,
293
+ terabit: 137438953472,
294
+ terabyte: 1099511627776,
295
+ petabit: 0x800000000000,
296
+ petabyte: 0x4000000000000
297
+ };
298
+ /**
299
+ * Convert data value to other data units
300
+ * @param value Number or numeric string value to convert.
301
+ * @param unit Base data unit for the provided value.
302
+ */
303
+ constructor(value, unit) {
304
+ super(value, unit);
305
+ }
306
+ /** @instance Converts to base unit (bytes). */
307
+ #toBytes() {
308
+ return this.value * $Data.#factors[this.unit];
309
+ }
310
+ /**
311
+ * @instance Converts to target data unit.
312
+ * @param target Target data unit.
313
+ */
314
+ to(target) {
315
+ return this.#toBytes() / $Data.#factors[target];
316
+ }
317
+ /**
318
+ * @instance Converts to all data units.
319
+ * @returns Object with all unit conversions.
320
+ */
321
+ toAll() {
322
+ const inBytes = this.#toBytes();
323
+ const result = {};
324
+ for (const unit of require_constants.UNITS.data) result[unit] = inBytes / $Data.#factors[unit];
325
+ return result;
326
+ }
327
+ /**
328
+ * @instance Formats the converted value.
329
+ * @param target Target data unit.
330
+ * @param options Formatting options.
331
+ * @returns Formatted string like "256MB", "256 megabytes", or "2.56e+2 MB".
332
+ */
333
+ formatTo(target, options) {
334
+ const value = this.to(target);
335
+ return this.$formatTo(value, target, {
336
+ bit: "b",
337
+ byte: "B",
338
+ kilobit: "Kb",
339
+ kilobyte: "KB",
340
+ megabit: "Mb",
341
+ megabyte: "MB",
342
+ gigabit: "Gb",
343
+ gigabyte: "GB",
344
+ terabit: "Tb",
345
+ terabyte: "TB",
346
+ petabit: "Pb",
347
+ petabyte: "PB"
348
+ }, options);
349
+ }
350
+ };
351
+
352
+ //#endregion
353
+ //#region src/converter/length.ts
354
+ /**
355
+ * @class LengthConverter
356
+ * @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
357
+ */
358
+ var $Length = class $Length extends $BaseConverter {
359
+ /** * Conversion factors based on meters. */
360
+ static #factors = {
361
+ millimeter: .001,
362
+ centimeter: .01,
363
+ meter: 1,
364
+ kilometer: 1e3,
365
+ millimetre: .001,
366
+ centimetre: .01,
367
+ metre: 1,
368
+ kilometre: 1e3,
369
+ inch: .0254,
370
+ foot: .3048,
371
+ yard: .9144,
372
+ mile: 1609.344,
373
+ "nautical-mile": 1852,
374
+ "light-year": 9460730472580800
375
+ };
376
+ /**
377
+ * Convert length/distance value to other length/distance units
378
+ * @param value Number or numeric string value to convert.
379
+ * @param unit Base length/distance unit for the provided value.
380
+ */
381
+ constructor(value, unit) {
382
+ super(value, unit);
383
+ }
384
+ /** @instance Converts to base unit (meters). */
385
+ #toMeters() {
386
+ return this.value * $Length.#factors[this.unit];
387
+ }
388
+ /**
389
+ * @instance Converts to target length/distance unit.
390
+ * @param target Target length/distance unit.
391
+ */
392
+ to(target) {
393
+ return this.#toMeters() / $Length.#factors[target];
394
+ }
395
+ /**
396
+ * @instance Converts to all data units.
397
+ * @returns Object with all unit conversions.
398
+ */
399
+ toAll() {
400
+ const inMeters = this.#toMeters();
401
+ const result = {};
402
+ for (const unit of require_constants.UNITS.length) result[unit] = inMeters / $Length.#factors[unit];
403
+ return result;
404
+ }
405
+ /**
406
+ * @instance Formats the converted value and unit.
407
+ * @param target Target unit to format to.
408
+ * @param options Formatting options.
409
+ * @returns Formatted string like "5km", "5.12 miles", or "5e+3 meter".
410
+ */
411
+ formatTo(target, options) {
412
+ const value = this.to(target);
413
+ return this.$formatTo(value, target, {
414
+ millimeter: "mm",
415
+ centimeter: "cm",
416
+ meter: "m",
417
+ kilometer: "km",
418
+ millimetre: "mm",
419
+ centimetre: "cm",
420
+ metre: "m",
421
+ kilometre: "km",
422
+ inch: "in",
423
+ foot: "ft",
424
+ yard: "yd",
425
+ mile: "mi",
426
+ "nautical-mile": "nmi",
427
+ "light-year": "ly"
428
+ }, options);
429
+ }
430
+ };
431
+
432
+ //#endregion
433
+ //#region src/converter/mass.ts
434
+ /**
435
+ * @class MassConverter
436
+ * @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
437
+ */
438
+ var $Mass = class $Mass extends $BaseConverter {
439
+ /** * Common conversion factors relative to 1 kilogram. */
440
+ static #factors = {
441
+ microgram: 1e-9,
442
+ milligram: 1e-6,
443
+ gram: .001,
444
+ kilogram: 1,
445
+ tonne: 1e3,
446
+ ounce: .028349523125,
447
+ pound: .45359237,
448
+ stone: 6.35029318,
449
+ "short-ton": 907.18474,
450
+ "long-ton": 1016.0469088
451
+ };
452
+ /**
453
+ * Convert mass value to other mass units
454
+ * @param value Number or numeric string value to convert.
455
+ * @param unit Base mass unit for the provided value.
456
+ */
457
+ constructor(value, unit) {
458
+ super(value, unit);
459
+ }
460
+ /** @instance Converts to base unit (kilograms). */
461
+ #toKilograms() {
462
+ return this.value * $Mass.#factors[this.unit];
463
+ }
464
+ /**
465
+ * @instance Converts to target mass unit.
466
+ * @param target Target mass unit.
467
+ */
468
+ to(target) {
469
+ return this.#toKilograms() / $Mass.#factors[target];
470
+ }
471
+ /**
472
+ * @instance Converts to all mass units at once.
473
+ * @returns Object with all unit conversions.
474
+ */
475
+ toAll() {
476
+ const base = this.#toKilograms();
477
+ const result = {};
478
+ for (const unit of require_constants.UNITS.mass) result[unit] = base / $Mass.#factors[unit];
479
+ return result;
480
+ }
481
+ /**
482
+ * @instance Formats the converted value and unit.
483
+ * @param target Target unit to format to.
484
+ * @param options Formatting options.
485
+ * @returns Formatted string like "5kg", "5.25 kilograms", or "5e+3 gram".
486
+ */
487
+ formatTo(target, options) {
488
+ const value = this.to(target);
489
+ return this.$formatTo(value, target, {
490
+ microgram: "µg",
491
+ milligram: "mg",
492
+ gram: "g",
493
+ kilogram: "kg",
494
+ tonne: "t",
495
+ ounce: "oz",
496
+ pound: "lb",
497
+ stone: "st",
498
+ "short-ton": "t (US)",
499
+ "long-ton": "t (UK)"
500
+ }, options);
501
+ }
502
+ };
503
+
504
+ //#endregion
505
+ //#region src/converter/temp.ts
506
+ /**
507
+ * @class TemperatureConverter
508
+ * @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
509
+ */
510
+ var $Temperature = class $Temperature extends $BaseConverter {
511
+ /**
512
+ * Convert temperature value to other temperature units
513
+ * @param value Number or numeric string value to convert.
514
+ * @param unit Base temperature unit for the provided value.
515
+ */
516
+ constructor(value, unit) {
517
+ super(value, unit);
518
+ }
519
+ /**
520
+ * @private
521
+ * @description Conversion helper from Fahrenheit and Kelvin to Celsius.
522
+ */
523
+ static #toCelsius(value, from) {
524
+ switch (from) {
525
+ case "fahrenheit": return (value - 32) * (5 / 9);
526
+ case "kelvin": return value - 273.15;
527
+ default: return value;
528
+ }
529
+ }
530
+ /**
531
+ * @private
532
+ * @description Conversion helper from Celsius to Fahrenheit and Kelvin.
533
+ */
534
+ static #fromCelsius(value, to) {
535
+ switch (to) {
536
+ case "fahrenheit": return value * (9 / 5) + 32;
537
+ case "kelvin": return value + 273.15;
538
+ default: return value;
539
+ }
540
+ }
541
+ /**
542
+ * @instance Converts to target temperature unit.
543
+ * @param target Target temperature unit.
544
+ */
545
+ to(target) {
546
+ const celsiusValue = $Temperature.#toCelsius(this.value, this.unit);
547
+ return $Temperature.#fromCelsius(celsiusValue, target);
548
+ }
549
+ /**
550
+ * @instance Converts to all temperature units at once.
551
+ * @returns Object with all unit conversions.
552
+ */
553
+ toAll() {
554
+ const result = {};
555
+ for (const unit of require_constants.UNITS.temp) result[unit] = this.to(unit);
556
+ return result;
557
+ }
558
+ /**
559
+ * @instance Formats the converted value and unit.
560
+ * @param target Target unit to format to.
561
+ * @param options Formatting options.
562
+ * @returns Formatted string like "95°F", "5.25 kelvins", or "5e+3 celsius".
563
+ */
564
+ formatTo(target, options) {
565
+ const value = this.to(target);
566
+ return this.$formatTo(value, target, {
567
+ celsius: "°C",
568
+ fahrenheit: "°F",
569
+ kelvin: "K"
570
+ }, options);
571
+ }
572
+ };
573
+
574
+ //#endregion
575
+ //#region src/converter/time.ts
576
+ /**
577
+ * @class TimeConverter
578
+ * @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
579
+ */
580
+ var $Time = class $Time extends $BaseConverter {
581
+ /** * Common conversion factors based on seconds. */
582
+ static #factors = {
583
+ nanosecond: 1e-9,
584
+ microsecond: 1e-6,
585
+ millisecond: .001,
586
+ second: 1,
587
+ minute: 60,
588
+ hour: 3600,
589
+ day: 86400,
590
+ week: 604800,
591
+ month: 2629746,
592
+ year: 31556952,
593
+ decade: 315569520,
594
+ century: 3155695200,
595
+ millennium: 31556952e3
596
+ };
597
+ /**
598
+ * Convert time value to other time units
599
+ * @param value Number or numeric string value to convert.
600
+ * @param unit Base time unit for the provided value.
601
+ */
602
+ constructor(value, unit) {
603
+ super(value, unit);
604
+ }
605
+ /** @instance Converts to base unit (seconds). */
606
+ #toSeconds() {
607
+ return this.value * $Time.#factors[this.unit];
608
+ }
609
+ /**
610
+ * @instance Converts to target time unit.
611
+ * @param target Target time unit.
612
+ */
613
+ to(target) {
614
+ return this.#toSeconds() / $Time.#factors[target];
615
+ }
616
+ /**
617
+ * @instance Converts to all time units at once.
618
+ * @returns Object with all unit conversions.
619
+ */
620
+ toAll() {
621
+ const inSeconds = this.#toSeconds();
622
+ const result = {};
623
+ for (const unit of require_constants.UNITS.time) result[unit] = inSeconds / $Time.#factors[unit];
624
+ return result;
625
+ }
626
+ /**
627
+ * @instance Formats the converted value and unit.
628
+ * @param target Target unit to format to.
629
+ * @param options Formatting options.
630
+ * @returns Formatted string like "5h", "5.25 hours", or "5e+3 minute".
631
+ */
632
+ formatTo(target, options) {
633
+ const value = this.to(target);
634
+ return this.$formatTo(value, target, {
635
+ nanosecond: "ns",
636
+ microsecond: "µs",
637
+ millisecond: "ms",
638
+ second: "s",
639
+ minute: "min",
640
+ hour: "h",
641
+ day: "d",
642
+ week: "wk",
643
+ month: "mo",
644
+ year: "yr",
645
+ decade: "dec",
646
+ century: "cen",
647
+ millennium: "mil"
648
+ }, options);
649
+ }
650
+ };
651
+
652
+ //#endregion
653
+ //#region src/converter/volume.ts
654
+ /**
655
+ * @class VolumeConverter
656
+ * @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
657
+ */
658
+ var $Volume = class $Volume extends $BaseConverter {
659
+ /** * Common conversion factors based on cubic-meters. */
660
+ static #factors = {
661
+ "cubic-millimeter": 1e-9,
662
+ "cubic-centimeter": 1e-6,
663
+ "cubic-meter": 1,
664
+ "cubic-kilometer": 1e9,
665
+ "cubic-millimetre": 1e-9,
666
+ "cubic-centimetre": 1e-6,
667
+ "cubic-metre": 1,
668
+ "cubic-kilometre": 1e9,
669
+ "cubic-inch": 16387064e-12,
670
+ "cubic-foot": .028316846592,
671
+ "cubic-yard": .764554857984,
672
+ liter: .001,
673
+ litre: .001,
674
+ milliliter: 1e-6,
675
+ millilitre: 1e-6,
676
+ gallon: .003785411784,
677
+ quart: .000946352946,
678
+ pint: .000473176473,
679
+ cup: .0002365882365,
680
+ tablespoon: 1478676478125e-17,
681
+ teaspoon: 492892159375e-17
682
+ };
683
+ /**
684
+ * Convert volume value to other volume units
685
+ * @param value Number or numeric string value to convert.
686
+ * @param unit Base volume unit for the provided value.
687
+ */
688
+ constructor(value, unit) {
689
+ super(value, unit);
690
+ }
691
+ /** @instance Converts to base unit (cubic-meters). */
692
+ #toCubicMeters() {
693
+ return this.value * $Volume.#factors[this.unit];
694
+ }
695
+ /**
696
+ * @instance Converts to target volume unit.
697
+ * @param target Target volume unit.
698
+ */
699
+ to(target) {
700
+ return this.#toCubicMeters() / $Volume.#factors[target];
701
+ }
702
+ /**
703
+ * @instance Converts to target volume unit.
704
+ * @param target Target volume unit.
705
+ */
706
+ toAll() {
707
+ const base = this.#toCubicMeters();
708
+ const result = {};
709
+ for (const unit of require_constants.UNITS.volume) result[unit] = base / $Volume.#factors[unit];
710
+ return result;
711
+ }
712
+ /**
713
+ * @instance Formats the converted value and unit.
714
+ * @param target Target unit to format to.
715
+ * @param options Formatting options.
716
+ * @returns Formatted string like "5m³", "5.25 cubic-meters", or "5e+3 meter".
717
+ */
718
+ formatTo(target, options) {
719
+ const value = this.to(target);
720
+ return this.$formatTo(value, target, {
721
+ "cubic-millimeter": "mm³",
722
+ "cubic-centimeter": "cm³",
723
+ "cubic-meter": "m³",
724
+ "cubic-kilometer": "km³",
725
+ "cubic-millimetre": "mm³",
726
+ "cubic-centimetre": "cm³",
727
+ "cubic-metre": "m³",
728
+ "cubic-kilometre": "km³",
729
+ "cubic-inch": "in³",
730
+ "cubic-foot": "ft³",
731
+ "cubic-yard": "yd³",
732
+ liter: "L",
733
+ litre: "L",
734
+ milliliter: "mL",
735
+ millilitre: "mL",
736
+ gallon: "gal",
737
+ quart: "qt",
738
+ pint: "pt",
739
+ cup: "c",
740
+ tablespoon: "tbsp",
741
+ teaspoon: "tsp"
742
+ }, options);
743
+ }
744
+ };
745
+
746
+ //#endregion
747
+ //#region src/converter/Converter.ts
748
+ /**
749
+ * @function `Converter` Creates instances of specific unit converter class based on the provided unit.
750
+ *
751
+ * @description Converts values between compatible units (time, length, data, temperature, mass, area, volume).
752
+ * @remarks The returned instance exposes only methods relevant to the provided unit type.
753
+ */
754
+ function Converter(value, unit) {
755
+ switch ((() => {
756
+ if (unit) {
757
+ for (const [category, values] of Object.entries(require_constants.UNITS)) if ([...values].includes(unit)) return category;
758
+ }
759
+ })()) {
760
+ case "area": return new $Area(value, unit);
761
+ case "time": return new $Time(value, unit);
762
+ case "data": return new $Data(value, unit);
763
+ case "length": return new $Length(value, unit);
764
+ case "mass": return new $Mass(value, unit);
765
+ case "temp": return new $Temperature(value, unit);
766
+ case "volume": return new $Volume(value, unit);
767
+ default: return new $BaseConverter(value, unit);
768
+ }
769
+ }
770
+
771
+ //#endregion
772
+ exports.AreaConverter = $Area;
773
+ exports.Converter = Converter;
774
+ exports.DataConverter = $Data;
775
+ exports.LengthConverter = $Length;
776
+ exports.MassConverter = $Mass;
777
+ exports.TemperatureConverter = $Temperature;
778
+ exports.TimeConverter = $Time;
779
+ exports.VolumeConverter = $Volume;
780
+ exports.converter = Converter;