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.
- package/LICENSE +201 -0
- package/dist/Color-B3mgF9Dh.d.cts +486 -0
- package/dist/Color-D38Xrw65.d.mts +486 -0
- package/dist/Stylog-Df7eq3-j.d.cts +519 -0
- package/dist/Stylog-jvlLcMQq.d.mts +519 -0
- package/dist/array-DvW0zIu6.d.mts +130 -0
- package/dist/array-rUnEVisO.d.cts +130 -0
- package/dist/basics-D_eSv0cu.cjs +132 -0
- package/dist/basics-Dp_aEK81.mjs +115 -0
- package/dist/basics-WEYWlnRO.d.cts +95 -0
- package/dist/basics-uBSfkBEI.d.mts +95 -0
- package/dist/case-BWIt8Ash.mjs +449 -0
- package/dist/case-C-S-b5YP.d.cts +327 -0
- package/dist/case-CS8Ii3A7.cjs +526 -0
- package/dist/case-CybASFPD.d.mts +327 -0
- package/dist/change-case.cjs +32 -0
- package/dist/change-case.d.cts +18 -0
- package/dist/change-case.d.mts +18 -0
- package/dist/change-case.mjs +19 -0
- package/dist/colors.cjs +574 -0
- package/dist/colors.d.cts +355 -0
- package/dist/colors.d.mts +355 -0
- package/dist/colors.mjs +547 -0
- package/dist/constants-2gAw23_7.mjs +144 -0
- package/dist/constants-B34K0QPi.d.cts +21 -0
- package/dist/constants-BIBDKY1u.cjs +924 -0
- package/dist/constants-BWT-810U.cjs +158 -0
- package/dist/constants-BwbHnXlM.mjs +662 -0
- package/dist/constants-BxN9l5el.cjs +74 -0
- package/dist/constants-CLS_bgKD.d.mts +847 -0
- package/dist/constants-D73iFu8g.mjs +171 -0
- package/dist/constants-DAfRxaa8.mjs +62 -0
- package/dist/constants-DQYeCjlx.cjs +207 -0
- package/dist/constants-Deeie-iH.d.mts +21 -0
- package/dist/constants-DpTG9RP6.d.mts +29 -0
- package/dist/constants-DqwnkJ_d.cjs +740 -0
- package/dist/constants-DvRUY_FY.cjs +150 -0
- package/dist/constants-VcRtQu0K.d.cts +29 -0
- package/dist/constants-X5hm1UtB.mjs +912 -0
- package/dist/constants-eNd-iYsV.mjs +134 -0
- package/dist/constants-qm8FafmD.d.cts +847 -0
- package/dist/constants.cjs +415 -0
- package/dist/constants.d.cts +184 -0
- package/dist/constants.d.mts +184 -0
- package/dist/constants.mjs +378 -0
- package/dist/convert-BOCgUv2D.cjs +252 -0
- package/dist/convert-Bn4jFomQ.mjs +169 -0
- package/dist/convert-BrzlG-m_.cjs +475 -0
- package/dist/convert-DhaUoPVU.mjs +368 -0
- package/dist/converter-1P90_RcP.d.mts +402 -0
- package/dist/converter-CmkcAppi.d.cts +402 -0
- package/dist/converter.cjs +780 -0
- package/dist/converter.d.cts +29 -0
- package/dist/converter.d.mts +29 -0
- package/dist/converter.mjs +771 -0
- package/dist/countries-CIpmtEzV.cjs +1469 -0
- package/dist/countries-Cy0xiqS3.mjs +1463 -0
- package/dist/css-colors-Bx947Ng3.d.cts +179 -0
- package/dist/css-colors-CXCDqQbG.cjs +186 -0
- package/dist/css-colors-CXTp1vvy.d.mts +179 -0
- package/dist/css-colors-DfUW3nTR.mjs +180 -0
- package/dist/date.cjs +332 -0
- package/dist/date.d.cts +213 -0
- package/dist/date.d.mts +213 -0
- package/dist/date.mjs +298 -0
- package/dist/dom.cjs +461 -0
- package/dist/dom.d.cts +228 -0
- package/dist/dom.d.mts +228 -0
- package/dist/dom.mjs +429 -0
- package/dist/form-BMFVGUrN.d.mts +118 -0
- package/dist/form-DRFbryvK.d.cts +118 -0
- package/dist/guards-3kaUX66g.mjs +157 -0
- package/dist/guards-C8gkvIHb.cjs +240 -0
- package/dist/guards-DdyU4h4o.mjs +110 -0
- package/dist/guards-Efhp1mNy.cjs +151 -0
- package/dist/guards.cjs +172 -0
- package/dist/guards.d.cts +399 -0
- package/dist/guards.d.mts +399 -0
- package/dist/guards.mjs +75 -0
- package/dist/hash-B6JPEyAz.d.mts +131 -0
- package/dist/hash-NTpeKYB_.d.cts +131 -0
- package/dist/hash.cjs +2126 -0
- package/dist/hash.d.cts +1239 -0
- package/dist/hash.d.mts +1239 -0
- package/dist/hash.mjs +2095 -0
- package/dist/http-status-BAZdtr7-.d.mts +65 -0
- package/dist/http-status-U_3MtoGb.d.cts +65 -0
- package/dist/http-status.cjs +173 -0
- package/dist/http-status.d.cts +142 -0
- package/dist/http-status.d.mts +142 -0
- package/dist/http-status.mjs +171 -0
- package/dist/index.cjs +2551 -0
- package/dist/index.d.cts +1493 -0
- package/dist/index.d.mts +1493 -0
- package/dist/index.mjs +2357 -0
- package/dist/object-B0TV3eHx.d.mts +8052 -0
- package/dist/object-Blq0Amdv.d.cts +8052 -0
- package/dist/objectify-CDs0Fbr1.mjs +417 -0
- package/dist/objectify-DIJ-OBmo.cjs +524 -0
- package/dist/paginator.cjs +245 -0
- package/dist/paginator.d.cts +144 -0
- package/dist/paginator.d.mts +144 -0
- package/dist/paginator.mjs +243 -0
- package/dist/parse-2ubxXZRp.cjs +211 -0
- package/dist/parse-N7g942uy.mjs +164 -0
- package/dist/pluralizer-BjMIc6uT.d.mts +42 -0
- package/dist/pluralizer-Cb6ZmrDl.d.cts +42 -0
- package/dist/pluralizer.cjs +678 -0
- package/dist/pluralizer.d.cts +152 -0
- package/dist/pluralizer.d.mts +152 -0
- package/dist/pluralizer.mjs +676 -0
- package/dist/primitives-B26uZolQ.cjs +228 -0
- package/dist/primitives-KsFUp3kQ.mjs +144 -0
- package/dist/specials-D48_IZbd.d.mts +108 -0
- package/dist/specials-DzLr1ZgU.cjs +477 -0
- package/dist/specials-LVONlKbQ.d.cts +108 -0
- package/dist/specials-uhDuRg8H.mjs +292 -0
- package/dist/string-CBAbxaG1.d.mts +258 -0
- package/dist/string-CsNsm_65.d.cts +258 -0
- package/dist/stylog.cjs +621 -0
- package/dist/stylog.d.cts +49 -0
- package/dist/stylog.d.mts +49 -0
- package/dist/stylog.mjs +614 -0
- package/dist/timezone-B2OYK6Fh.mjs +5589 -0
- package/dist/timezone-Beh9IGpw.cjs +5625 -0
- package/dist/types/array.cjs +16 -0
- package/dist/types/array.d.cts +18 -0
- package/dist/types/array.d.mts +18 -0
- package/dist/types/array.mjs +17 -0
- package/dist/types/colors.cjs +16 -0
- package/dist/types/colors.d.cts +18 -0
- package/dist/types/colors.d.mts +18 -0
- package/dist/types/colors.mjs +17 -0
- package/dist/types/converter.cjs +16 -0
- package/dist/types/converter.d.cts +18 -0
- package/dist/types/converter.d.mts +18 -0
- package/dist/types/converter.mjs +17 -0
- package/dist/types/form.cjs +16 -0
- package/dist/types/form.d.cts +18 -0
- package/dist/types/form.d.mts +18 -0
- package/dist/types/form.mjs +17 -0
- package/dist/types/hash.cjs +16 -0
- package/dist/types/hash.d.cts +18 -0
- package/dist/types/hash.d.mts +18 -0
- package/dist/types/hash.mjs +17 -0
- package/dist/types/http-status.cjs +16 -0
- package/dist/types/http-status.d.cts +18 -0
- package/dist/types/http-status.d.mts +18 -0
- package/dist/types/http-status.mjs +17 -0
- package/dist/types/index.cjs +16 -0
- package/dist/types/index.d.cts +18 -0
- package/dist/types/index.d.mts +18 -0
- package/dist/types/index.mjs +17 -0
- package/dist/types/number.cjs +16 -0
- package/dist/types/number.d.cts +18 -0
- package/dist/types/number.d.mts +18 -0
- package/dist/types/number.mjs +17 -0
- package/dist/types/object.cjs +16 -0
- package/dist/types/object.d.cts +18 -0
- package/dist/types/object.d.mts +18 -0
- package/dist/types/object.mjs +17 -0
- package/dist/types/pluralizer.cjs +16 -0
- package/dist/types/pluralizer.d.cts +18 -0
- package/dist/types/pluralizer.d.mts +18 -0
- package/dist/types/pluralizer.mjs +17 -0
- package/dist/types/string.cjs +16 -0
- package/dist/types/string.d.cts +18 -0
- package/dist/types/string.d.mts +18 -0
- package/dist/types/string.mjs +17 -0
- package/dist/types/stylog.cjs +16 -0
- package/dist/types/stylog.d.cts +18 -0
- package/dist/types/stylog.d.mts +18 -0
- package/dist/types/stylog.mjs +17 -0
- package/dist/types/utils.cjs +16 -0
- package/dist/types/utils.d.cts +18 -0
- package/dist/types/utils.d.mts +18 -0
- package/dist/types/utils.mjs +17 -0
- package/dist/types/verbalizer.cjs +16 -0
- package/dist/types/verbalizer.d.cts +30 -0
- package/dist/types/verbalizer.d.mts +30 -0
- package/dist/types/verbalizer.mjs +17 -0
- package/dist/utilities-CLUmdQeV.cjs +140 -0
- package/dist/utilities-m5yFKqLd.mjs +105 -0
- package/dist/utils-ClW9LA6f.mjs +449 -0
- package/dist/utils-DLFRgXUC.cjs +568 -0
- package/dist/verbalizer.cjs +998 -0
- package/dist/verbalizer.d.cts +148 -0
- package/dist/verbalizer.d.mts +148 -0
- package/dist/verbalizer.mjs +996 -0
- package/package.json +249 -0
|
@@ -0,0 +1,402 @@
|
|
|
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 { Hn as Mutable, i as $Record, it as Numeric, zn as LooseLiteral } from "./object-Blq0Amdv.cjs";
|
|
18
|
+
import { t as UNITS } from "./constants-VcRtQu0K.cjs";
|
|
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.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox.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.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox.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
|
+
//#region src/converter/data.d.ts
|
|
172
|
+
/**
|
|
173
|
+
* @class DataConverter
|
|
174
|
+
* @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
|
|
175
|
+
*/
|
|
176
|
+
declare class $Data extends $BaseConverter<$DataUnit> {
|
|
177
|
+
#private;
|
|
178
|
+
/**
|
|
179
|
+
* Convert data value to other data units
|
|
180
|
+
* @param value Number or numeric string value to convert.
|
|
181
|
+
* @param unit Base data unit for the provided value.
|
|
182
|
+
*/
|
|
183
|
+
constructor(value: Numeric, unit: $DataUnit);
|
|
184
|
+
/**
|
|
185
|
+
* @instance Converts to target data unit.
|
|
186
|
+
* @param target Target data unit.
|
|
187
|
+
*/
|
|
188
|
+
to(target: $DataUnit): number;
|
|
189
|
+
/**
|
|
190
|
+
* @instance Converts to all data units.
|
|
191
|
+
* @returns Object with all unit conversions.
|
|
192
|
+
*/
|
|
193
|
+
toAll(): $Record<$DataUnit, number>;
|
|
194
|
+
/**
|
|
195
|
+
* @instance Formats the converted value.
|
|
196
|
+
* @param target Target data unit.
|
|
197
|
+
* @param options Formatting options.
|
|
198
|
+
* @returns Formatted string like "256MB", "256 megabytes", or "2.56e+2 MB".
|
|
199
|
+
*/
|
|
200
|
+
formatTo(target: $DataUnit, options?: FormatToOptions): string;
|
|
201
|
+
}
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region src/converter/length.d.ts
|
|
204
|
+
/**
|
|
205
|
+
* @class LengthConverter
|
|
206
|
+
* @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
|
|
207
|
+
*/
|
|
208
|
+
declare class $Length extends $BaseConverter<$LengthUnit> {
|
|
209
|
+
#private;
|
|
210
|
+
/**
|
|
211
|
+
* Convert length/distance value to other length/distance units
|
|
212
|
+
* @param value Number or numeric string value to convert.
|
|
213
|
+
* @param unit Base length/distance unit for the provided value.
|
|
214
|
+
*/
|
|
215
|
+
constructor(value: Numeric, unit: $LengthUnit);
|
|
216
|
+
/**
|
|
217
|
+
* @instance Converts to target length/distance unit.
|
|
218
|
+
* @param target Target length/distance unit.
|
|
219
|
+
*/
|
|
220
|
+
to(target: $LengthUnit): number;
|
|
221
|
+
/**
|
|
222
|
+
* @instance Converts to all data units.
|
|
223
|
+
* @returns Object with all unit conversions.
|
|
224
|
+
*/
|
|
225
|
+
toAll(): $Record<$LengthUnit, number>;
|
|
226
|
+
/**
|
|
227
|
+
* @instance Formats the converted value and unit.
|
|
228
|
+
* @param target Target unit to format to.
|
|
229
|
+
* @param options Formatting options.
|
|
230
|
+
* @returns Formatted string like "5km", "5.12 miles", or "5e+3 meter".
|
|
231
|
+
*/
|
|
232
|
+
formatTo(target: $LengthUnit, options?: FormatToOptions): string;
|
|
233
|
+
}
|
|
234
|
+
//#endregion
|
|
235
|
+
//#region src/converter/mass.d.ts
|
|
236
|
+
/**
|
|
237
|
+
* @class MassConverter
|
|
238
|
+
* @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
|
|
239
|
+
*/
|
|
240
|
+
declare class $Mass extends $BaseConverter<$MassUnit> {
|
|
241
|
+
#private;
|
|
242
|
+
/**
|
|
243
|
+
* Convert mass value to other mass units
|
|
244
|
+
* @param value Number or numeric string value to convert.
|
|
245
|
+
* @param unit Base mass unit for the provided value.
|
|
246
|
+
*/
|
|
247
|
+
constructor(value: Numeric, unit: $MassUnit);
|
|
248
|
+
/**
|
|
249
|
+
* @instance Converts to target mass unit.
|
|
250
|
+
* @param target Target mass unit.
|
|
251
|
+
*/
|
|
252
|
+
to(target: $MassUnit): number;
|
|
253
|
+
/**
|
|
254
|
+
* @instance Converts to all mass units at once.
|
|
255
|
+
* @returns Object with all unit conversions.
|
|
256
|
+
*/
|
|
257
|
+
toAll(): $Record<$MassUnit, number>;
|
|
258
|
+
/**
|
|
259
|
+
* @instance Formats the converted value and unit.
|
|
260
|
+
* @param target Target unit to format to.
|
|
261
|
+
* @param options Formatting options.
|
|
262
|
+
* @returns Formatted string like "5kg", "5.25 kilograms", or "5e+3 gram".
|
|
263
|
+
*/
|
|
264
|
+
formatTo(target: $MassUnit, options?: FormatToOptions): string;
|
|
265
|
+
}
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/converter/temp.d.ts
|
|
268
|
+
/**
|
|
269
|
+
* @class TemperatureConverter
|
|
270
|
+
* @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
|
|
271
|
+
*/
|
|
272
|
+
declare class $Temperature extends $BaseConverter<$TempUnit> {
|
|
273
|
+
#private;
|
|
274
|
+
/**
|
|
275
|
+
* Convert temperature value to other temperature units
|
|
276
|
+
* @param value Number or numeric string value to convert.
|
|
277
|
+
* @param unit Base temperature unit for the provided value.
|
|
278
|
+
*/
|
|
279
|
+
constructor(value: Numeric, unit: $TempUnit);
|
|
280
|
+
/**
|
|
281
|
+
* @instance Converts to target temperature unit.
|
|
282
|
+
* @param target Target temperature unit.
|
|
283
|
+
*/
|
|
284
|
+
to(target: $TempUnit): number;
|
|
285
|
+
/**
|
|
286
|
+
* @instance Converts to all temperature units at once.
|
|
287
|
+
* @returns Object with all unit conversions.
|
|
288
|
+
*/
|
|
289
|
+
toAll(): $Record<$TempUnit, number>;
|
|
290
|
+
/**
|
|
291
|
+
* @instance Formats the converted value and unit.
|
|
292
|
+
* @param target Target unit to format to.
|
|
293
|
+
* @param options Formatting options.
|
|
294
|
+
* @returns Formatted string like "95°F", "5.25 kelvins", or "5e+3 celsius".
|
|
295
|
+
*/
|
|
296
|
+
formatTo(target: $TempUnit, options?: FormatToOptions): string;
|
|
297
|
+
}
|
|
298
|
+
//#endregion
|
|
299
|
+
//#region src/converter/time.d.ts
|
|
300
|
+
/**
|
|
301
|
+
* @class TimeConverter
|
|
302
|
+
* @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
|
|
303
|
+
*/
|
|
304
|
+
declare class $Time extends $BaseConverter<$TimeUnit> {
|
|
305
|
+
#private;
|
|
306
|
+
/**
|
|
307
|
+
* Convert time value to other time units
|
|
308
|
+
* @param value Number or numeric string value to convert.
|
|
309
|
+
* @param unit Base time unit for the provided value.
|
|
310
|
+
*/
|
|
311
|
+
constructor(value: Numeric, unit: $TimeUnit);
|
|
312
|
+
/**
|
|
313
|
+
* @instance Converts to target time unit.
|
|
314
|
+
* @param target Target time unit.
|
|
315
|
+
*/
|
|
316
|
+
to(target: $TimeUnit): number;
|
|
317
|
+
/**
|
|
318
|
+
* @instance Converts to all time units at once.
|
|
319
|
+
* @returns Object with all unit conversions.
|
|
320
|
+
*/
|
|
321
|
+
toAll(): $Record<$TimeUnit, number>;
|
|
322
|
+
/**
|
|
323
|
+
* @instance Formats the converted value and unit.
|
|
324
|
+
* @param target Target unit to format to.
|
|
325
|
+
* @param options Formatting options.
|
|
326
|
+
* @returns Formatted string like "5h", "5.25 hours", or "5e+3 minute".
|
|
327
|
+
*/
|
|
328
|
+
formatTo(target: $TimeUnit, options?: FormatToOptions): string;
|
|
329
|
+
}
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region src/converter/volume.d.ts
|
|
332
|
+
/**
|
|
333
|
+
* @class VolumeConverter
|
|
334
|
+
* @description Handles conversions with smart `.to()`, `.toAll()`, and `.formatTo()`.
|
|
335
|
+
*/
|
|
336
|
+
declare class $Volume extends $BaseConverter<$VolumeUnit> {
|
|
337
|
+
#private;
|
|
338
|
+
/**
|
|
339
|
+
* Convert volume value to other volume units
|
|
340
|
+
* @param value Number or numeric string value to convert.
|
|
341
|
+
* @param unit Base volume unit for the provided value.
|
|
342
|
+
*/
|
|
343
|
+
constructor(value: Numeric, unit: $VolumeUnit);
|
|
344
|
+
/**
|
|
345
|
+
* @instance Converts to target volume unit.
|
|
346
|
+
* @param target Target volume unit.
|
|
347
|
+
*/
|
|
348
|
+
to(target: $VolumeUnit): number;
|
|
349
|
+
/**
|
|
350
|
+
* @instance Converts to target volume unit.
|
|
351
|
+
* @param target Target volume unit.
|
|
352
|
+
*/
|
|
353
|
+
toAll(): $Record<$VolumeUnit, number>;
|
|
354
|
+
/**
|
|
355
|
+
* @instance Formats the converted value and unit.
|
|
356
|
+
* @param target Target unit to format to.
|
|
357
|
+
* @param options Formatting options.
|
|
358
|
+
* @returns Formatted string like "5m³", "5.25 cubic-meters", or "5e+3 meter".
|
|
359
|
+
*/
|
|
360
|
+
formatTo(target: $VolumeUnit, options?: FormatToOptions): string;
|
|
361
|
+
}
|
|
362
|
+
//#endregion
|
|
363
|
+
//#region src/types/converter.d.ts
|
|
364
|
+
/** - Type for Record of Units */
|
|
365
|
+
type UnitsRecord = typeof UNITS;
|
|
366
|
+
/** * Category of units supported by the converter. */
|
|
367
|
+
type Category = keyof UnitsRecord;
|
|
368
|
+
/** * Map of unit categories to their respective units. */
|
|
369
|
+
type UnitMap = { [Key in Category]: UnitsRecord[Key][number] };
|
|
370
|
+
/** * Union type of all supported units. May include any other strings. */
|
|
371
|
+
type $Unit = LooseLiteral<UnitMap[Category]>;
|
|
372
|
+
/** * Type for array of all Units */
|
|
373
|
+
type Units = Array<UnitMap[Category]>;
|
|
374
|
+
/** * Tuple type for Units in a specific Category */
|
|
375
|
+
type UnitsTuple<Cat extends Category> = Mutable<UnitsRecord[Cat]>;
|
|
376
|
+
/** * Infer the category of a given unit type `U`. */
|
|
377
|
+
type InferCategory<U extends $Unit> = { [K in Category]: U extends UnitMap[K] ? K : never }[Category];
|
|
378
|
+
/** * Infer Units belong to a specific Category */
|
|
379
|
+
type CategoryUnits<Cat extends Category> = UnitMap[Cat];
|
|
380
|
+
/** * Type for the returned converter instance based on the provided unit `U`. */
|
|
381
|
+
type Converted<U extends $Unit> = InferCategory<U> extends never ? $BaseConverter<U> : InferCategory<U> extends 'area' ? $Area : InferCategory<U> extends 'time' ? $Time : InferCategory<U> extends 'length' ? $Length : InferCategory<U> extends 'mass' ? $Mass : InferCategory<U> extends 'data' ? $Data : InferCategory<U> extends 'temp' ? $Temperature : InferCategory<U> extends 'volume' ? $Volume : $BaseConverter<U>;
|
|
382
|
+
/** * Options for formatting converted values for unit converter method(s). */
|
|
383
|
+
type FormatToOptions = {
|
|
384
|
+
/** Style of formatting. Default is `'plural'`. */style?: 'compact' | 'scientific' | 'plural'; /** Number of decimal places to include. Default is `2`. */
|
|
385
|
+
decimals?: number;
|
|
386
|
+
};
|
|
387
|
+
/** Union type for all the area units */
|
|
388
|
+
type $AreaUnit = UnitMap['area'];
|
|
389
|
+
/** Union type for all the data units */
|
|
390
|
+
type $DataUnit = UnitMap['data'];
|
|
391
|
+
/** Union type for all the length/distance units */
|
|
392
|
+
type $LengthUnit = UnitMap['length'];
|
|
393
|
+
/** Union type for all the mass units */
|
|
394
|
+
type $MassUnit = UnitMap['mass'];
|
|
395
|
+
/** Union type for all the temperature units */
|
|
396
|
+
type $TempUnit = UnitMap['temp'];
|
|
397
|
+
/** Union type for all the time units */
|
|
398
|
+
type $TimeUnit = UnitMap['time'];
|
|
399
|
+
/** Union type for all the volume units */
|
|
400
|
+
type $VolumeUnit = UnitMap['volume'];
|
|
401
|
+
//#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 };
|