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