nhb-toolbox 4.0.70 → 4.0.75

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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Unit = void 0;
4
+ const constants_1 = require("./constants");
4
5
  /**
5
6
  * @class Represents a measurable unit and supports conversions between various types of units.
6
7
  *
@@ -37,11 +38,31 @@ class Unit {
37
38
  return `${this.#value} ${this.#unit ?? ''}`.trim();
38
39
  }
39
40
  /**
40
- * @instance Converts the value using a static method name from the Unit class.
41
+ * @instance Converts using scientific prefixes (e.g., kB to MB, mg to g).
41
42
  *
42
- * *Provides IntelliSense and type safety for method selection.*
43
+ * @param fromPrefix The SI prefix of the source unit.
44
+ * @param toPrefix The SI prefix of the target unit.
45
+ * @returns The converted numeric value.
46
+ */
47
+ convertByPrefix(fromPrefix, toPrefix) {
48
+ return Unit.convertByPrefix(this.#value, fromPrefix, toPrefix);
49
+ }
50
+ /**
51
+ * @instance Converts from prefixed unit string to another (e.g., kB to MB, mg to g).
52
+ *
53
+ * @param from Prefixed unit string (e.g., 'kB', 'mg').
54
+ * @param to Target prefixed unit string (e.g., 'MB', 'g').
55
+ * @returns The converted numeric value.
56
+ */
57
+ convertFromTo(from, to) {
58
+ return Unit.convertFromTo(this.#value, from, to);
59
+ }
60
+ /**
61
+ * @instance Converts the value using a static method name from the `Unit` class.
43
62
  *
44
- * @param methodName - A key of Unit class static method accepting a number and returning a number.
63
+ * - **N.B.** *Provides IntelliSense and type safety for method selection.*
64
+ *
65
+ * @param methodName - A static `Unit` method that accepts a number and returns a number.
45
66
  * @returns The converted numeric value.
46
67
  */
47
68
  convert(methodName) {
@@ -49,10 +70,44 @@ class Unit {
49
70
  if (typeof method !== 'function') {
50
71
  throw new Error(`Method ${methodName} is not a valid method!`);
51
72
  }
52
- // @ts-expect-error -_-
53
73
  return method(this.#value);
54
74
  }
55
- // ----- Static Conversion Methods -----
75
+ // ! ----- Static Conversion Methods ----- ! //
76
+ /**
77
+ * @static Converts a value using scientific prefixes (e.g., kB to MB, mg to g).
78
+ *
79
+ * @param value The value to convert.
80
+ * @param fromPrefix The SI prefix of the source unit.
81
+ * @param toPrefix The SI prefix of the target unit.
82
+ * @returns The converted numeric value.
83
+ */
84
+ static convertByPrefix(value, fromPrefix, toPrefix) {
85
+ const fromMultiplier = constants_1.PREFIX_MULTIPLIERS[fromPrefix];
86
+ const toMultiplier = constants_1.PREFIX_MULTIPLIERS[toPrefix];
87
+ return (value * fromMultiplier) / toMultiplier;
88
+ }
89
+ /**
90
+ * @static Converts from prefixed unit string to another (e.g., kB to MB, mg to g).
91
+ *
92
+ * @param value The numeric value.
93
+ * @param from Prefixed unit string (e.g., 'kB', 'mg').
94
+ * @param to Target prefixed unit string (e.g., 'MB', 'g').
95
+ * @returns The converted numeric value.
96
+ */
97
+ static convertFromTo(value, from, to) {
98
+ const extractPrefix = (str) => {
99
+ const match = str.match(/^(da|[yzafpnμumcdhkMGTPEZY]?)(.+)$/);
100
+ if (!match)
101
+ throw new Error(`Invalid unit format: ${str}`);
102
+ return [match[1], match[2]];
103
+ };
104
+ const [fromPrefix, fromUnit] = extractPrefix(from);
105
+ const [toPrefix, toUnit] = extractPrefix(to);
106
+ if (fromUnit !== toUnit) {
107
+ throw new Error(`Mismatched units: ${fromUnit} vs ${toUnit}`);
108
+ }
109
+ return Unit.convertByPrefix(value, fromPrefix, toPrefix);
110
+ }
56
111
  /** Converts meters to feet. */
57
112
  static metersToFeet(m) {
58
113
  return m * 3.28084;
@@ -101,6 +156,30 @@ class Unit {
101
156
  static kelvinToCelsius(k) {
102
157
  return k - 273.15;
103
158
  }
159
+ /** Converts Fahrenheit to Kelvin. */
160
+ static fahrenheitToKelvin(f) {
161
+ return ((f - 32) * 5) / 9 + 273.15;
162
+ }
163
+ /** Converts Kelvin to Fahrenheit. */
164
+ static kelvinToFahrenheit(k) {
165
+ return ((k - 273.15) * 9) / 5 + 32;
166
+ }
167
+ /** Converts milliliters to liters. */
168
+ static mlToLiters(ml) {
169
+ return ml / 1000;
170
+ }
171
+ /** Converts liters to milliliters. */
172
+ static litersToMl(l) {
173
+ return l * 1000;
174
+ }
175
+ /** Converts gallons to milliliters. */
176
+ static gallonsToMl(gal) {
177
+ return gal * 3785.41;
178
+ }
179
+ /** Converts milliliters to gallons. */
180
+ static mlToGallons(ml) {
181
+ return ml / 3785.41;
182
+ }
104
183
  /** Converts liters to gallons. */
105
184
  static litersToGallons(l) {
106
185
  return l * 0.264172;
@@ -125,6 +204,18 @@ class Unit {
125
204
  static mphToKmph(mph) {
126
205
  return mph / 0.621371;
127
206
  }
207
+ /** Converts minutes to hours. */
208
+ static minutesToHours(min) {
209
+ return min / 60;
210
+ }
211
+ /** Converts seconds to minutes. */
212
+ static secondsToMinutes(sec) {
213
+ return sec / 60;
214
+ }
215
+ /** Converts hours to days. */
216
+ static hoursToDays(hr) {
217
+ return hr / 24;
218
+ }
128
219
  /** Converts hours to minutes. */
129
220
  static hoursToMinutes(h) {
130
221
  return h * 60;
@@ -149,6 +240,34 @@ class Unit {
149
240
  static kbToMb(kb) {
150
241
  return kb / 1024;
151
242
  }
243
+ /** Converts kilobytes to gigabytes. */
244
+ static kbToGb(kb) {
245
+ return kb / (1024 * 1024);
246
+ }
247
+ /** Converts gigabytes to kilobytes. */
248
+ static gbToKb(gb) {
249
+ return gb * 1024 * 1024;
250
+ }
251
+ /** Converts bytes to kilobytes. */
252
+ static bytesToKb(bytes) {
253
+ return bytes / 1024;
254
+ }
255
+ /** Converts kilobytes to bytes. */
256
+ static kbToBytes(kb) {
257
+ return kb * 1024;
258
+ }
259
+ /** Converts megabytes to kilobytes. */
260
+ static mbToKb(mb) {
261
+ return mb * 1024;
262
+ }
263
+ /** Converts gigabytes to terabytes. */
264
+ static gbToTb(gb) {
265
+ return gb / 1024;
266
+ }
267
+ /** Converts terabytes to gigabytes. */
268
+ static tbToGb(tb) {
269
+ return tb * 1024;
270
+ }
152
271
  /** Converts joules to calories. */
153
272
  static joulesToCalories(j) {
154
273
  return j * 0.239006;
@@ -157,6 +276,14 @@ class Unit {
157
276
  static caloriesToJoules(cal) {
158
277
  return cal / 0.239006;
159
278
  }
279
+ /** Converts calories to kilojoules. */
280
+ static caloriesToKJoules(cal) {
281
+ return cal / 0.239006 / 1000;
282
+ }
283
+ /** Converts kilojoules to calories. */
284
+ static kJoulesToCalories(kj) {
285
+ return kj * 1000 * 0.239006;
286
+ }
160
287
  /** Converts atmospheres to pascals. */
161
288
  static atmToPascal(atm) {
162
289
  return atm * 101325;
@@ -165,6 +292,14 @@ class Unit {
165
292
  static pascalToAtm(pa) {
166
293
  return pa / 101325;
167
294
  }
295
+ /** Converts bar to pascals. */
296
+ static barToPascal(bar) {
297
+ return bar * 100000;
298
+ }
299
+ /** Converts pascals to bar. */
300
+ static pascalToBar(pa) {
301
+ return pa / 100000;
302
+ }
168
303
  /** Converts hertz to kilohertz. */
169
304
  static hzToKHz(hz) {
170
305
  return hz / 1000;
@@ -173,5 +308,61 @@ class Unit {
173
308
  static kHzToHz(khz) {
174
309
  return khz * 1000;
175
310
  }
311
+ /** Converts hertz to megahertz. */
312
+ static hzToMHz(hz) {
313
+ return hz / 1_000_000;
314
+ }
315
+ /** Converts megahertz to hertz. */
316
+ static mHzToHz(mhz) {
317
+ return mhz * 1_000_000;
318
+ }
319
+ /** Converts kilohertz to megahertz. */
320
+ static kHzToMHz(khz) {
321
+ return khz / 1000;
322
+ }
323
+ /** Converts megahertz to kilohertz. */
324
+ static mHzToKHz(mhz) {
325
+ return mhz * 1000;
326
+ }
327
+ /** Converts centimeters to meters. */
328
+ static cmToMeters(cm) {
329
+ return cm / 100;
330
+ }
331
+ /** Converts meters to centimeters. */
332
+ static metersToCm(m) {
333
+ return m * 100;
334
+ }
335
+ /** Converts millimeters to meters. */
336
+ static mmToMeters(mm) {
337
+ return mm / 1000;
338
+ }
339
+ /** Converts meters to millimeters. */
340
+ static metersToMm(m) {
341
+ return m * 1000;
342
+ }
343
+ /** Converts square kilometers to square meters. */
344
+ static sqkmToSqm(sqkm) {
345
+ return sqkm * 1_000_000;
346
+ }
347
+ /** Converts square meters to square kilometers. */
348
+ static sqmToSqkm(sqm) {
349
+ return sqm / 1_000_000;
350
+ }
351
+ /** Converts square feet to square inches. */
352
+ static sqftToSqin(sqft) {
353
+ return sqft * 144;
354
+ }
355
+ /** Converts square inches to square feet. */
356
+ static sqinToSqft(sqin) {
357
+ return sqin / 144;
358
+ }
359
+ /** Converts watts to kilowatts. */
360
+ static wattsToKw(w) {
361
+ return w / 1000;
362
+ }
363
+ /** Converts kilowatts to watts. */
364
+ static kwToWatts(kw) {
365
+ return kw * 1000;
366
+ }
176
367
  }
177
368
  exports.Unit = Unit;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UNIT_LABELS = exports.SUPPORTED_CURRENCIES = exports.CURRENCY_LOCALES = exports.LOCALE_CODES = exports.CURRENCY_CODES = exports.thousands = exports.tens = exports.teens = exports.ones = void 0;
3
+ exports.PREFIX_MULTIPLIERS = exports.UNITS = exports.SUPPORTED_CURRENCIES = exports.CURRENCY_LOCALES = exports.LOCALE_CODES = exports.CURRENCY_CODES = exports.thousands = exports.tens = exports.teens = exports.ones = void 0;
4
4
  exports.ones = [
5
5
  '',
6
6
  'one',
@@ -539,10 +539,8 @@ exports.SUPPORTED_CURRENCIES = [
539
539
  'USD',
540
540
  'ZAR',
541
541
  ];
542
- /**
543
- * @constant Unit names and their full readable labels.
544
- */
545
- exports.UNIT_LABELS = {
542
+ /** * @constant Unit names and their full readable labels. */
543
+ exports.UNITS = {
546
544
  // Length
547
545
  m: 'Meter',
548
546
  km: 'Kilometer',
@@ -585,3 +583,28 @@ exports.UNIT_LABELS = {
585
583
  hz: 'Hertz',
586
584
  khz: 'Kilohertz',
587
585
  };
586
+ /** * Scientific SI Unit prefix multipliers. */
587
+ exports.PREFIX_MULTIPLIERS = {
588
+ y: 1e-24,
589
+ z: 1e-21,
590
+ a: 1e-18,
591
+ f: 1e-15,
592
+ p: 1e-12,
593
+ n: 1e-9,
594
+ μ: 1e-6,
595
+ u: 1e-6,
596
+ m: 1e-3,
597
+ c: 1e-2,
598
+ d: 1e-1,
599
+ da: 1e1,
600
+ h: 1e2,
601
+ k: 1e3,
602
+ M: 1e6,
603
+ G: 1e9,
604
+ T: 1e12,
605
+ P: 1e15,
606
+ E: 1e18,
607
+ Z: 1e21,
608
+ Y: 1e24,
609
+ '': 1, // base unit, like meter, gram, byte etc.
610
+ };
@@ -1,4 +1,4 @@
1
- import type { UnitKey } from './types';
1
+ import type { SIPrefix, UnitKey, UnitNumberMethods } from './types';
2
2
  /**
3
3
  * @class Represents a measurable unit and supports conversions between various types of units.
4
4
  *
@@ -29,14 +29,48 @@ export declare class Unit {
29
29
  */
30
30
  toString(): string;
31
31
  /**
32
- * @instance Converts the value using a static method name from the Unit class.
32
+ * @instance Converts using scientific prefixes (e.g., kB to MB, mg to g).
33
33
  *
34
- * *Provides IntelliSense and type safety for method selection.*
34
+ * @param fromPrefix The SI prefix of the source unit.
35
+ * @param toPrefix The SI prefix of the target unit.
36
+ * @returns The converted numeric value.
37
+ */
38
+ convertByPrefix(fromPrefix: SIPrefix, toPrefix: SIPrefix): number;
39
+ /**
40
+ * @instance Converts from prefixed unit string to another (e.g., kB to MB, mg to g).
41
+ *
42
+ * @param from Prefixed unit string (e.g., 'kB', 'mg').
43
+ * @param to Target prefixed unit string (e.g., 'MB', 'g').
44
+ * @returns The converted numeric value.
45
+ */
46
+ convertFromTo(from: string, to: string): number;
47
+ /**
48
+ * @instance Converts the value using a static method name from the `Unit` class.
49
+ *
50
+ * - **N.B.** *Provides IntelliSense and type safety for method selection.*
51
+ *
52
+ * @param methodName - A static `Unit` method that accepts a number and returns a number.
53
+ * @returns The converted numeric value.
54
+ */
55
+ convert(methodName: UnitNumberMethods): number;
56
+ /**
57
+ * @static Converts a value using scientific prefixes (e.g., kB to MB, mg to g).
58
+ *
59
+ * @param value The value to convert.
60
+ * @param fromPrefix The SI prefix of the source unit.
61
+ * @param toPrefix The SI prefix of the target unit.
62
+ * @returns The converted numeric value.
63
+ */
64
+ static convertByPrefix(value: number, fromPrefix: SIPrefix, toPrefix: SIPrefix): number;
65
+ /**
66
+ * @static Converts from prefixed unit string to another (e.g., kB to MB, mg to g).
35
67
  *
36
- * @param methodName - A key of Unit class static method accepting a number and returning a number.
68
+ * @param value The numeric value.
69
+ * @param from Prefixed unit string (e.g., 'kB', 'mg').
70
+ * @param to Target prefixed unit string (e.g., 'MB', 'g').
37
71
  * @returns The converted numeric value.
38
72
  */
39
- convert<T extends keyof typeof Unit>(methodName: T): (typeof Unit)[T] extends (value: number) => number ? number : never;
73
+ static convertFromTo(value: number, from: string, to: string): number;
40
74
  /** Converts meters to feet. */
41
75
  static metersToFeet(m: number): number;
42
76
  /** Converts feet to meters. */
@@ -61,6 +95,18 @@ export declare class Unit {
61
95
  static celsiusToKelvin(c: number): number;
62
96
  /** Converts Kelvin to Celsius. */
63
97
  static kelvinToCelsius(k: number): number;
98
+ /** Converts Fahrenheit to Kelvin. */
99
+ static fahrenheitToKelvin(f: number): number;
100
+ /** Converts Kelvin to Fahrenheit. */
101
+ static kelvinToFahrenheit(k: number): number;
102
+ /** Converts milliliters to liters. */
103
+ static mlToLiters(ml: number): number;
104
+ /** Converts liters to milliliters. */
105
+ static litersToMl(l: number): number;
106
+ /** Converts gallons to milliliters. */
107
+ static gallonsToMl(gal: number): number;
108
+ /** Converts milliliters to gallons. */
109
+ static mlToGallons(ml: number): number;
64
110
  /** Converts liters to gallons. */
65
111
  static litersToGallons(l: number): number;
66
112
  /** Converts gallons to liters. */
@@ -73,6 +119,12 @@ export declare class Unit {
73
119
  static kmphToMph(kmph: number): number;
74
120
  /** Converts miles per hour to kilometers per hour. */
75
121
  static mphToKmph(mph: number): number;
122
+ /** Converts minutes to hours. */
123
+ static minutesToHours(min: number): number;
124
+ /** Converts seconds to minutes. */
125
+ static secondsToMinutes(sec: number): number;
126
+ /** Converts hours to days. */
127
+ static hoursToDays(hr: number): number;
76
128
  /** Converts hours to minutes. */
77
129
  static hoursToMinutes(h: number): number;
78
130
  /** Converts minutes to seconds. */
@@ -85,17 +137,67 @@ export declare class Unit {
85
137
  static gbToMb(gb: number): number;
86
138
  /** Converts kilobytes to megabytes. */
87
139
  static kbToMb(kb: number): number;
140
+ /** Converts kilobytes to gigabytes. */
141
+ static kbToGb(kb: number): number;
142
+ /** Converts gigabytes to kilobytes. */
143
+ static gbToKb(gb: number): number;
144
+ /** Converts bytes to kilobytes. */
145
+ static bytesToKb(bytes: number): number;
146
+ /** Converts kilobytes to bytes. */
147
+ static kbToBytes(kb: number): number;
148
+ /** Converts megabytes to kilobytes. */
149
+ static mbToKb(mb: number): number;
150
+ /** Converts gigabytes to terabytes. */
151
+ static gbToTb(gb: number): number;
152
+ /** Converts terabytes to gigabytes. */
153
+ static tbToGb(tb: number): number;
88
154
  /** Converts joules to calories. */
89
155
  static joulesToCalories(j: number): number;
90
156
  /** Converts calories to joules. */
91
157
  static caloriesToJoules(cal: number): number;
158
+ /** Converts calories to kilojoules. */
159
+ static caloriesToKJoules(cal: number): number;
160
+ /** Converts kilojoules to calories. */
161
+ static kJoulesToCalories(kj: number): number;
92
162
  /** Converts atmospheres to pascals. */
93
163
  static atmToPascal(atm: number): number;
94
164
  /** Converts pascals to atmospheres. */
95
165
  static pascalToAtm(pa: number): number;
166
+ /** Converts bar to pascals. */
167
+ static barToPascal(bar: number): number;
168
+ /** Converts pascals to bar. */
169
+ static pascalToBar(pa: number): number;
96
170
  /** Converts hertz to kilohertz. */
97
171
  static hzToKHz(hz: number): number;
98
172
  /** Converts kilohertz to hertz. */
99
173
  static kHzToHz(khz: number): number;
174
+ /** Converts hertz to megahertz. */
175
+ static hzToMHz(hz: number): number;
176
+ /** Converts megahertz to hertz. */
177
+ static mHzToHz(mhz: number): number;
178
+ /** Converts kilohertz to megahertz. */
179
+ static kHzToMHz(khz: number): number;
180
+ /** Converts megahertz to kilohertz. */
181
+ static mHzToKHz(mhz: number): number;
182
+ /** Converts centimeters to meters. */
183
+ static cmToMeters(cm: number): number;
184
+ /** Converts meters to centimeters. */
185
+ static metersToCm(m: number): number;
186
+ /** Converts millimeters to meters. */
187
+ static mmToMeters(mm: number): number;
188
+ /** Converts meters to millimeters. */
189
+ static metersToMm(m: number): number;
190
+ /** Converts square kilometers to square meters. */
191
+ static sqkmToSqm(sqkm: number): number;
192
+ /** Converts square meters to square kilometers. */
193
+ static sqmToSqkm(sqm: number): number;
194
+ /** Converts square feet to square inches. */
195
+ static sqftToSqin(sqft: number): number;
196
+ /** Converts square inches to square feet. */
197
+ static sqinToSqft(sqin: number): number;
198
+ /** Converts watts to kilowatts. */
199
+ static wattsToKw(w: number): number;
200
+ /** Converts kilowatts to watts. */
201
+ static kwToWatts(kw: number): number;
100
202
  }
101
203
  //# sourceMappingURL=Unit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Unit.d.ts","sourceRoot":"","sources":["../../../src/number/Unit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,IAAI;;IAIhB;;;;OAIG;gBACS,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;IAKzC;;;OAGG;IACH,QAAQ,IAAI,MAAM;IAIlB;;;;;;;OAOG;IACH,OAAO,CAAC,CAAC,SAAS,MAAM,OAAO,IAAI,EAClC,UAAU,EAAE,CAAC,GACX,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,GAAG,KAAK;IAatE,+BAA+B;IAC/B,MAAM,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAItC,+BAA+B;IAC/B,MAA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CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAIpC,mDAAmD;IACnD,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAItC,mDAAmD;IACnD,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAIrC,6CAA6C;IAC7C,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIvC,6CAA6C;IAC7C,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIvC,mCAAmC;IACnC,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAInC,mCAAmC;IACnC,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;CAGpC"}
@@ -171,10 +171,8 @@ export declare const CURRENCY_LOCALES: {
171
171
  };
172
172
  /** * Fiat currencies supported by Frankfurter API */
173
173
  export declare const SUPPORTED_CURRENCIES: readonly ["AUD", "BGN", "BRL", "CAD", "CHF", "CNY", "CZK", "DKK", "EUR", "GBP", "HKD", "HUF", "IDR", "ILS", "INR", "ISK", "JPY", "KRW", "MXN", "MYR", "NOK", "NZD", "PHP", "PLN", "RON", "SEK", "SGD", "THB", "TRY", "USD", "ZAR"];
174
- /**
175
- * @constant Unit names and their full readable labels.
176
- */
177
- export declare const UNIT_LABELS: {
174
+ /** * @constant Unit names and their full readable labels. */
175
+ export declare const UNITS: {
178
176
  readonly m: "Meter";
179
177
  readonly km: "Kilometer";
180
178
  readonly mi: "Mile";
@@ -206,4 +204,29 @@ export declare const UNIT_LABELS: {
206
204
  readonly hz: "Hertz";
207
205
  readonly khz: "Kilohertz";
208
206
  };
207
+ /** * Scientific SI Unit prefix multipliers. */
208
+ export declare const PREFIX_MULTIPLIERS: {
209
+ readonly y: 1e-24;
210
+ readonly z: 1e-21;
211
+ readonly a: 1e-18;
212
+ readonly f: 1e-15;
213
+ readonly p: 1e-12;
214
+ readonly n: 1e-9;
215
+ readonly μ: 0.000001;
216
+ readonly u: 0.000001;
217
+ readonly m: 0.001;
218
+ readonly c: 0.01;
219
+ readonly d: 0.1;
220
+ readonly da: 10;
221
+ readonly h: 100;
222
+ readonly k: 1000;
223
+ readonly M: 1000000;
224
+ readonly G: 1000000000;
225
+ readonly T: 1000000000000;
226
+ readonly P: 1000000000000000;
227
+ readonly E: 1000000000000000000;
228
+ readonly Z: 1e+21;
229
+ readonly Y: 1e+24;
230
+ readonly '': 1;
231
+ };
209
232
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/number/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,uFAWP,CAAC;AAEX,eAAO,MAAM,KAAK,sHAWR,CAAC;AAEX,eAAO,MAAM,IAAI,oGAWP,CAAC;AAEX,eAAO,MAAM,SAAS,8JAaZ,CAAC;AAEX,sCAAsC;AACtC,eAAO,MAAM,cAAc,2mCAiKjB,CAAC;AAEX,2CAA2C;AAC3C,eAAO,MAAM,YAAY,mnCA8Hf,CAAC;AAEX,8CAA8C;AAC9C,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiKnB,CAAC;AAEX,qDAAqD;AACrD,eAAO,MAAM,oBAAoB,oOAgCvB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoDd,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/number/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,uFAWP,CAAC;AAEX,eAAO,MAAM,KAAK,sHAWR,CAAC;AAEX,eAAO,MAAM,IAAI,oGAWP,CAAC;AAEX,eAAO,MAAM,SAAS,8JAaZ,CAAC;AAEX,sCAAsC;AACtC,eAAO,MAAM,cAAc,2mCAiKjB,CAAC;AAEX,2CAA2C;AAC3C,eAAO,MAAM,YAAY,mnCA8Hf,CAAC;AAEX,8CAA8C;AAC9C,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiKnB,CAAC;AAEX,qDAAqD;AACrD,eAAO,MAAM,oBAAoB,oOAgCvB,CAAC;AAEX,6DAA6D;AAC7D,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoDR,CAAC;AAEX,+CAA+C;AAC/C,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;CAuBrB,CAAC"}
@@ -1,4 +1,5 @@
1
- import type { CURRENCY_CODES, CURRENCY_LOCALES, LOCALE_CODES, SUPPORTED_CURRENCIES, UNIT_LABELS } from './constants';
1
+ import type { CURRENCY_CODES, CURRENCY_LOCALES, LOCALE_CODES, PREFIX_MULTIPLIERS, SUPPORTED_CURRENCIES, UNITS } from './constants';
2
+ import type { Unit } from './Unit';
2
3
  /** - Options for random number generator */
3
4
  export interface RandomNumberOptions {
4
5
  /** Minimum number to start with. */
@@ -118,8 +119,14 @@ export interface InversePercentageOptions {
118
119
  }
119
120
  /** * Options for calculating percentages and related values. */
120
121
  export type PercentageOptions = GetPercentOptions | GetValueOptions | GetOriginalOptions | GetChangeOptions | ApplyChangeOptions | GetDifferenceOptions | InversePercentageOptions;
121
- /** * Short forms of units */
122
- export type UnitKey = keyof typeof UNIT_LABELS;
123
- /** Labels for the units */
124
- export type UnitLabel = (typeof UNIT_LABELS)[UnitKey];
122
+ /** * Static methods from `Unit` class that accept a single number argument and return a number. */
123
+ export type UnitNumberMethods = {
124
+ [K in keyof typeof Unit]: (typeof Unit)[K] extends ((value: number) => number) ? K : never;
125
+ }[keyof typeof Unit];
126
+ /** - Short forms of units */
127
+ export type UnitKey = keyof typeof UNITS;
128
+ /** - Labels for the units */
129
+ export type UnitLabel = (typeof UNITS)[UnitKey];
130
+ /** - Prefixes for SI units */
131
+ export type SIPrefix = keyof typeof PREFIX_MULTIPLIERS;
125
132
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/number/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,oBAAoB,EACpB,WAAW,EACX,MAAM,aAAa,CAAC;AAErB,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IACnC,oCAAoC;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,kDAAkD;AAClD,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,OAAO,GAAG,SAAS,GAAG,KAAK;IACpE,6DAA6D;IAC7D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,CAAC,CAAC;CACb;AAED,4DAA4D;AAC5D,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,GAAG,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC;AAExE,oCAAoC;AACpC,MAAM,MAAM,UAAU,GACnB,KAAK,GACL,SAAS,GACT,KAAK,GACL,MAAM,GACN,OAAO,GACP,QAAQ,CAAC;AAEZ,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,kBAAkB,GAClB,oBAAoB,GACpB,wBAAwB,CAAC;AAE5B,mGAAmG;AACnG,MAAM,MAAM,iBAAiB,GAAG;KAC9B,CAAC,IAAI,MAAM,OAAO,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAClD,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CACzB,GACA,CAAC,GACA,KAAK;CACP,CAAC,MAAM,OAAO,IAAI,CAAC,CAAC;AAErB,6BAA6B;AAC7B,MAAM,MAAM,OAAO,GAAG,MAAM,OAAO,KAAK,CAAC;AAEzC,6BAA6B;AAC7B,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC;AAEhD,8BAA8B;AAC9B,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,kBAAkB,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { PREFIX_MULTIPLIERS } from './constants';
1
2
  /**
2
3
  * @class Represents a measurable unit and supports conversions between various types of units.
3
4
  *
@@ -34,11 +35,31 @@ export class Unit {
34
35
  return `${this.#value} ${this.#unit ?? ''}`.trim();
35
36
  }
36
37
  /**
37
- * @instance Converts the value using a static method name from the Unit class.
38
+ * @instance Converts using scientific prefixes (e.g., kB to MB, mg to g).
38
39
  *
39
- * *Provides IntelliSense and type safety for method selection.*
40
+ * @param fromPrefix The SI prefix of the source unit.
41
+ * @param toPrefix The SI prefix of the target unit.
42
+ * @returns The converted numeric value.
43
+ */
44
+ convertByPrefix(fromPrefix, toPrefix) {
45
+ return Unit.convertByPrefix(this.#value, fromPrefix, toPrefix);
46
+ }
47
+ /**
48
+ * @instance Converts from prefixed unit string to another (e.g., kB to MB, mg to g).
49
+ *
50
+ * @param from Prefixed unit string (e.g., 'kB', 'mg').
51
+ * @param to Target prefixed unit string (e.g., 'MB', 'g').
52
+ * @returns The converted numeric value.
53
+ */
54
+ convertFromTo(from, to) {
55
+ return Unit.convertFromTo(this.#value, from, to);
56
+ }
57
+ /**
58
+ * @instance Converts the value using a static method name from the `Unit` class.
40
59
  *
41
- * @param methodName - A key of Unit class static method accepting a number and returning a number.
60
+ * - **N.B.** *Provides IntelliSense and type safety for method selection.*
61
+ *
62
+ * @param methodName - A static `Unit` method that accepts a number and returns a number.
42
63
  * @returns The converted numeric value.
43
64
  */
44
65
  convert(methodName) {
@@ -46,10 +67,44 @@ export class Unit {
46
67
  if (typeof method !== 'function') {
47
68
  throw new Error(`Method ${methodName} is not a valid method!`);
48
69
  }
49
- // @ts-expect-error -_-
50
70
  return method(this.#value);
51
71
  }
52
- // ----- Static Conversion Methods -----
72
+ // ! ----- Static Conversion Methods ----- ! //
73
+ /**
74
+ * @static Converts a value using scientific prefixes (e.g., kB to MB, mg to g).
75
+ *
76
+ * @param value The value to convert.
77
+ * @param fromPrefix The SI prefix of the source unit.
78
+ * @param toPrefix The SI prefix of the target unit.
79
+ * @returns The converted numeric value.
80
+ */
81
+ static convertByPrefix(value, fromPrefix, toPrefix) {
82
+ const fromMultiplier = PREFIX_MULTIPLIERS[fromPrefix];
83
+ const toMultiplier = PREFIX_MULTIPLIERS[toPrefix];
84
+ return (value * fromMultiplier) / toMultiplier;
85
+ }
86
+ /**
87
+ * @static Converts from prefixed unit string to another (e.g., kB to MB, mg to g).
88
+ *
89
+ * @param value The numeric value.
90
+ * @param from Prefixed unit string (e.g., 'kB', 'mg').
91
+ * @param to Target prefixed unit string (e.g., 'MB', 'g').
92
+ * @returns The converted numeric value.
93
+ */
94
+ static convertFromTo(value, from, to) {
95
+ const extractPrefix = (str) => {
96
+ const match = str.match(/^(da|[yzafpnμumcdhkMGTPEZY]?)(.+)$/);
97
+ if (!match)
98
+ throw new Error(`Invalid unit format: ${str}`);
99
+ return [match[1], match[2]];
100
+ };
101
+ const [fromPrefix, fromUnit] = extractPrefix(from);
102
+ const [toPrefix, toUnit] = extractPrefix(to);
103
+ if (fromUnit !== toUnit) {
104
+ throw new Error(`Mismatched units: ${fromUnit} vs ${toUnit}`);
105
+ }
106
+ return Unit.convertByPrefix(value, fromPrefix, toPrefix);
107
+ }
53
108
  /** Converts meters to feet. */
54
109
  static metersToFeet(m) {
55
110
  return m * 3.28084;
@@ -98,6 +153,30 @@ export class Unit {
98
153
  static kelvinToCelsius(k) {
99
154
  return k - 273.15;
100
155
  }
156
+ /** Converts Fahrenheit to Kelvin. */
157
+ static fahrenheitToKelvin(f) {
158
+ return ((f - 32) * 5) / 9 + 273.15;
159
+ }
160
+ /** Converts Kelvin to Fahrenheit. */
161
+ static kelvinToFahrenheit(k) {
162
+ return ((k - 273.15) * 9) / 5 + 32;
163
+ }
164
+ /** Converts milliliters to liters. */
165
+ static mlToLiters(ml) {
166
+ return ml / 1000;
167
+ }
168
+ /** Converts liters to milliliters. */
169
+ static litersToMl(l) {
170
+ return l * 1000;
171
+ }
172
+ /** Converts gallons to milliliters. */
173
+ static gallonsToMl(gal) {
174
+ return gal * 3785.41;
175
+ }
176
+ /** Converts milliliters to gallons. */
177
+ static mlToGallons(ml) {
178
+ return ml / 3785.41;
179
+ }
101
180
  /** Converts liters to gallons. */
102
181
  static litersToGallons(l) {
103
182
  return l * 0.264172;
@@ -122,6 +201,18 @@ export class Unit {
122
201
  static mphToKmph(mph) {
123
202
  return mph / 0.621371;
124
203
  }
204
+ /** Converts minutes to hours. */
205
+ static minutesToHours(min) {
206
+ return min / 60;
207
+ }
208
+ /** Converts seconds to minutes. */
209
+ static secondsToMinutes(sec) {
210
+ return sec / 60;
211
+ }
212
+ /** Converts hours to days. */
213
+ static hoursToDays(hr) {
214
+ return hr / 24;
215
+ }
125
216
  /** Converts hours to minutes. */
126
217
  static hoursToMinutes(h) {
127
218
  return h * 60;
@@ -146,6 +237,34 @@ export class Unit {
146
237
  static kbToMb(kb) {
147
238
  return kb / 1024;
148
239
  }
240
+ /** Converts kilobytes to gigabytes. */
241
+ static kbToGb(kb) {
242
+ return kb / (1024 * 1024);
243
+ }
244
+ /** Converts gigabytes to kilobytes. */
245
+ static gbToKb(gb) {
246
+ return gb * 1024 * 1024;
247
+ }
248
+ /** Converts bytes to kilobytes. */
249
+ static bytesToKb(bytes) {
250
+ return bytes / 1024;
251
+ }
252
+ /** Converts kilobytes to bytes. */
253
+ static kbToBytes(kb) {
254
+ return kb * 1024;
255
+ }
256
+ /** Converts megabytes to kilobytes. */
257
+ static mbToKb(mb) {
258
+ return mb * 1024;
259
+ }
260
+ /** Converts gigabytes to terabytes. */
261
+ static gbToTb(gb) {
262
+ return gb / 1024;
263
+ }
264
+ /** Converts terabytes to gigabytes. */
265
+ static tbToGb(tb) {
266
+ return tb * 1024;
267
+ }
149
268
  /** Converts joules to calories. */
150
269
  static joulesToCalories(j) {
151
270
  return j * 0.239006;
@@ -154,6 +273,14 @@ export class Unit {
154
273
  static caloriesToJoules(cal) {
155
274
  return cal / 0.239006;
156
275
  }
276
+ /** Converts calories to kilojoules. */
277
+ static caloriesToKJoules(cal) {
278
+ return cal / 0.239006 / 1000;
279
+ }
280
+ /** Converts kilojoules to calories. */
281
+ static kJoulesToCalories(kj) {
282
+ return kj * 1000 * 0.239006;
283
+ }
157
284
  /** Converts atmospheres to pascals. */
158
285
  static atmToPascal(atm) {
159
286
  return atm * 101325;
@@ -162,6 +289,14 @@ export class Unit {
162
289
  static pascalToAtm(pa) {
163
290
  return pa / 101325;
164
291
  }
292
+ /** Converts bar to pascals. */
293
+ static barToPascal(bar) {
294
+ return bar * 100000;
295
+ }
296
+ /** Converts pascals to bar. */
297
+ static pascalToBar(pa) {
298
+ return pa / 100000;
299
+ }
165
300
  /** Converts hertz to kilohertz. */
166
301
  static hzToKHz(hz) {
167
302
  return hz / 1000;
@@ -170,4 +305,60 @@ export class Unit {
170
305
  static kHzToHz(khz) {
171
306
  return khz * 1000;
172
307
  }
308
+ /** Converts hertz to megahertz. */
309
+ static hzToMHz(hz) {
310
+ return hz / 1_000_000;
311
+ }
312
+ /** Converts megahertz to hertz. */
313
+ static mHzToHz(mhz) {
314
+ return mhz * 1_000_000;
315
+ }
316
+ /** Converts kilohertz to megahertz. */
317
+ static kHzToMHz(khz) {
318
+ return khz / 1000;
319
+ }
320
+ /** Converts megahertz to kilohertz. */
321
+ static mHzToKHz(mhz) {
322
+ return mhz * 1000;
323
+ }
324
+ /** Converts centimeters to meters. */
325
+ static cmToMeters(cm) {
326
+ return cm / 100;
327
+ }
328
+ /** Converts meters to centimeters. */
329
+ static metersToCm(m) {
330
+ return m * 100;
331
+ }
332
+ /** Converts millimeters to meters. */
333
+ static mmToMeters(mm) {
334
+ return mm / 1000;
335
+ }
336
+ /** Converts meters to millimeters. */
337
+ static metersToMm(m) {
338
+ return m * 1000;
339
+ }
340
+ /** Converts square kilometers to square meters. */
341
+ static sqkmToSqm(sqkm) {
342
+ return sqkm * 1_000_000;
343
+ }
344
+ /** Converts square meters to square kilometers. */
345
+ static sqmToSqkm(sqm) {
346
+ return sqm / 1_000_000;
347
+ }
348
+ /** Converts square feet to square inches. */
349
+ static sqftToSqin(sqft) {
350
+ return sqft * 144;
351
+ }
352
+ /** Converts square inches to square feet. */
353
+ static sqinToSqft(sqin) {
354
+ return sqin / 144;
355
+ }
356
+ /** Converts watts to kilowatts. */
357
+ static wattsToKw(w) {
358
+ return w / 1000;
359
+ }
360
+ /** Converts kilowatts to watts. */
361
+ static kwToWatts(kw) {
362
+ return kw * 1000;
363
+ }
173
364
  }
@@ -536,10 +536,8 @@ export const SUPPORTED_CURRENCIES = [
536
536
  'USD',
537
537
  'ZAR',
538
538
  ];
539
- /**
540
- * @constant Unit names and their full readable labels.
541
- */
542
- export const UNIT_LABELS = {
539
+ /** * @constant Unit names and their full readable labels. */
540
+ export const UNITS = {
543
541
  // Length
544
542
  m: 'Meter',
545
543
  km: 'Kilometer',
@@ -582,3 +580,28 @@ export const UNIT_LABELS = {
582
580
  hz: 'Hertz',
583
581
  khz: 'Kilohertz',
584
582
  };
583
+ /** * Scientific SI Unit prefix multipliers. */
584
+ export const PREFIX_MULTIPLIERS = {
585
+ y: 1e-24,
586
+ z: 1e-21,
587
+ a: 1e-18,
588
+ f: 1e-15,
589
+ p: 1e-12,
590
+ n: 1e-9,
591
+ μ: 1e-6,
592
+ u: 1e-6,
593
+ m: 1e-3,
594
+ c: 1e-2,
595
+ d: 1e-1,
596
+ da: 1e1,
597
+ h: 1e2,
598
+ k: 1e3,
599
+ M: 1e6,
600
+ G: 1e9,
601
+ T: 1e12,
602
+ P: 1e15,
603
+ E: 1e18,
604
+ Z: 1e21,
605
+ Y: 1e24,
606
+ '': 1, // base unit, like meter, gram, byte etc.
607
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "4.0.70",
3
+ "version": "4.0.75",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions and classes for everyday development needs.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",