@oliasoft-open-source/units 5.9.0 → 5.10.0-beta-1

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/dist/index.cjs CHANGED
@@ -1,6 +1,2937 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_conversion = require("./chunks/conversion.cjs");
3
- const require_units = require("./chunks/units.cjs");
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
21
+ value: mod,
22
+ enumerable: true
23
+ }) : target, mod));
24
+ //#endregion
25
+ let fraction_js = require("fraction.js");
26
+ fraction_js = __toESM(fraction_js, 1);
27
+ //#region src/numbers/statistics/confidence-interval.ts
28
+ const { abs, exp, sqrt } = Math;
29
+ /** Applies the one-dimensional iterative Newton method. */
30
+ function newton(functionValue, derivative, initialValue, tolerance = 1e-8, maxIterations = 30) {
31
+ let currentValue = initialValue;
32
+ let iteration = 0;
33
+ let error = 1;
34
+ while (error > tolerance && iteration < maxIterations) {
35
+ const nextValue = currentValue - functionValue(currentValue) / derivative(currentValue);
36
+ error = abs(functionValue(nextValue) - functionValue(currentValue));
37
+ if (error < tolerance) return [
38
+ nextValue,
39
+ true,
40
+ iteration
41
+ ];
42
+ currentValue = nextValue;
43
+ iteration += 1;
44
+ }
45
+ return [
46
+ initialValue,
47
+ false,
48
+ iteration
49
+ ];
50
+ }
51
+ /** Approximates the Gaussian error function. */
52
+ function erf(value) {
53
+ const t = 1 / (1 + .5 * abs(value));
54
+ const answer = 1 - t * exp(-(value ** 2) - 1.26551223 + t * (1.00002368 + t * (.37409196 + t * (.09678418 + t * (-.18628806 + t * (.27886807 + t * (-1.13520398 + t * (1.48851587 + t * (-.82215223 + t * .17087277)))))))));
55
+ return value >= 0 ? answer : -answer;
56
+ }
57
+ /** Converts a confidence interval to a number of standard deviations. */
58
+ function get_k_from_conf_int(confidenceInterval) {
59
+ const functionValue = (value) => {
60
+ return confidenceInterval - erf(value / sqrt(2));
61
+ };
62
+ const derivative = (value) => {
63
+ return -sqrt(2 / Math.PI) * exp(-.5 * value ** 2);
64
+ };
65
+ const [result] = newton(functionValue, derivative, 1);
66
+ return result;
67
+ }
68
+ /** Converts a number of standard deviations to a confidence interval. */
69
+ function get_conf_int_from_k(standardDeviations) {
70
+ return erf(standardDeviations / sqrt(2));
71
+ }
72
+ //#endregion
73
+ //#region src/units/constants.ts
74
+ /**
75
+ * Units labels
76
+ *
77
+ * @readonly
78
+ * @enum {Object}
79
+ */
80
+ const LABELS = Object.freeze({
81
+ in: "in",
82
+ mm: "mm",
83
+ cm: "cm",
84
+ m: "m",
85
+ microM: "μm",
86
+ km: "km",
87
+ ft: "ft",
88
+ usft: "usft",
89
+ in2: "in²",
90
+ cm2: "cm²",
91
+ m2: "m²",
92
+ kg: "kg",
93
+ tonnes: "t",
94
+ mt: "mt",
95
+ kip: "kip",
96
+ bbl: "bbl",
97
+ m3: "m³",
98
+ Mm3: "Mm³",
99
+ MMSCF: "MMSCF",
100
+ lbm: "lbm",
101
+ "kg/mol": "kg/mol",
102
+ "lbf/mol": "lbf/mol",
103
+ sg: "sg",
104
+ ppg: "ppg",
105
+ "kg/m3": "kg/m³",
106
+ "lbm/ft3": "lbm/ft³",
107
+ s: "s",
108
+ min: "min",
109
+ h: "h",
110
+ d: "d",
111
+ month: "month",
112
+ year: "year",
113
+ "bbl/ft": "bbl/ft",
114
+ lpm: "L/min",
115
+ lps: "L/s",
116
+ bpm: "bbl/min",
117
+ "m3/min": "m³/min",
118
+ "m3/s": "m³/s",
119
+ MMSCFD: "MMSCFD",
120
+ bar: "Bar",
121
+ Pa: "Pa",
122
+ kPa: "kPa",
123
+ MPa: "MPa",
124
+ GPa: "GPa",
125
+ kPsi: "Psi",
126
+ ksi: "ksi",
127
+ "lbf/100ft2": "lbf/100ft²",
128
+ "1/Pa": "Pa⁻¹",
129
+ "1/kPa": "kPa⁻¹",
130
+ "1/MPa": "MPa⁻¹",
131
+ "1/GPa": "GPa⁻¹",
132
+ "1/psi": "psi⁻¹",
133
+ "kPa/m": "kPa/m",
134
+ "1/bar": "bar⁻¹",
135
+ klbf: "klbf",
136
+ "psi/ft": "Psi/ft",
137
+ "bar/100m": "bar/100m",
138
+ "psi/100ft": "psi/100ft",
139
+ "kPa/100m": "kPa/100m",
140
+ C: "°C",
141
+ F: "°F",
142
+ K: "K",
143
+ "C/100m": "°C/100m",
144
+ "C/m": "°C/m",
145
+ "Pa/C": "Pa/°C",
146
+ "Bar/C": "Bar/°C",
147
+ "psi/F": "psi/°F",
148
+ "psi/C": "psi/°C",
149
+ "F/100ft": "°F/100ft",
150
+ "F/ft": "°F/ft",
151
+ "K/100m": "K/100m",
152
+ "K/m": "K/m",
153
+ "lbf/ft": "lbf/ft",
154
+ N: "N",
155
+ kN: "kN",
156
+ "N/m": "N/m",
157
+ "daN/m": "daN/m",
158
+ lbf: "lbf",
159
+ kgf: "kgf",
160
+ rad: "rad",
161
+ "BTU/lbm": "BTU/lbm",
162
+ ppf: "ppf",
163
+ "kg/m": "kg/m",
164
+ "E-06/degC": "10⁻⁶/°C",
165
+ "E-06/degF": "10⁻⁶/°F",
166
+ "1/K": "K⁻¹",
167
+ km2: "km²",
168
+ ft2: "ft²",
169
+ mm2: "mm²",
170
+ mile2: "mile²",
171
+ ft3: "ft³",
172
+ "g/cm3": "g/cm³",
173
+ Sm3: "Sm³",
174
+ "ft3/s": "ft³/s",
175
+ "ft3/d": "ft³/d",
176
+ "m3/d": "m³/d",
177
+ "1/m3/d": "1/m³/d",
178
+ "s/m3": "s/m³",
179
+ "1/MMSCFD": "1/MMSCFD",
180
+ "bbl/d": "bbl/d",
181
+ tonneForce: "tonne-force",
182
+ USGal: "US gal",
183
+ "g/mol": "g/mol",
184
+ Nm: "N⋅m",
185
+ kNm: "kN⋅m",
186
+ ftlbf: "ft⋅lbf",
187
+ "J/(kg*degC)": "J/(kg⋅°C)",
188
+ "J/(kg*degK)": "J/(kg⋅K)",
189
+ "J/(s*m*degK)": "J/(s⋅m⋅K)",
190
+ "BTU/(lbm*degF)": "BTU/(lbm⋅°F)",
191
+ "BTU/(h*ft*degF)": "BTU/(h⋅ft⋅°F)",
192
+ l: "L",
193
+ "l/m": "L/m",
194
+ "kJ/kg": "kJ/kg",
195
+ "J/kg": "J/kg",
196
+ deg: "°",
197
+ "W/(mK)": "W/(m⋅K)",
198
+ psi: "psi",
199
+ "deg/100ft": "°/100ft",
200
+ "deg/30m": "°/30m",
201
+ "deg/10m": "°/10m",
202
+ "%": "%",
203
+ Hz: "Hz",
204
+ "1/s": "1/s",
205
+ rpm: "rpm",
206
+ "Pa/m": "Pa/m",
207
+ "bar/m": "bar/m",
208
+ gpm: "gpm",
209
+ "kg/s": "kg/s",
210
+ "lbm/s": "lbm/s",
211
+ "tonnes/h": "tonnes/h",
212
+ "tons/h": "tons/h",
213
+ "deg/m": "°/m",
214
+ "deg/ft": "°/ft",
215
+ "rad/m": "rad/m",
216
+ "rad/ft": "rad/ft",
217
+ "dyn/cm": "dyn/cm",
218
+ "mN/m": "mN/m",
219
+ "m/s": "m/s",
220
+ "ft/s": "ft/s",
221
+ "m/min": "m/min",
222
+ "ft/min": "ft/min",
223
+ "m/h": "m/h",
224
+ "ft/h": "ft/h",
225
+ mph: "mph",
226
+ "km/h": "km/h",
227
+ "m/s2": "m/s²",
228
+ Gs: "Gs",
229
+ nT: "nT",
230
+ g: "g",
231
+ "ft/s2": "ft/s²",
232
+ "Pa*s": "Pa⋅s",
233
+ P: "P",
234
+ "mPa*s": "mPa⋅s",
235
+ cP: "cP",
236
+ W: "W",
237
+ hhp: "hhp",
238
+ hp: "hp",
239
+ kW: "kW",
240
+ MW: "MW",
241
+ "BTU/h": "BTU/h",
242
+ "W/m2": "W/m²",
243
+ "hhp/in2": "hhp/in²",
244
+ "hhp/ft2": "hhp/ft²",
245
+ "Mm3/d": "Mm³/d",
246
+ "STB/d": "STB/d",
247
+ "Sm3/d": "Sm³/d",
248
+ "Sm3/min": "Sm³/min",
249
+ "MSm3/d": "MSm³/d",
250
+ "SCF/STB": "SCF / STB",
251
+ "Sm3/Sm3": "Sm³ / Sm³",
252
+ "SCF/d": "SCF/d",
253
+ STB: "STB",
254
+ SCF: "SCF",
255
+ MSm3: "MSm³",
256
+ Gsg: "sg",
257
+ Gppg: "ppg",
258
+ "Gkg/m3": "kg/m³",
259
+ "Glbm/ft3": "lbm/ft³",
260
+ "lb/ft3": "lb/ft³",
261
+ "°N": "°N",
262
+ "°S": "°S",
263
+ "°W": "°W",
264
+ "°E": "°E",
265
+ fr: " ",
266
+ mD: "mD",
267
+ CI: "CI",
268
+ Sigma: "σ",
269
+ "Sm3/d/bar": "Sm³/d/bar",
270
+ "STB/d/psi": "STB/d/psi",
271
+ "m3/s/bar": "m³/s/bar",
272
+ "lb/ft": "lb/ft",
273
+ "E-09/bar": "10⁻⁹/bar",
274
+ "E-10/psi": "10⁻¹⁰/psi",
275
+ "E-14/pa": "10⁻¹⁴/pa",
276
+ "m3/m": " m³/m",
277
+ "cm3/m": "cm³/m",
278
+ "mm3/m": "mm³/m",
279
+ "ft3/ft": "ft³/ft",
280
+ "in3/ft": "in³/ft",
281
+ lk: "lk",
282
+ ftCla: "ftCla",
283
+ lkCla: "lkCla",
284
+ ftSe: "ftSe",
285
+ ydSe: "ydSe",
286
+ chSe: "chSe",
287
+ "chSe(T)": "chSe(T)",
288
+ ftGC: "ftGC",
289
+ ydInd: "ydInd",
290
+ "d/stand": "d/stand",
291
+ "h/stand": "h/stand",
292
+ "min/stand": "min/stand",
293
+ "s/stand": "s/stand",
294
+ "m3/t": "m3/t",
295
+ "L/100kg": "L/100kg",
296
+ "deg/h": "°/h"
297
+ });
298
+ /**
299
+ * Alternative units grouped by quantity
300
+ *
301
+ * @readonly
302
+ * @enum {Object}
303
+ */
304
+ const ALT_UNITS = Object.freeze({
305
+ acceleration: ["ft/s2", "m/s2"],
306
+ angleGradient: [
307
+ "deg/30m",
308
+ "rad/m",
309
+ "deg/m",
310
+ "deg/ft",
311
+ "rad/ft",
312
+ "deg/100ft",
313
+ "deg/10m"
314
+ ],
315
+ angles: ["deg", "rad"],
316
+ areaOther: [
317
+ "in2",
318
+ "ft2",
319
+ "mm2",
320
+ "cm2",
321
+ "m2",
322
+ "mile2",
323
+ "km2"
324
+ ],
325
+ areaTubular: [
326
+ "in2",
327
+ "cm2",
328
+ "ft2",
329
+ "m2"
330
+ ],
331
+ blowoutFlowRate: [
332
+ "lpm",
333
+ "bpm",
334
+ "m3/min",
335
+ "ft3/s",
336
+ "m3/s",
337
+ "MMSCFD",
338
+ "ft3/d",
339
+ "m3/d",
340
+ "bbl/d",
341
+ "Mm3/d",
342
+ "STB/d",
343
+ "Sm3/d",
344
+ "Sm3/min",
345
+ "MSm3/d",
346
+ "SCF/d"
347
+ ],
348
+ blowoutGasFlowRate: [
349
+ "MMSCFD",
350
+ "Sm3/d",
351
+ "MSm3/d",
352
+ "SCF/d"
353
+ ],
354
+ blowoutOilFlowRate: [
355
+ "Sm3/d",
356
+ "Sm3/min",
357
+ "STB/d"
358
+ ],
359
+ deg: ["deg", "rad"],
360
+ density: [
361
+ "sg",
362
+ "ppg",
363
+ "kg/m3",
364
+ "lbm/ft3",
365
+ "g/cm3",
366
+ "lb/ft3",
367
+ "kPa/m"
368
+ ],
369
+ densityGas: [
370
+ "Gsg",
371
+ "Gppg",
372
+ "Gkg/m3",
373
+ "Glbm/ft3"
374
+ ],
375
+ densityOil: [
376
+ "sg",
377
+ "ppg",
378
+ "kg/m3",
379
+ "lbm/ft3"
380
+ ],
381
+ densityOilGas: [
382
+ "ppg",
383
+ "kg/m3",
384
+ "lbm/ft3"
385
+ ],
386
+ densitySolid: [
387
+ "sg",
388
+ "ppg",
389
+ "kg/m3",
390
+ "lbm/ft3"
391
+ ],
392
+ depth: ["m", "ft"],
393
+ diameters: [
394
+ "in",
395
+ "m",
396
+ "cm",
397
+ "ft",
398
+ "mm"
399
+ ],
400
+ distance: ["m", "ft"],
401
+ dls: [
402
+ "deg/10m",
403
+ "deg/30m",
404
+ "deg/100ft"
405
+ ],
406
+ doglegSeverity: [
407
+ "deg/10m",
408
+ "deg/30m",
409
+ "deg/100ft"
410
+ ],
411
+ duration: [
412
+ "s",
413
+ "h",
414
+ "d",
415
+ "min"
416
+ ],
417
+ durationShort: [
418
+ "s",
419
+ "min",
420
+ "h",
421
+ "d"
422
+ ],
423
+ durationLong: [
424
+ "min",
425
+ "h",
426
+ "d",
427
+ "month",
428
+ "year"
429
+ ],
430
+ flowrate: [
431
+ "lpm",
432
+ "gpm",
433
+ "bpm",
434
+ "ft3/d",
435
+ "ft3/s",
436
+ "m3/s",
437
+ "m3/d",
438
+ "m3/min",
439
+ "Mm3/d",
440
+ "bbl/d",
441
+ "MMSCFD",
442
+ "STB/d",
443
+ "Sm3/d",
444
+ "Sm3/min",
445
+ "MSm3/d",
446
+ "SCF/d"
447
+ ],
448
+ fluidCompressibility: [
449
+ "1/bar",
450
+ "1/psi",
451
+ "1/Pa",
452
+ "1/kPa",
453
+ "1/MPa",
454
+ "1/GPa"
455
+ ],
456
+ force: [
457
+ "tonnes",
458
+ "lbf",
459
+ "kgf",
460
+ "N",
461
+ "kN",
462
+ "tonneForce",
463
+ "klbf"
464
+ ],
465
+ forceGradient: ["lbf/ft", "N/m"],
466
+ frequency: ["Hz"],
467
+ gasVolume: [
468
+ "MMSCF",
469
+ "Sm3",
470
+ "MSm3",
471
+ "SCF"
472
+ ],
473
+ gor: ["Sm3/Sm3", "SCF/STB"],
474
+ height: ["m", "ft"],
475
+ intensity: [
476
+ "W/m2",
477
+ "hhp/in2",
478
+ "hhp/ft2"
479
+ ],
480
+ interfacialTension: [
481
+ "dyn/cm",
482
+ "N/m",
483
+ "lbf/ft",
484
+ "mN/m"
485
+ ],
486
+ latitude: ["°N", "°S"],
487
+ length: [
488
+ "m",
489
+ "cm",
490
+ "ft",
491
+ "km",
492
+ "in",
493
+ "mm"
494
+ ],
495
+ linearCapacity: ["l/m", "bbl/ft"],
496
+ longitude: ["°E", "°W"],
497
+ massFlowRate: [
498
+ "kg/s",
499
+ "lbm/s",
500
+ "tonnes/h",
501
+ "tons/h"
502
+ ],
503
+ moleWeight: [
504
+ "kg/mol",
505
+ "lbf/mol",
506
+ "g/mol"
507
+ ],
508
+ oilVolume: ["STB", "Sm3"],
509
+ percentage: ["%", "fr"],
510
+ permeability: ["mD", "m2"],
511
+ power: [
512
+ "hp",
513
+ "W",
514
+ "hhp",
515
+ "MW",
516
+ "kW",
517
+ "BTU/h"
518
+ ],
519
+ pressure: [
520
+ "bar",
521
+ "psi",
522
+ "Pa",
523
+ "kPa",
524
+ "MPa",
525
+ "ksi",
526
+ "GPa",
527
+ "lbf/100ft2"
528
+ ],
529
+ pressureGradient: [
530
+ "bar/100m",
531
+ "Pa/m",
532
+ "bar/m",
533
+ "psi/100ft",
534
+ "psi/ft",
535
+ "kPa/m"
536
+ ],
537
+ pressurechange: [
538
+ "bar",
539
+ "psi",
540
+ "Pa",
541
+ "MPa",
542
+ "kPa"
543
+ ],
544
+ gasliftFlowRate: [
545
+ "STB/d",
546
+ "Sm3/d",
547
+ "SCF/d"
548
+ ],
549
+ productionFlowRate: [
550
+ "MMSCFD",
551
+ "STB/d",
552
+ "Sm3/d",
553
+ "Sm3/min",
554
+ "MSm3/d",
555
+ "SCF/d"
556
+ ],
557
+ productionFlowRateOil: [
558
+ "MMSCFD",
559
+ "STB/d",
560
+ "Sm3/d",
561
+ "Sm3/min",
562
+ "MSm3/d",
563
+ "SCF/d"
564
+ ],
565
+ productionFlowRateGas: [
566
+ "MMSCFD",
567
+ "STB/d",
568
+ "Sm3/d",
569
+ "MSm3/d",
570
+ "SCF/d"
571
+ ],
572
+ injectionFlowRate: [
573
+ "lpm",
574
+ "lps",
575
+ "bpm",
576
+ "gpm",
577
+ "MMSCFD",
578
+ "STB/d",
579
+ "Sm3/d",
580
+ "Sm3/min",
581
+ "MSm3/d",
582
+ "SCF/d"
583
+ ],
584
+ pumpRate: [
585
+ "lpm",
586
+ "lps",
587
+ "bpm",
588
+ "m3/s",
589
+ "Sm3/min",
590
+ "ft3/s",
591
+ "gpm"
592
+ ],
593
+ rotationalSpeed: ["rpm", "Hz"],
594
+ rotationalRate: ["deg/h"],
595
+ roughness: [
596
+ "m",
597
+ "microM",
598
+ "in",
599
+ "mm"
600
+ ],
601
+ rpm: ["rpm", "Hz"],
602
+ sdstats: ["CI", "Sigma"],
603
+ specificHeatCapacity: [
604
+ "J/(kg*degC)",
605
+ "J/(kg*degK)",
606
+ "BTU/(lbm*degF)"
607
+ ],
608
+ speed: [
609
+ "km/h",
610
+ "ft/min",
611
+ "mph",
612
+ "ft/h",
613
+ "ft/s",
614
+ "m/min",
615
+ "m/s",
616
+ "m/h"
617
+ ],
618
+ inverseStandSpeed: [
619
+ "d/stand",
620
+ "h/stand",
621
+ "min/stand",
622
+ "s/stand"
623
+ ],
624
+ rop: [
625
+ "ft/h",
626
+ "ft/min",
627
+ "ft/s",
628
+ "km/h",
629
+ "m/h",
630
+ "m/min",
631
+ "m/s",
632
+ "mph"
633
+ ],
634
+ stress: [
635
+ "MPa",
636
+ "kPa",
637
+ "psi",
638
+ "bar",
639
+ "Pa",
640
+ "ksi",
641
+ "lbf/100ft2"
642
+ ],
643
+ temperature: [
644
+ "C",
645
+ "F",
646
+ "K"
647
+ ],
648
+ pressurePerTemperature: [
649
+ "Pa/C",
650
+ "Bar/C",
651
+ "psi/F",
652
+ "psi/C"
653
+ ],
654
+ tempgrad: [
655
+ "C/100m",
656
+ "F/100ft",
657
+ "K/100m",
658
+ "C/m",
659
+ "F/ft",
660
+ "K/m"
661
+ ],
662
+ thermalConductivity: ["BTU/(h*ft*degF)", "W/(mK)"],
663
+ thermalExpansionCoefficient: [
664
+ "E-06/degC",
665
+ "E-06/degF",
666
+ "1/K"
667
+ ],
668
+ torque: [
669
+ "Nm",
670
+ "ftlbf",
671
+ "kNm"
672
+ ],
673
+ torqueGradient: [
674
+ "N",
675
+ "lbf",
676
+ "tonnes"
677
+ ],
678
+ turbulentSkin: [
679
+ "s/m3",
680
+ "1/m3/d",
681
+ "1/MMSCFD"
682
+ ],
683
+ viscosity: [
684
+ "Pa*s",
685
+ "P",
686
+ "mPa*s",
687
+ "cP"
688
+ ],
689
+ inflowProductivityIndex: [
690
+ "Sm3/d/bar",
691
+ "STB/d/psi",
692
+ "m3/s/bar"
693
+ ],
694
+ volume: [
695
+ "m3",
696
+ "bbl",
697
+ "Mm3",
698
+ "l",
699
+ "USGal",
700
+ "ft3",
701
+ "STB",
702
+ "Sm3",
703
+ "MMSCF",
704
+ "MSm3",
705
+ "SCF"
706
+ ],
707
+ kickToleranceVolume: [
708
+ "m3",
709
+ "bbl",
710
+ "USGal",
711
+ "ft3",
712
+ "STB",
713
+ "Sm3",
714
+ "SCF"
715
+ ],
716
+ weight: [
717
+ "tonnes",
718
+ "kg",
719
+ "lbf",
720
+ "mt",
721
+ "kip",
722
+ "N"
723
+ ],
724
+ weightGradient: ["ppf", "kg/m"],
725
+ wgrad: ["sg", "ppg"],
726
+ wltubulars: ["ppf", "kg/m"],
727
+ youngsModulus: ["Pa", "psi"],
728
+ massPerLength: ["kg/m", "lb/ft"],
729
+ wearFactor: [
730
+ "E-09/bar",
731
+ "E-10/psi",
732
+ "E-14/pa"
733
+ ],
734
+ volumeGradient: [
735
+ "m3/m",
736
+ "cm3/m",
737
+ "mm3/m",
738
+ "ft3/ft",
739
+ "in3/ft"
740
+ ],
741
+ shearStress: ["Pa", "lbf/100ft2"],
742
+ sensorAccelerometer: ["g", "m/s2"],
743
+ sensorMagnetometer: ["nT", "Gs"],
744
+ location: [
745
+ "lk",
746
+ "ftCla",
747
+ "lkCla",
748
+ "ftSe",
749
+ "ydSe",
750
+ "chSe",
751
+ "chSe(T)",
752
+ "ftGC",
753
+ "ydInd",
754
+ "ft",
755
+ "m",
756
+ "usft"
757
+ ],
758
+ mixingRequirements: ["m3/t", "L/100kg"],
759
+ entalphy: [
760
+ "J/kg",
761
+ "kJ/kg",
762
+ "BTU/lbm"
763
+ ]
764
+ });
765
+ /**
766
+ * Units list
767
+ *
768
+ * @readonly
769
+ * @enum {Object}
770
+ */
771
+ const UNIT_FROM_KEY = Object.freeze({
772
+ density: "sg",
773
+ densityGas: "Gsg",
774
+ densityOil: "sg",
775
+ densityOilGas: "kg/m3",
776
+ densitySolid: "kg/m3",
777
+ length: "m",
778
+ roughness: "m",
779
+ speed: "m/s",
780
+ diameters: "in",
781
+ duration: "s",
782
+ durationShort: "h",
783
+ durationLong: "d",
784
+ pressurechange: "bar",
785
+ pressure: "bar",
786
+ temperature: "C",
787
+ tempgrad: "C/100m",
788
+ volume: "m3",
789
+ kickToleranceVolume: "m3",
790
+ weight: "kg",
791
+ force: "N",
792
+ wgrad: "sg",
793
+ wltubulars: "ppf",
794
+ flowrate: "lpm",
795
+ permeability: "mD",
796
+ interfacialTension: "dyn/cm",
797
+ deg: "deg",
798
+ dls: "deg/30m",
799
+ percentage: "%",
800
+ latitude: "°N",
801
+ longitude: "°E",
802
+ torque: "Nm",
803
+ rpm: "rpm",
804
+ testSingleUnit: "m",
805
+ turbulentSkin: "1/m3/d",
806
+ pressurePerTemperature: "Pa/C",
807
+ sdstats: "Sigma",
808
+ acceleration: "m/s2",
809
+ massFlowRate: "kg/s",
810
+ angleGradient: "deg/m",
811
+ viscosity: "Pa*s",
812
+ weightGradient: "kg/m",
813
+ intensity: "W/m2",
814
+ gor: "Sm3/Sm3",
815
+ inflowProductivityIndex: "Sm3/d/bar",
816
+ wearFactor: "E-09/psi",
817
+ location: "m",
818
+ inverseStandSpeed: "s/stand",
819
+ mixingRequirements: "m3/t",
820
+ entalphy: "J/kg",
821
+ shearStress: "Pa",
822
+ volumeGradient: "m3/m",
823
+ sensorAccelerometer: "g",
824
+ sensorMagnetometer: "Gs",
825
+ rotationalRate: "deg/h"
826
+ });
827
+ /**
828
+ * Constants to help conversion
829
+ *
830
+ * @readonly
831
+ * @enum {Object}
832
+ */
833
+ const C = Object.freeze({
834
+ g: .0980665175317196,
835
+ ft_to_m: .3048,
836
+ inch_to_m: .0254,
837
+ lbf_to_kg: .45359237,
838
+ kg_to_lbf: 2.20462262184877,
839
+ ppf_to_kgm: .45359237 / .3048,
840
+ kg_cm3: .0293984025938081,
841
+ bar_to_psi: 14.503773773022,
842
+ bar_to_pascal: 1e5,
843
+ sg_to_ppg: 8.345404265,
844
+ bbl_to_m3: .158987294928,
845
+ USGal_to_m3: .003785411784,
846
+ kelvin_to_degrees: 273.15,
847
+ tonnes_to_pascal: 9806.65,
848
+ therm_exp_coeff: 1242e-8,
849
+ psi_to_pascal: 6894.757293168361,
850
+ ft3_to_m3: .028316846592,
851
+ ft3_to_in3: 1728,
852
+ day_to_second: 3600 * 24,
853
+ m3_per_m_to_ft3_per_ft: 10.763910416709722,
854
+ in3_per_ft_to_m3_per_m: 537633333333e-16,
855
+ MSm3d_to_m3s: 625 / 54
856
+ });
857
+ /**
858
+ * Conversions list
859
+ *
860
+ * All unit conversion formulas should have a credible source/reference (please add a comment with URL to where you
861
+ * got the formula when adding new units to this package). For example:
862
+ * - Wikipedia
863
+ * - https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors/nist-guide-si-appendix-b8
864
+ * - https://www.wolframalpha.com/input?i=cubic+meter+to+bbl
865
+ *
866
+ * Do not round conversion factors in formulas (we need full precision). Make sure the inverse conversion (A->B->A)
867
+ * produces a valid result.
868
+ *
869
+ * @readonly
870
+ * @enum {Object}
871
+ */
872
+ const KNOWN_CONVERSIONS = Object.freeze({
873
+ "m|mm": (val) => val * 1e3,
874
+ "m|cm": (val) => val * 100,
875
+ "m|km": (val) => val / 1e3,
876
+ "m|ft": (val) => val / C.ft_to_m,
877
+ "m|in": (val) => val / C.inch_to_m,
878
+ "m|microM": (val) => val * 1e6,
879
+ "mm|m": (val) => val / 1e3,
880
+ "cm|m": (val) => val / 100,
881
+ "km|m": (val) => val * 1e3,
882
+ "ft|m": (val) => val * C.ft_to_m,
883
+ "in|m": (val) => val * C.inch_to_m,
884
+ "microM|m": (val) => val / 1e6,
885
+ "m2|mm2": (val) => val * 1e6,
886
+ "m2|cm2": (val) => val * 1e4,
887
+ "m2|km2": (val) => val / 1e6,
888
+ "m2|in2": (val) => val * 1550.0031,
889
+ "m2|ft2": (val) => val * 10.76391,
890
+ "m2|mile2": (val) => val * 3.861022e-7,
891
+ "mm2|m2": (val) => val / 1e6,
892
+ "cm2|m2": (val) => val / 1e4,
893
+ "km2|m2": (val) => val * 1e6,
894
+ "in2|m2": (val) => val / 1550.0031,
895
+ "ft2|m2": (val) => val / 10.76391,
896
+ "mile2|m2": (val) => val / 3.861022e-7,
897
+ "m3|bbl": (val) => val / C.bbl_to_m3,
898
+ "m3|ft3": (val) => val / C.ft3_to_m3,
899
+ "m3|l": (val) => val * 1e3,
900
+ "m3|Mm3": (val) => val / 1e6,
901
+ "m3|USGal": (val) => val / C.USGal_to_m3,
902
+ "bbl|m3": (val) => val * C.bbl_to_m3,
903
+ "ft3|m3": (val) => val * C.ft3_to_m3,
904
+ "Mm3|m3": (val) => val * 1e6,
905
+ "l|m3": (val) => val / 1e3,
906
+ "USGal|m3": (val) => val * C.USGal_to_m3,
907
+ "m3|Sm3": (val) => val * 1,
908
+ "m3|STB": (val) => val * 6.289512957422142,
909
+ "Sm3|m3": (val) => val * 1,
910
+ "STB|m3": (val) => val * .1589948230919721,
911
+ "m3|MMSCF": (val) => val * 1e6 / C.ft3_to_m3,
912
+ "m3|MSm3": (val) => val * 1e-6,
913
+ "m3|SCF": (val) => val / C.ft3_to_m3,
914
+ "MMSCF|m3": (val) => val * 1e-6 * C.ft3_to_m3,
915
+ "MSm3|m3": (val) => val * 1e6,
916
+ "SCF|m3": (val) => val * C.ft3_to_m3,
917
+ "kg/m3|sg": (val) => val * .001,
918
+ "kg/m3|g/cm3": (val) => val * .001,
919
+ "kg/m3|lbm/ft3": (val) => val / 16.01846337,
920
+ "kg/m3|lb/ft3": (val) => val / 16.01846337,
921
+ "kg/m3|ppg": (val) => val * .008345404265,
922
+ "sg|kg/m3": (val) => val * 1e3,
923
+ "g/cm3|kg/m3": (val) => val * 1e3,
924
+ "lbm/ft3|kg/m3": (val) => val * 16.01846337,
925
+ "lb/ft3|kg/m3": (val) => val * 16.01846337,
926
+ "ppg|kg/m3": (val) => val / .008345404265,
927
+ "sg|kPa/m": (val) => val * 9.81,
928
+ "kPa/m|sg": (val) => val / 9.81,
929
+ "Gkg/m3|Gsg": (val) => val / 1.225,
930
+ "Gkg/m3|Glbm/ft3": (val) => val / 16.0176516725,
931
+ "Gkg/m3|Gppg": (val) => val / 119.8659491193,
932
+ "Gsg|Gkg/m3": (val) => val * 1.225,
933
+ "Glbm/ft3|Gkg/m3": (val) => val * 16.0176516725,
934
+ "Gppg|Gkg/m3": (val) => val * 119.8659491193,
935
+ "ppf|kg/m": (val) => val * .45359237 / .3048,
936
+ "kg/m|ppf": (val) => val * 1 / (.45359237 / .3048),
937
+ "kg/m|lbf/ft": (val) => val / .67196897675131,
938
+ "lbf/ft|kg/m": (val) => val * .67196897675131,
939
+ "Pa|psi": (val) => val / C.psi_to_pascal,
940
+ "psi|Pa": (val) => val * C.psi_to_pascal,
941
+ "Pa|bar": (val) => val * 1e-5,
942
+ "Pa|kPa": (val) => val * .001,
943
+ "Pa|MPa": (val) => val * 1e-6,
944
+ "Pa|GPa": (val) => val * 1e-9,
945
+ "bar|Pa": (val) => val * 1e5,
946
+ "kPa|Pa": (val) => val * 1e3,
947
+ "MPa|Pa": (val) => val * 1e6,
948
+ "GPa|Pa": (val) => val * 1e9,
949
+ "psi|ksi": (val) => val / 1e3,
950
+ "ksi|psi": (val) => val * 1e3,
951
+ "psi|lbf/100ft2": (val) => val * 14400,
952
+ "lbf/100ft2|psi": (val) => val / 14400,
953
+ "1/psi|1/Pa": (val) => val / C.psi_to_pascal,
954
+ "1/bar|1/Pa": (val) => val * 1e-5,
955
+ "1/kPa|1/Pa": (val) => val * .001,
956
+ "1/MPa|1/Pa": (val) => val * 1e-6,
957
+ "1/GPa|1/Pa": (val) => val * 1e-9,
958
+ "1/Pa|1/psi": (val) => val * C.psi_to_pascal,
959
+ "1/Pa|1/bar": (val) => val * 1e5,
960
+ "1/Pa|1/kPa": (val) => val * 1e3,
961
+ "1/Pa|1/MPa": (val) => val * 1e6,
962
+ "1/Pa|1/GPa": (val) => val * 1e9,
963
+ "C|F": (val) => val * 1.8 + 32,
964
+ "F|C": (val) => (val - 32) * 5 / 9,
965
+ "K|C": (val) => val - C.kelvin_to_degrees,
966
+ "C|K": (val) => val + C.kelvin_to_degrees,
967
+ "C/100m|F/100ft": (val) => val * 1.8 * C.ft_to_m,
968
+ "F/100ft|C/100m": (val) => val * 5 / 9 / C.ft_to_m,
969
+ "C/100m|C/m": (val) => val / 100,
970
+ "C/m|C/100m": (val) => val * 100,
971
+ "C/100m|F/ft": (val) => val * 1.8 / 100 * C.ft_to_m,
972
+ "F/ft|C/100m": (val) => val * 5 / 9 * 100 / C.ft_to_m,
973
+ "C/100m|K/m": (val) => val / 100,
974
+ "K/m|C/100m": (val) => val * 100,
975
+ "K/100m|C/100m": (val) => val,
976
+ "C/100m|K/100m": (val) => val,
977
+ "Pa/C|Bar/C": (val) => val * 1e-5,
978
+ "Pa/C|psi/F": (val) => val / 1.8 / C.psi_to_pascal,
979
+ "Pa/C|psi/C": (val) => val / C.psi_to_pascal,
980
+ "Bar/C|Pa/C": (val) => val * 1e5,
981
+ "psi/F|Pa/C": (val) => val * 1.8 * C.psi_to_pascal,
982
+ "psi/C|Pa/C": (val) => val * C.psi_to_pascal,
983
+ "psi/F|psi/C": (val) => val * 1.8,
984
+ "psi/C|psi/F": (val) => val / 1.8,
985
+ "kg|kgf": (val) => val,
986
+ "kg|lbf": (val) => val * C.kg_to_lbf,
987
+ "kg|t": (val) => val / 1e3,
988
+ "kg|tonnes": (val) => val / 1e3,
989
+ "kg|mt": (val) => val / 1e3,
990
+ "kg|kip": (val) => val * C.kg_to_lbf * .001,
991
+ "kgf|kg": (val) => val,
992
+ "lbf|kg": (val) => val * C.lbf_to_kg,
993
+ "t|kg": (val) => val * 1e3,
994
+ "tonnes|kg": (val) => val * 1e3,
995
+ "mt|kg": (val) => val * 1e3,
996
+ "kip|kg": (val) => val * 1e3 * C.lbf_to_kg,
997
+ "tonnes|lbf": (val) => val * 1e3 * C.kg_to_lbf,
998
+ "lbf|tonnes": (val) => val * C.lbf_to_kg / 1e3,
999
+ "t|lbf": (val) => val * 1e3 * C.kg_to_lbf,
1000
+ "lbf|t": (val) => val * C.lbf_to_kg / 1e3,
1001
+ "mt|lbf": (val) => val * 1e3 * C.kg_to_lbf,
1002
+ "lbf|mt": (val) => val / (1e3 * C.kg_to_lbf),
1003
+ "kgf|lbf": (val) => val * C.kg_to_lbf,
1004
+ "lbf|kgf": (val) => val * C.lbf_to_kg,
1005
+ "kg|g": (val) => val * 1e3,
1006
+ "g|kg": (val) => val / 1e3,
1007
+ "kgf|t": (val) => val / 1e3,
1008
+ "t|kgf": (val) => val * 1e3,
1009
+ "kgf|tonnes": (val) => val / 1e3,
1010
+ "tonnes|kgf": (val) => val * 1e3,
1011
+ "kg/m|lb/ft": (val) => val * 1.4881639435695537,
1012
+ "lb/ft|kg/m": (val) => val * .6719689751395069,
1013
+ "kg|N": (val) => val * C.g * 100,
1014
+ "N|kg": (val) => val / (C.g * 100),
1015
+ "m/s|km/h": (val) => val * 3.6,
1016
+ "km/h|m/s": (val) => val / 3.6,
1017
+ "m/s|ft/s": (val) => val / C.ft_to_m,
1018
+ "m/s|ft/min": (val) => val * 60 / C.ft_to_m,
1019
+ "m/s|ft/h": (val) => val * 3600 / C.ft_to_m,
1020
+ "m/s|m/min": (val) => val * 60,
1021
+ "m/s|m/h": (val) => val * 3600,
1022
+ "ft/s|m/s": (val) => val * C.ft_to_m,
1023
+ "ft/min|m/s": (val) => val * C.ft_to_m / 60,
1024
+ "ft/h|m/s": (val) => val * C.ft_to_m / 3600,
1025
+ "m/min|m/s": (val) => val / 60,
1026
+ "m/h|m/s": (val) => val / 3600,
1027
+ "m/s|mph": (val) => val * 2.2369362920544,
1028
+ "mph|m/s": (val) => val / 2.2369362920544,
1029
+ "ft/h|ft/d": (val) => val * 24,
1030
+ "ft/d|ft/h": (val) => val / 24,
1031
+ "ft/h|m/h": (val) => val * C.ft_to_m,
1032
+ "m/h|ft/h": (val) => val / C.ft_to_m,
1033
+ "ft/d|m/h": (val) => val * C.ft_to_m / 24,
1034
+ "m/h|ft/d": (val) => val * 24 / C.ft_to_m,
1035
+ "ft/d|m/d": (val) => val * C.ft_to_m,
1036
+ "m/d|ft/d": (val) => val / C.ft_to_m,
1037
+ "m/h|m/d": (val) => val * 24,
1038
+ "m/d|m/h": (val) => val / 24,
1039
+ "l/m|bbl/ft": (val) => val * .0019171343228277056,
1040
+ "bbl/ft|l/m": (val) => val / .0019171343228277056,
1041
+ "m3/s|ft3/s": (val) => val / C.ft3_to_m3,
1042
+ "m3/s|lpm": (val) => val * 6e4,
1043
+ "m3/s|bpm": (val) => val * 377.388646,
1044
+ "m3/s|m3/min": (val) => val * 60,
1045
+ "m3/s|m3/d": (val) => val * C.day_to_second,
1046
+ "m3/s|bbl/d": (val) => val * 543439.6505653338,
1047
+ "m3/s|ft3/d": (val) => val * C.day_to_second / C.ft3_to_m3,
1048
+ "m3/s|gpm": (val) => val * 25e11 / 157725491,
1049
+ "m3/s|MMSCFD": (val) => val / .32774128,
1050
+ "m3/s|STB/d": (val) => val * 0x7a7f6097db00 / 247854343,
1051
+ "m3/s|Sm3/d": (val) => val * C.day_to_second,
1052
+ "m3/s|Sm3/min": (val) => val * 60,
1053
+ "Sm3/min|m3/s": (val) => val / 60,
1054
+ "m3/s|MSm3/d": (val) => val / C.MSm3d_to_m3s,
1055
+ "m3/s|SCF/d": (val) => val * 3051187.2047366146,
1056
+ "ft3/s|m3/s": (val) => val * C.ft3_to_m3,
1057
+ "lpm|m3/s": (val) => val / 6e4,
1058
+ "lps|lpm": (val) => val * 60,
1059
+ "lpm|lps": (val) => val / 60,
1060
+ "bpm|m3/s": (val) => val / 377.388646,
1061
+ "m3/d|m3/s": (val) => val / C.day_to_second,
1062
+ "m3/min|m3/s": (val) => val / 60,
1063
+ "bbl/d|m3/s": (val) => val / C.day_to_second * C.bbl_to_m3,
1064
+ "ft3/d|m3/s": (val) => val / C.day_to_second * C.ft3_to_m3,
1065
+ "ft3/d|m3/d": (val) => val * C.ft3_to_m3,
1066
+ "m3/d|ft3/d": (val) => val / C.ft3_to_m3,
1067
+ "m3/d|ft3/s": (val) => val / C.ft3_to_m3 / C.day_to_second,
1068
+ "gpm|m3/s": (val) => val * 157725491 / 25e11,
1069
+ "MMSCFD|m3/s": (val) => val * .32774128,
1070
+ "Mm3/d|m3/d": (val) => val * 1e6,
1071
+ "m3/d|Mm3/d": (val) => val * 1e-6,
1072
+ "STB/d|m3/s": (val) => val * 184021785986e-17,
1073
+ "Sm3/d|m3/d": (val) => val,
1074
+ "m3/d|Sm3/d": (val) => val,
1075
+ "Sm3/d|m3/s": (val) => val / C.day_to_second,
1076
+ "MSm3/d|Sm3/d": (val) => val * 1e6,
1077
+ "Sm3/d|MSm3/d": (val) => val * 1e-6,
1078
+ "MSm3/d|m3/s": (val) => val * C.MSm3d_to_m3s,
1079
+ "SCF/d|m3/s": (val) => val * 3.2774128e-7,
1080
+ "1/m3/d|1/MMSCFD": (val) => val * 28316.85,
1081
+ "1/MMSCFD|1/m3/d": (val) => val / 28316.85,
1082
+ "s/m3|1/m3/d": (val) => val / 86400,
1083
+ "1/m3/d|s/m3": (val) => val * 86400,
1084
+ "kg/s|lbm/s": (val) => val * 2.20462262,
1085
+ "lbm/s|kg/s": (val) => val / 2.20462262,
1086
+ "kg/s|tonnes/h": (val) => val * 3.6,
1087
+ "tonnes/h|kg/s": (val) => val / 3.6,
1088
+ "kg/s|tons/h": (val) => val * 3.9683207193277967,
1089
+ "tons/h|kg/s": (val) => val * .2519957611111111,
1090
+ "lbm/s|tonnes/h": (val) => val * 1.632932532,
1091
+ "tonnes/h|lbm/s": (val) => val * .612395172735771,
1092
+ "lbm/s|tons/h": (val) => val * 1.8,
1093
+ "tons/h|lbm/s": (val) => val / 1.8,
1094
+ "tonnes/h|tons/h": (val) => val * 1.1023113109243878,
1095
+ "tons/h|tonnes/h": (val) => val * .90718474,
1096
+ "mD|m2": (val) => val * 9869233e-19,
1097
+ "m2|mD": (val) => val / 9869233e-19,
1098
+ "N/m|lbf/ft": (val) => val * .22480894387096 * C.ft_to_m,
1099
+ "lbf/ft|N/m": (val) => val / .22480894387096 / C.ft_to_m,
1100
+ "dyn/cm|mN/m": (val) => val,
1101
+ "mN/m|dyn/cm": (val) => val,
1102
+ "dyn/cm|N/m": (val) => val * .001,
1103
+ "N/m|dyn/cm": (val) => val * 1e3,
1104
+ "mN/m|N/m": (val) => val * .001,
1105
+ "N/m|mN/m": (val) => val * 1e3,
1106
+ "Nm|ftlbf": (val) => val * .737562058700684,
1107
+ "Nm|kNm": (val) => val / 1e3,
1108
+ "kNm|Nm": (val) => val * 1e3,
1109
+ "ftlbf|Nm": (val) => val / .737562058700684,
1110
+ "N|kN": (val) => val * .001,
1111
+ "N|kgf": (val) => val * 2e4 / 196133,
1112
+ "N|lbf": (val) => val * 2e12 / 8896443230521,
1113
+ "kN|lbf": (val) => val * 1e3 * 2e12 / 8896443230521,
1114
+ "N|tonneForce": (val) => val * 20 / 196133,
1115
+ "kN|N": (val) => val / .001,
1116
+ "kgf|N": (val) => val * 196133 / 2e4,
1117
+ "lbf|N": (val) => val * 8896443230521 / 2e12,
1118
+ "lbf|kN": (val) => val * 8896443230521 / (2e12 * 1e3),
1119
+ "lbf|tonneForce": (val) => val * 45359237 / 1e11,
1120
+ "klbf|tonneForce": (val) => val * 45359237 / (1e11 * .001),
1121
+ "tonneForce|N": (val) => val * 196133 / 20,
1122
+ "tonneForce|lbf": (val) => val * 1e11 / 45359237,
1123
+ "tonneForce|klbf": (val) => val * 1e11 / (45359237 * 1e3),
1124
+ "klbf|lbf": (val) => val * 1e3,
1125
+ "lbf|klbf": (val) => val / 1e3,
1126
+ "s|min": (val) => val / 60,
1127
+ "s|h": (val) => val / 3600,
1128
+ "s|d": (val) => val / (24 * 3600),
1129
+ "min|s": (val) => val * 60,
1130
+ "h|s": (val) => val * 3600,
1131
+ "d|s": (val) => val * 24 * 3600,
1132
+ "year|d": (val) => val * 365.25,
1133
+ "d|year": (val) => val / 365.25,
1134
+ "year|month": (val) => val * 12,
1135
+ "month|year": (val) => val / 12,
1136
+ "month|d": (val) => val * 30.4375,
1137
+ "d|month": (val) => val / 30.4375,
1138
+ "s/stand|min/stand": (val) => val / 60,
1139
+ "s/stand|h/stand": (val) => val / 3600,
1140
+ "s/stand|d/stand": (val) => val / 86400,
1141
+ "min/stand|s/stand": (val) => val * 60,
1142
+ "h/stand|s/stand": (val) => val * 3600,
1143
+ "d/stand|s/stand": (val) => val * 86400,
1144
+ "min/stand|h/stand": (val) => val / 60,
1145
+ "min/stand|d/stand": (val) => val / 1440,
1146
+ "h/stand|min/stand": (val) => val * 60,
1147
+ "h/stand|d/stand": (val) => val / 24,
1148
+ "d/stand|min/stand": (val) => val * 1440,
1149
+ "d/stand|h/stand": (val) => val * 24,
1150
+ "%|fr": (val) => val * .01,
1151
+ "fr|%": (val) => val / .01,
1152
+ "deg|rad": (val) => val * Math.PI / 180,
1153
+ "rad|deg": (val) => val * 180 / Math.PI,
1154
+ "W|hp": (val) => val / 745.699872,
1155
+ "hp|W": (val) => val * 745.699872,
1156
+ "W|kW": (val) => val / 1e3,
1157
+ "W|MW": (val) => val / 1e6,
1158
+ "kW|W": (val) => val * 1e3,
1159
+ "MW|W": (val) => val * 1e6,
1160
+ "W|BTU/h": (val) => val * 3.4121416351331,
1161
+ "BTU/h|W": (val) => val / 3.4121416351331,
1162
+ "hhp|hp": (val) => val,
1163
+ "hp|hhp": (val) => val,
1164
+ "°N|°S": (val) => val,
1165
+ "°S|°N": (val) => val,
1166
+ "°W|°E": (val) => val,
1167
+ "°E|°W": (val) => val,
1168
+ "BTU/(Kg*K)|BTU/(lbm*degF)": (val) => val / 4186.798188,
1169
+ "BTU/(lbm*degF)|J/(kg*degC)": (val) => val * 4186.798188,
1170
+ "BTU/(lbm*degF)|BTU/(Kg*K)": (val) => val * 4186.798188,
1171
+ "J/(kg*degK)|J/(kg*degC)": (val) => val,
1172
+ "J/(kg*degC)|BTU/(lbm*degF)": (val) => val / 4186.798188,
1173
+ "J/(kg*degC)|J/(kg*degK)": (val) => val,
1174
+ "J/(kg*degC)|J/(s*m*degK)": (val) => val,
1175
+ "BTU/(h*ft*degF)|W/(mK)": (val) => val * 1.7295772056,
1176
+ "BTU/(h*ft*degF)|J/(s*m*degK)": (val) => val * 1.7295772056,
1177
+ "W/(mK)|BTU/(h*ft*degF)": (val) => val / 1.7295772056,
1178
+ "W/(mK)|J/(s*m*degK)": (val) => val,
1179
+ "W/(m*degK)|J/(s*m*degK)": (val) => val,
1180
+ "W/(m*degK)|BTU/(h*ft*degF)": (val) => val / 1.7295772056,
1181
+ "J/(s*m*degK)|BTU/(h*ft*degF)": (val) => val / 1.7295772056,
1182
+ "J/(s*m*degK)|W/(m*degK)": (val) => val,
1183
+ "J/(s*m*degK)|W/(mK)": (val) => val,
1184
+ "J/(s*m*degK)|J/(kg*degC)": (val) => val,
1185
+ "E-06/degF|E-06/degC": (val) => val * 1.8,
1186
+ "E-06/degC|E-06/degF": (val) => val / 1.8,
1187
+ "E-06/degC|1/K": (val) => val / 1e6,
1188
+ "1/K|E-06/degC": (val) => val * 1e6,
1189
+ "rpm|Hz": (val) => val / 60,
1190
+ "Hz|rpm": (val) => val * 60,
1191
+ "CI|Sigma": (val) => get_k_from_conf_int(val),
1192
+ "Sigma|CI": (val) => get_conf_int_from_k(val),
1193
+ "g/mol|kg/mol": (val) => val / 1e3,
1194
+ "kg/mol|g/mol": (val) => val * 1e3,
1195
+ "lbf/mol|kg/mol": (val) => val / C.kg_to_lbf,
1196
+ "kg/mol|lbf/mol": (val) => val * C.kg_to_lbf,
1197
+ "m/s2|ft/s2": (val) => val / C.ft_to_m,
1198
+ "ft/s2|m/s2": (val) => val * C.ft_to_m,
1199
+ "Pa*s|P": (val) => val * 10,
1200
+ "P|Pa*s": (val) => val / 10,
1201
+ "mPa*s|Pa*s": (val) => val / 1e3,
1202
+ "Pa*s|mPa*s": (val) => val * 1e3,
1203
+ "cP|Pa*s": (val) => val * .001,
1204
+ "Pa*s|cP": (val) => val / .001,
1205
+ "Pa/m|bar/m": (val) => val * 1e-5,
1206
+ "bar/m|Pa/m": (val) => val * 1e5,
1207
+ "Pa/m|kPa/m": (val) => val / 1e3,
1208
+ "kPa/m|Pa/m": (val) => val * 1e3,
1209
+ "Pa/m|bar/100m": (val) => val * .001,
1210
+ "bar/100m|Pa/m": (val) => val * 1e3,
1211
+ "bar/m|bar/100m": (val) => val * 100,
1212
+ "bar/100m|bar/m": (val) => val / 100,
1213
+ "psi/ft|Pa/m": (val) => val * C.psi_to_pascal / C.ft_to_m,
1214
+ "Pa/m|psi/ft": (val) => val / C.psi_to_pascal * C.ft_to_m,
1215
+ "psi/100ft|Pa/m": (val) => val * 68.9475729 / C.ft_to_m,
1216
+ "Pa/m|psi/100ft": (val) => val / 68.9475729 * C.ft_to_m,
1217
+ "deg/30m|deg/100ft": (val) => val * (100 * C.ft_to_m / 30),
1218
+ "deg/100ft|deg/30m": (val) => val / (100 * C.ft_to_m / 30),
1219
+ "deg/30m|deg/m": (val) => val / 30,
1220
+ "deg/m|deg/30m": (val) => val * 30,
1221
+ "deg/100ft|deg/ft": (val) => val / 100,
1222
+ "deg/ft|deg/100ft": (val) => val * 100,
1223
+ "deg/100ft|deg/m": (val) => val / (100 * C.ft_to_m),
1224
+ "deg/m|deg/100ft": (val) => val * (100 * C.ft_to_m),
1225
+ "deg/ft|deg/m": (val) => val / C.ft_to_m,
1226
+ "deg/m|deg/ft": (val) => val * C.ft_to_m,
1227
+ "deg/m|rad/m": (val) => val * Math.PI / 180,
1228
+ "rad/m|deg/m": (val) => val * 180 / Math.PI,
1229
+ "rad/ft|deg/m": (val) => val * 180 / Math.PI / C.ft_to_m,
1230
+ "deg/m|rad/ft": (val) => val * Math.PI / 180 * C.ft_to_m,
1231
+ "deg/10m|deg/100ft": (val) => val * (10 * C.ft_to_m),
1232
+ "deg/100ft|deg/10m": (val) => val / (10 * C.ft_to_m),
1233
+ "deg/10m|deg/m": (val) => val / 10,
1234
+ "deg/m|deg/10m": (val) => val * 10,
1235
+ "deg/30m|deg/10m": (val) => val / 3,
1236
+ "deg/10m|deg/30m": (val) => val * 3,
1237
+ "deg/10m|rad/m": (val) => val * Math.PI / 180 / 10,
1238
+ "rad/m|deg/10m": (val) => val * 180 / Math.PI * 10,
1239
+ "W/m2|hhp/in2": (val) => val * (1 / 745.699872 / 1550.0031),
1240
+ "W/m2|hhp/ft2": (val) => val * (1 / 745.699872 / 10.76391),
1241
+ "hhp/in2|W/m2": (val) => val / (1 / 745.699872 / 1550.0031),
1242
+ "hhp/ft2|W/m2": (val) => val / (1 / 745.699872 / 10.76391),
1243
+ "SCF/STB|Sm3/Sm3": (val) => val * .178099173553719,
1244
+ "Sm3/Sm3|SCF/STB": (val) => val * 5.614849187935035,
1245
+ "Sm3/d/bar|m3/s/bar": (val) => val / 86400,
1246
+ "STB/d/psi|m3/s/bar": (val) => val / 37468.77736,
1247
+ "m3/s/bar|Sm3/d/bar": (val) => val * 86400,
1248
+ "m3/s/bar|STB/d/psi": (val) => val * 37468.77736,
1249
+ "E-10/psi|E-09/bar": (val) => val * 1.450377378,
1250
+ "E-10/psi|E-14/pa": (val) => val * 1.450377378,
1251
+ "E-14/pa|E-10/psi": (val) => val / 1.450377378,
1252
+ "E-09/bar|E-10/psi": (val) => val / 1.450377378,
1253
+ "E-14/pa|1/Pa": (val) => val / Math.pow(10, 14),
1254
+ "E-09/bar|1/bar": (val) => val / Math.pow(10, 9),
1255
+ "E-10/psi|1/psi": (val) => val / Math.pow(10, 10),
1256
+ "1/Pa|E-14/pa": (val) => val * Math.pow(10, 14),
1257
+ "1/bar|E-09/bar": (val) => val * Math.pow(10, 9),
1258
+ "1/psi|E-10/psi": (val) => val * Math.pow(10, 10),
1259
+ "m3/m|cm3/m": (val) => val * 10 ** 6,
1260
+ "m3/m|mm3/m": (val) => val * 10 ** 9,
1261
+ "m3/m|ft3/ft": (val) => val * C.m3_per_m_to_ft3_per_ft,
1262
+ "m3/m|in3/ft": (val) => val * C.m3_per_m_to_ft3_per_ft * C.ft3_to_in3,
1263
+ "cm3/m|m3/m": (val) => val * 1e-6,
1264
+ "cm3/m|mm3/m": (val) => val * 1e3,
1265
+ "cm3/m|ft3/ft": (val) => val * C.m3_per_m_to_ft3_per_ft * 1e-6,
1266
+ "cm3/m|in3/ft": (val) => val * C.m3_per_m_to_ft3_per_ft * 1e-6 * C.ft3_to_in3,
1267
+ "mm3/m|m3/m": (val) => val * 1e-9,
1268
+ "mm3/m|cm3/m": (val) => val * .001,
1269
+ "mm3/m|ft3/ft": (val) => val * C.m3_per_m_to_ft3_per_ft * 1e-9,
1270
+ "mm3/m|in3/ft": (val) => val * C.m3_per_m_to_ft3_per_ft * 1e-9 * C.ft3_to_in3,
1271
+ "ft3/ft|m3/m": (val) => val * .09290304,
1272
+ "ft3/ft|cm3/m": (val) => val * 92903.04,
1273
+ "ft3/ft|mm3/m": (val) => val * 92903040,
1274
+ "ft3/ft|in3/ft": (val) => val * 1728,
1275
+ "in3/ft|m3/m": (val) => val * C.in3_per_ft_to_m3_per_m,
1276
+ "in3/ft|cm3/m": (val) => val * C.in3_per_ft_to_m3_per_m * 1e6,
1277
+ "in3/ft|mm3/m": (val) => val * C.in3_per_ft_to_m3_per_m * 1e9,
1278
+ "in3/ft|ft3/ft": (val) => val / C.ft3_to_in3,
1279
+ "Pa|lbf/100ft2": (val) => val * 2.088543423315013,
1280
+ "lbf/100ft2|Pa": (val) => val * .4788025898033584,
1281
+ "usft|m": (val) => val * .30480060960121924,
1282
+ "lk|m": (val) => val * .201168,
1283
+ "ftCla|m": (val) => val * .3047972651151,
1284
+ "lkCla|m": (val) => val * .2011057269733667,
1285
+ "ftGC|m": (val) => val * .30479971018150875,
1286
+ "ydInd|m": (val) => val * .9143985307444408,
1287
+ "ftSe|m": (val) => val * (12 / 39.370147),
1288
+ "ydSe|m": (val) => val * .9143991154275526,
1289
+ "chSe|m": (val) => val * 20.11676512155263,
1290
+ "chSe(T)|m": (val) => val * 20.116756,
1291
+ "m|usft": (val) => val / .30480060960121924,
1292
+ "m|lk": (val) => val / .201168,
1293
+ "m|ftCla": (val) => val / .3047972651151,
1294
+ "m|lkCla": (val) => val / .2011057269733667,
1295
+ "m|ftGC": (val) => val / .30479971018150875,
1296
+ "m|ydInd": (val) => val / .9143985307444408,
1297
+ "m|ftSe": (val) => val / (12 / 39.370147),
1298
+ "m|ydSe": (val) => val / .9143991154275526,
1299
+ "m|chSe": (val) => val / 20.11676512155263,
1300
+ "m|chSe(T)": (val) => val / 20.116756,
1301
+ "m3/t|L/100kg": (val) => val * 100,
1302
+ "L/100kg|m3/t": (val) => val * .01,
1303
+ "kJ/kg|J/kg": (val) => val * 1e3,
1304
+ "J/kg|kJ/kg": (val) => val / 1e3,
1305
+ "BTU/lbm|J/kg": (val) => val * 2326,
1306
+ "J/kg|BTU/lbm": (val) => val / 2326,
1307
+ "g|m/s2": (val) => val * 9.81,
1308
+ "m/s2|g": (val) => val / 9.81,
1309
+ "Gs|nT": (val) => val * 1e5,
1310
+ "nT|Gs": (val) => val / 1e5
1311
+ });
1312
+ /**
1313
+ * Deprecated units
1314
+ *
1315
+ * @readonly
1316
+ * @enum {Object}
1317
+ */
1318
+ const DEPRECATED_UNITS = Object.freeze({
1319
+ "N-m": "Nm",
1320
+ "ft-lbf": "ftlbf",
1321
+ "BTU/hr": "BTU/h",
1322
+ "BTU/(htf*degF)": "BTU/(h*ft*degF)",
1323
+ "BTU/(hft*degF)": "BTU/(h*ft*degF)"
1324
+ });
1325
+ /**
1326
+ * This list is mapping from legal alternative unit names to our selected unit name
1327
+ *
1328
+ * @readonly
1329
+ * @enum {Object}
1330
+ */
1331
+ const UNIT_ALIASES = Object.freeze({
1332
+ "lbs/ft": "lb/ft",
1333
+ "lbm/ft": "lb/ft",
1334
+ ftUS: "usft"
1335
+ });
1336
+ /**
1337
+ * Intermediate conversions
1338
+ *
1339
+ * @readonly
1340
+ * @enum {Object}
1341
+ */
1342
+ const INTERMEDIATE_CONVERSIONS = Object.freeze({
1343
+ mm: "m",
1344
+ cm: "m",
1345
+ km: "m",
1346
+ ft: "m",
1347
+ in: "m",
1348
+ microM: "m",
1349
+ lbf: "kg",
1350
+ t: "kg",
1351
+ tonnes: "kg",
1352
+ mt: "kg",
1353
+ kip: "kg",
1354
+ kW: "W",
1355
+ MW: "W",
1356
+ hp: "W",
1357
+ hhp: "hp",
1358
+ mm2: "m2",
1359
+ cm2: "m2",
1360
+ km2: "m2",
1361
+ in2: "m2",
1362
+ ft2: "m2",
1363
+ mile2: "m2",
1364
+ bbl: "m3",
1365
+ ft3: "m3",
1366
+ Mm3: "m3",
1367
+ l: "m3",
1368
+ USGal: "m3",
1369
+ Sm3: "m3",
1370
+ STB: "m3",
1371
+ MMSCF: "m3",
1372
+ MSm3: "m3",
1373
+ SCF: "m3",
1374
+ kN: "N",
1375
+ kgf: "N",
1376
+ tonneForce: "N",
1377
+ klbf: "lbf",
1378
+ psi: "Pa",
1379
+ bar: "Pa",
1380
+ kPa: "Pa",
1381
+ MPa: "Pa",
1382
+ ksi: "psi",
1383
+ "lbf/100ft2": "psi",
1384
+ "psi/100ft": "Pa/m",
1385
+ "psi/ft": "Pa/m",
1386
+ "bar/100m": "Pa/m",
1387
+ "bar/m": "Pa/m",
1388
+ "Pa/m": "kPa/m",
1389
+ sg: "kg/m3",
1390
+ "g/cm3": "kg/m3",
1391
+ "lbm/ft3": "kg/m3",
1392
+ "lb/ft3": "kg/m3",
1393
+ ppg: "kg/m3",
1394
+ "kPa/m": "sg",
1395
+ Gsg: "Gkg/m3",
1396
+ Gppg: "Gkg/m3",
1397
+ "Glbm/ft3": "Gkg/m3",
1398
+ "1/psi": "1/Pa",
1399
+ "1/bar": "1/Pa",
1400
+ "1/kPa": "1/Pa",
1401
+ "1/MPa": "1/Pa",
1402
+ "1/GPa": "1/Pa",
1403
+ "ft/s": "m/s",
1404
+ "ft/min": "m/s",
1405
+ "ft/h": "m/s",
1406
+ "m/min": "m/s",
1407
+ "m/h": "m/s",
1408
+ mph: "m/s",
1409
+ "ft3/s": "m3/s",
1410
+ lpm: "m3/s",
1411
+ lps: "lpm",
1412
+ bpm: "m3/s",
1413
+ "m3/d": "m3/s",
1414
+ "bbl/d": "m3/s",
1415
+ "ft3/d": "m3/s",
1416
+ "STB/d": "m3/s",
1417
+ "Sm3/d": "m3/s",
1418
+ "Sm3/min": "m3/s",
1419
+ gpm: "m3/s",
1420
+ MMSCFD: "m3/s",
1421
+ "Mm3/d": "m3/d",
1422
+ "m3/min": "m3/s",
1423
+ "MSm3/d": "m3/s",
1424
+ "lbf/ft": "N/m",
1425
+ min: "s",
1426
+ h: "s",
1427
+ d: "s",
1428
+ month: "d",
1429
+ year: "d",
1430
+ "J/(kg*degK)": "J/(kg*degC)",
1431
+ "BTU/(lbm*degF)": "J/(kg*degC)",
1432
+ "BTU/(Kg*K)": "J/(kg*degC)",
1433
+ "BTU/(h*ft*degF)": "J/(s*m*degK)",
1434
+ "W/(m*degK)": "J/(s*m*degK)",
1435
+ "W/(mK)": "J/(s*m*degK)",
1436
+ K: "C",
1437
+ "C/m": "C/100m",
1438
+ "F/ft": "C/100m",
1439
+ "K/m": "C/100m",
1440
+ "F/100ft": "C/100m",
1441
+ "K/100m": "C/100m",
1442
+ "Bar/C": "Pa/C",
1443
+ "s/m3": "1/m3/d",
1444
+ "1/MMSCFD": "1/m3/d",
1445
+ P: "Pa*s",
1446
+ "mPa*s": "Pa*s",
1447
+ cP: "Pa*s",
1448
+ "hhp/in2": "W/m2",
1449
+ "hhp/ft2": "W/m2",
1450
+ "Sm3/d/bar": "m3/s/bar",
1451
+ "STB/d/psi": "m3/s/bar",
1452
+ "deg/100ft": "deg/m",
1453
+ "deg/30m": "deg/m",
1454
+ "deg/10m": "deg/m",
1455
+ "deg/ft": "deg/m",
1456
+ "rad/ft": "deg/m",
1457
+ "lbf/mol": "kg/mol",
1458
+ "g/mol": "kg/mol",
1459
+ "1/K": "E-06/degC",
1460
+ "E-09/bar": "E-10/psi",
1461
+ "E-14/pa": "E-10/psi",
1462
+ "1/Pa": "E-14/pa",
1463
+ kNm: "Nm",
1464
+ ftlbf: "Nm",
1465
+ lk: "m",
1466
+ ftCla: "m",
1467
+ lkCla: "m",
1468
+ ftSe: "m",
1469
+ ydSe: "m",
1470
+ chSe: "m",
1471
+ "chSe(T)": "m",
1472
+ ftGC: "m",
1473
+ ydInd: "m",
1474
+ "BTU/lbm": "J/kg"
1475
+ });
1476
+ /**
1477
+ * List of all known units in application
1478
+ *
1479
+ * @readonly
1480
+ * @enum {string[]}
1481
+ */
1482
+ const KNOWN_UNITS = Object.freeze(Array.from(new Set(Object.values(ALT_UNITS).flat())));
1483
+ const SPECIAL_NUMBERS_STRING = [
1484
+ NaN,
1485
+ -Infinity,
1486
+ Infinity
1487
+ ].map((number) => number.toString());
1488
+ /**
1489
+ * Description for the different quantites
1490
+ * @readonly
1491
+ */
1492
+ const QUANTITIES_DESCRIPTION = {
1493
+ density: "Density",
1494
+ length: "Length",
1495
+ duration: "Duration",
1496
+ temperature: "Temperature",
1497
+ tempgrad: "Temperature Gradient",
1498
+ volume: "Volume",
1499
+ weight: "Weight",
1500
+ angles: "Angles",
1501
+ depth: "Depth",
1502
+ distance: "Distances",
1503
+ height: "Height",
1504
+ diameters: "Diameters",
1505
+ doglegSeverity: "Dogleg severity",
1506
+ fluidCompressibility: "Fluid Compressibility",
1507
+ force: "Force",
1508
+ gasVolume: "Gas volume",
1509
+ oilVolume: "Oil volume",
1510
+ moleWeight: "Mole weight",
1511
+ linearCapacity: "Linear Capacity",
1512
+ stress: "Stress",
1513
+ thermalConductivity: "Thermal conductivity",
1514
+ specificHeatCapacity: "Specific heat capacity",
1515
+ thermalExpansionCoefficient: "Thermal expansion coefficient",
1516
+ youngsModulus: "Youngs Modulus",
1517
+ torque: "Torque",
1518
+ areaOther: "Area - Other",
1519
+ areaTubular: "Area - Tubular",
1520
+ pumpRate: "Pump Rate",
1521
+ pressure: "Pressure",
1522
+ blowoutFlowRate: "Flowrate (blowout)",
1523
+ percentage: "Percentage",
1524
+ frequency: "Frequency",
1525
+ torqueGradient: "Torque gradient",
1526
+ pressureGradient: "Pressure gradient",
1527
+ flowrate: "Volumetric flow rate",
1528
+ massFlowRate: "Mass flow rate",
1529
+ angleGradient: "Angle gradient",
1530
+ weightGradient: "Weight gradient",
1531
+ forceGradient: "Force gradient",
1532
+ interfacialTension: "Interfacial tension",
1533
+ acceleration: "Acceleration",
1534
+ viscosity: "Viscosity",
1535
+ power: "Power",
1536
+ intensity: "Power intensity",
1537
+ gasliftFlowRate: "Flowrate (Gas lift)",
1538
+ productionFlowRate: "Flowrate (production)",
1539
+ productionFlowRateOil: "Flowrate for Oil (production)",
1540
+ productionFlowRateGas: "Flowrate for Gas (production)",
1541
+ injectionFlowRate: "Flowrate (injection)",
1542
+ blowoutOilFlowRate: "Flowrate for Oil (blowout)",
1543
+ blowoutGasFlowRate: "Flowrate for Gas (blowout)",
1544
+ gor: "Gas Oil Ratio",
1545
+ rotationalSpeed: "Rotational Speed",
1546
+ densityGas: "Density for gas",
1547
+ inflowProductivityIndex: "Inflow productivity index",
1548
+ latitude: "Latitude",
1549
+ longitude: "Longitude",
1550
+ permeability: "Permeability",
1551
+ sdstats: "Standard deviation",
1552
+ roughness: "Material Roughness",
1553
+ wltubulars: "Tubular weight",
1554
+ speed: "Velocity",
1555
+ inverseStandSpeed: "Inverse Stand velocity",
1556
+ rop: "Rate of Penetration (ROP)",
1557
+ densityOil: "Density for oil",
1558
+ densityOilGas: "Density for oil/gas",
1559
+ kickToleranceVolume: "Volume for kick tolerance",
1560
+ densitySolid: "Density for solid",
1561
+ massPerLength: "Mass Per Length",
1562
+ durationShort: "Duration (TempSim short)",
1563
+ durationLong: "Duration (TempSim long)",
1564
+ wearFactor: "Wear factor",
1565
+ turbulentSkin: "Turbulent skin",
1566
+ pressurePerTemperature: "Pressure per temperature",
1567
+ location: "Location coordinates length",
1568
+ mixingRequirements: "Ratio between water and cement",
1569
+ Entalphy: "Entalphy",
1570
+ shearStress: "Shear Stress, force parallel to surface",
1571
+ volumeGradient: "Rate of Volume change per unit",
1572
+ deg: "Degree, a unit of angular measurement",
1573
+ dls: "Dogleg Severity, measure of wellbore curvature changes per unit length",
1574
+ wgrad: "Weight Gradient, change in weight per unit length",
1575
+ entalphy: "Entalphy, total heat content of a system",
1576
+ pressurechange: "Change in pressure over time or between two points",
1577
+ rpm: "Rotations per minute, a measure of the frequency of rotation, specifying the number of full rotations completed in one minute around a fixed axis",
1578
+ sensorAccelerometer: "Strength of gravitational acceleration",
1579
+ sensorMagnetometer: "Strength of magnetic forces at a position",
1580
+ rotationalRate: "Rotational rate, the speed at which an object rotates around a fixed axis, typically measured in degrees per unit of time"
1581
+ };
1582
+ /**
1583
+ * Description for the different units
1584
+ * @readonly
1585
+ */
1586
+ const UNITS_DESCRIPTION = {
1587
+ in: "Inches",
1588
+ mm: "Milimeters",
1589
+ cm: "Centimeters",
1590
+ m: "Meters",
1591
+ km: "Kilometers",
1592
+ ft: "Feets",
1593
+ usft: "US Feets",
1594
+ in2: "Square inches",
1595
+ cm2: "Square centimeters",
1596
+ m2: "Square meters",
1597
+ kg: "Kilograms",
1598
+ tonnes: "Tonnes",
1599
+ mt: "Metric tonnes",
1600
+ kip: "Kip",
1601
+ bbl: "Barrels",
1602
+ Mm3: "Mega cubic meters",
1603
+ MMSCF: "Million Standard Cubic Feet",
1604
+ lbm: "Pound mass",
1605
+ "kg/mol": "Kilograms per mole",
1606
+ "lbf/mol": "Pounds per mole",
1607
+ sg: "Specific gravity",
1608
+ ppg: "Pounds per gallon",
1609
+ "kg/m3": "Kilogram per cubic meters",
1610
+ "lbm/ft3": "Pounds per cubic foot",
1611
+ s: "Seconds",
1612
+ min: "Minutes",
1613
+ h: "Hours",
1614
+ d: "Days",
1615
+ month: "Months",
1616
+ year: "Years",
1617
+ "bbl/ft": "Barrels per foot",
1618
+ lpm: "Litres per minute",
1619
+ bpm: "Barrels per minute",
1620
+ "m3/min": "Cubic meters per minute",
1621
+ "m3/s": "Cubic meters per second",
1622
+ MMSCFD: "Million Standard Cubic Feet per day",
1623
+ "1/MMSCFD": "Inverse Million Standard Cubic Feet per day",
1624
+ bar: "Bar",
1625
+ Pa: "Pascals",
1626
+ kPa: "Kilopascals",
1627
+ MPa: "Megapascals",
1628
+ kPsi: "Kilo pounds per square inch",
1629
+ "kPa/m": "Kilopascals per meter",
1630
+ "psi/ft": "Psi per foot",
1631
+ "bar/100m": "Bars per 100m",
1632
+ "psi/100ft": "Psi per 100ft",
1633
+ "kPa/100m": "Kilopascals per 100m",
1634
+ C: "Degrees Celsius",
1635
+ F: "Degrees Fahrenheit",
1636
+ K: "Kelvins",
1637
+ "C/100m": "Degrees Celsius per 100m",
1638
+ "F/100ft": "Degrees Fahrenheit per 100m",
1639
+ "K/100m": "Kelvins per 100m",
1640
+ "lbf/ft": "Pound force / foot",
1641
+ "Pa/C": "Pascal per celsius",
1642
+ "Bar/C": "Bar per celsius",
1643
+ "psi/F": "Psi per fahrenheit",
1644
+ "psi/C": "Psi per celsius",
1645
+ N: "Newtons",
1646
+ kN: "Kilo Newtons",
1647
+ "N/m": "Newtons per meter",
1648
+ "daN/m": "Decanewtons per meter",
1649
+ lbf: "Pound force",
1650
+ kgf: "Kilogram force",
1651
+ rad: "Radians",
1652
+ "BTU/lbm": "British Thermal Units per pound",
1653
+ ppf: "Pound per foot",
1654
+ "kg/m": "Kilograms per meter",
1655
+ "E-06/degC": "Micro per degree Celsius",
1656
+ "E-06/degF": "Micro per degree Fahrenheit",
1657
+ km2: "Square kilometers",
1658
+ ft2: "Square feet",
1659
+ mm2: "Square millimeters",
1660
+ mile2: "Square miles",
1661
+ ft3: "Cubic feet",
1662
+ "g/cm3": "Grams per cubic centimeter",
1663
+ Sm3: "Standard cubic meter",
1664
+ "ft3/s": "Cubic feet per second",
1665
+ "ft3/d": "Cubic feet per day",
1666
+ "m3/d": "Cubic meter per day",
1667
+ "1/m3/d": "Inverse Cubic meter per day",
1668
+ "s/m3": "Seconds per cubic meters",
1669
+ "bbl/d": "Barrels per day",
1670
+ tonneForce: "Tonne force",
1671
+ USGal: "US gallon",
1672
+ "g/mol": "Grams per mol",
1673
+ Nm: "Newton meter",
1674
+ kNm: "Kilo Newton meter",
1675
+ ftlbf: "Foot pound",
1676
+ "J/(kg*degC)": "Joules per kilogram degree Celsius",
1677
+ "J/(kg*degK)": "Joules per kilogram degree Kelwin",
1678
+ "BTU/(lbm*degF)": "British Thermal Unit per pound Fahrenheit",
1679
+ "BTU/(h*ft*degF)": "British Thermal Units per hour feet degree Fahrenheit",
1680
+ l: "Litres",
1681
+ "l/m": "Litres per meter",
1682
+ "kJ/kg": "Kilo joules per kilogram",
1683
+ "J/kg": "Joules per kilogram",
1684
+ deg: "Degrees",
1685
+ "W/(mK)": "Watts per milli Kelvin",
1686
+ psi: "Pounds per square inch",
1687
+ "1/bar": "1/bar",
1688
+ "1/psi": "1/psi",
1689
+ "deg/100ft": "Degrees per 100ft",
1690
+ "deg/10m": "Degrees per 10m",
1691
+ "deg/30m": "Degrees per 30m",
1692
+ "%": "Percent",
1693
+ Hz: "Hertz",
1694
+ "1/s": "Inverse second",
1695
+ rpm: "Revolutions per minute",
1696
+ "Pa/m": "Pascal per meter",
1697
+ "bar/m": "Bar per meter",
1698
+ gpm: "Gallons per minute",
1699
+ "kg/s": "Kilograms per second",
1700
+ "lbm/s": "Pound mass per second",
1701
+ "tonnes/h": "Tonnes per hour",
1702
+ "tons/h": "Tons per hour",
1703
+ "deg/m": "Degrees per meter",
1704
+ "deg/ft": "Degrees per foot",
1705
+ "rad/m": "Radians per meter",
1706
+ "rad/ft": "Radians per foot",
1707
+ "dyn/cm": "Dyn per centimeter",
1708
+ "mN/m": "Millinewtons per meter",
1709
+ "1/kPa": "1/kPa",
1710
+ m3: "Cubic meters",
1711
+ "m/s": "Meters per second",
1712
+ "ft/s": "Feet per second",
1713
+ "m/min": "Meters per minute",
1714
+ "ft/min": "Feet per min",
1715
+ "m/h": "Meters per hour",
1716
+ "ft/h": "Feet per hour",
1717
+ mph: "Miles per hour",
1718
+ "km/h": "Kilometers per hour",
1719
+ "m/s2": "Meters per second squared",
1720
+ "ft/s2": "Feet per second squared",
1721
+ "Pa*s": "Pascal seconds",
1722
+ P: "Poise (dyne second per square centimeter)",
1723
+ "mPa*s": "Millipascal seconds",
1724
+ cP: "Centi Poise",
1725
+ W: "Watts",
1726
+ hhp: "Hydraulic horsepower",
1727
+ hp: "Horsepower",
1728
+ kW: "Kilowatts",
1729
+ MW: "Megawatts",
1730
+ "BTU/h": "British Thermal Units per hour",
1731
+ "hhp/in2": "Hydraulic horsepower per square inch",
1732
+ "hhp/ft2": "Hydraulic horsepower per square feet",
1733
+ "Mm3/d": "Mega cubic meters per day",
1734
+ "STB/d": "Stock Tank Barrel per day",
1735
+ "Sm3/d": "Standard cubic meters per day",
1736
+ "Sm3/min": "Standard cubic meters per minute",
1737
+ "MSm3/d": "Mega standard cubic meters per day",
1738
+ "SCF/STB": "Standard Cubic Feet per Stock Tank Barrel",
1739
+ "Sm3/Sm3": "Standard cubic meters per Standard cubic meter",
1740
+ "SCF/d": "Standard cubic feet per day",
1741
+ STB: "Stock Tank Barrel",
1742
+ SCF: "Standard Cubic Feet",
1743
+ Gsg: "Gas - specific gravity",
1744
+ Gppg: "Gas - pounds per gallon",
1745
+ "Gkg/m3": "Gas - kilogram per cubic meters",
1746
+ "Glbm/ft3": "Gas - pounds per cubic foot",
1747
+ MSm3: "Mega standard cubic meters",
1748
+ "m3/s/bar": "Cubic per second per bar",
1749
+ "Sm3/d/bar": "Standard cubic per day per bar",
1750
+ "STB/d/psi": "Standard barrels per day per psi",
1751
+ klbf: "kilopound force",
1752
+ "1/Pa": "1/Pascal",
1753
+ "1/MPa": "1/MPa",
1754
+ ksi: "Kilopound per square inch",
1755
+ "lbf/100ft2": "Pounds per 100 square foot",
1756
+ "lb/ft3": "lb/ft3",
1757
+ "°N": "°N (latitude)",
1758
+ "°S": "°S (latitude)",
1759
+ "°W": "°W (longitude)",
1760
+ "°E": "°E (longitude)",
1761
+ fr: "Fraction",
1762
+ mD: "Millidarcy",
1763
+ Sigma: "Sigma",
1764
+ CI: "Confidence Interval",
1765
+ "J/(s*m*degK)": "Joules per second meter Kelvin",
1766
+ "C/m": "Degrees Celsius per meter",
1767
+ "F/ft": "Degrees Fahrenheit per meter",
1768
+ "K/m": "Kelvin per meter",
1769
+ microM: "Micro meter",
1770
+ "W/m2": "Watt per square meter",
1771
+ "1/K": "Inverse Kelvin",
1772
+ "lb/ft": "Pound Per Feet",
1773
+ "E-09/bar": "Nano per bar",
1774
+ "E-10/psi": "10⁻¹⁰ per psi",
1775
+ "E-14/pa": "10⁻¹⁴ per pascal",
1776
+ lk: "Link",
1777
+ ftCla: "Clark`s foot",
1778
+ lkCla: "Clark`s link",
1779
+ ftSe: "British foot (Sears 1922)",
1780
+ ydSe: "British yard (Sears 1922)",
1781
+ chSe: "British chain (Sears 1922)",
1782
+ "chSe(T)": "British chain (Sears 1922 Truncated)",
1783
+ ftGC: "Gold Coast foot",
1784
+ ydInd: "Indian yard",
1785
+ "d/stand": "Day per stand",
1786
+ "h/stand": "Hour per stand",
1787
+ "min/stand": "Minute per stand",
1788
+ "s/stand": "Second per stand",
1789
+ "m3/t": "Cubic meter per ton",
1790
+ "L/100kg": "Liter per 100kg",
1791
+ GPa: "Gigapascals, unit of pressure",
1792
+ "cm3/m": "Cubic cm per meter",
1793
+ "in3/ft": "Cubic inches per foot",
1794
+ "ft3/ft": "Cubic feet per foot",
1795
+ "m3/m": "Cubic meters per meter",
1796
+ "mm3/m": "Cubic millimeters per meter",
1797
+ "1/GPa": "Inverse gigapascal",
1798
+ lps: "Liters per second",
1799
+ nT: "nanoTesla",
1800
+ Gs: "Gauss",
1801
+ g: "g force",
1802
+ "deg/h": "Degrees per hour"
1803
+ };
1804
+ //#endregion
1805
+ //#region src/units/unit-catalog.ts
1806
+ /** Returns the units configured for a quantity key. */
1807
+ function showAltUnitsList(quantityKey) {
1808
+ return ALT_UNITS[quantityKey];
1809
+ }
1810
+ /** Returns the units configured for a quantity. */
1811
+ function getUnitsForQuantity(quantity) {
1812
+ return showAltUnitsList(quantity);
1813
+ }
1814
+ /** Returns all configured quantity keys. */
1815
+ function getQuantities() {
1816
+ return Object.keys(ALT_UNITS);
1817
+ }
1818
+ /** Returns the display label for a unit key. */
1819
+ function label(unitKey) {
1820
+ return LABELS[unitKey];
1821
+ }
1822
+ /** Returns the base unit configured for a quantity. */
1823
+ function unitFromKey(quantity) {
1824
+ return UNIT_FROM_KEY[quantity];
1825
+ }
1826
+ /** Alias for `unitFromKey`. */
1827
+ function unitFromQuantity(quantity) {
1828
+ return unitFromKey(quantity);
1829
+ }
1830
+ /** Returns the alternative units and their display labels for a quantity. */
1831
+ function getAltUnitsListByQuantity(quantity) {
1832
+ const quantityUnitList = showAltUnitsList(quantity);
1833
+ return quantityUnitList ? quantityUnitList.map((unit) => ({
1834
+ unit,
1835
+ label: label(unit)
1836
+ })) : void 0;
1837
+ }
1838
+ //#endregion
1839
+ //#region src/numbers/parsing/number-input.ts
1840
+ /** Basic trimming of numeric input strings. */
1841
+ const trim = (value) => {
1842
+ return value.trim().replace(/[\t\r\n]/g, "");
1843
+ };
1844
+ /** Counts occurrences of a character in a string. */
1845
+ function charCount(character, value) {
1846
+ const singleCharacter = String(character)[0];
1847
+ let total = 0;
1848
+ let lastLocation = value.indexOf(singleCharacter, 0) + 1;
1849
+ while (lastLocation > 0) {
1850
+ lastLocation = value.indexOf(singleCharacter, lastLocation) + 1;
1851
+ total += 1;
1852
+ }
1853
+ return total;
1854
+ }
1855
+ /** Normalizes supported decimal and thousands separators in a numeric input string. */
1856
+ function cleanNumStr(value) {
1857
+ let cleanString = trim(String(value));
1858
+ const slashCount = charCount("/", cleanString);
1859
+ const spaceCount = charCount(" ", cleanString) + charCount("\xA0", cleanString);
1860
+ let dotCount = charCount(".", cleanString);
1861
+ let commaCount = charCount(",", cleanString);
1862
+ if (slashCount === 0 && spaceCount > 0) cleanString = cleanString.replace(/\s/g, "");
1863
+ if (commaCount > 1) cleanString = cleanString.replace(/,/g, "");
1864
+ if (dotCount > 1) cleanString = cleanString.replace(/\./g, "");
1865
+ commaCount = charCount(",", cleanString);
1866
+ dotCount = charCount(".", cleanString);
1867
+ if (dotCount === 1 && commaCount === 1) {
1868
+ if (cleanString.indexOf(",") > cleanString.indexOf(".")) {
1869
+ cleanString = cleanString.replace(".", "");
1870
+ cleanString = cleanString.replace(",", ".");
1871
+ } else cleanString = cleanString.replace(",", "");
1872
+ if (cleanString.indexOf(".") === 0) cleanString = `0${cleanString}`;
1873
+ return cleanString;
1874
+ }
1875
+ if (!dotCount && commaCount) cleanString = cleanString.replace(",", ".");
1876
+ if (cleanString.indexOf(".") === 0) cleanString = `0${cleanString}`;
1877
+ return cleanString;
1878
+ }
1879
+ /** Removes redundant leading zeros while preserving the sign and fractional part. */
1880
+ const stripLeadingZeros = (value) => {
1881
+ const isMinus = value?.[0] === "-";
1882
+ const cleanedValue = value.replace(/^-/gm, "").replace(/^(?:0+(?=[1-9])|0+(?=0))/gm, "");
1883
+ return isMinus ? `-${cleanedValue}` : cleanedValue;
1884
+ };
1885
+ /** Normalizes a numeric input string and parses it as a number. */
1886
+ function cleanNum(value) {
1887
+ if (typeof value === "number") return value;
1888
+ return parseFloat(cleanNumStr(value));
1889
+ }
1890
+ const isNull = (value) => {
1891
+ return value === null;
1892
+ };
1893
+ const isUndefined = (value) => {
1894
+ return value === void 0;
1895
+ };
1896
+ const isArray = (value) => {
1897
+ return Boolean(value) && value.constructor === Array;
1898
+ };
1899
+ const isObject = (value) => {
1900
+ return Boolean(value) && value.constructor === Object;
1901
+ };
1902
+ const isEmptyString = (value) => {
1903
+ return value === "";
1904
+ };
1905
+ const isTrailingPeriodSeparator = (value) => {
1906
+ return Boolean(value) && String(value)[String(value).length - 1] === ".";
1907
+ };
1908
+ const isTrailingCommaSeparator = (value) => {
1909
+ return Boolean(value) && String(value)[String(value).length - 1] === ",";
1910
+ };
1911
+ //#endregion
1912
+ //#region src/units/unit-string.ts
1913
+ const SEPARATOR = "|";
1914
+ const UNIT_RE = /^(-?[0-9., /]*?(?:e[-+]?[0-9]+)?)([^0-9-., /].*)?$/;
1915
+ /** Checks whether a unit string has an empty numeric part, for example `|m`. */
1916
+ function isEmptyValueWithUnit(value) {
1917
+ return typeof value === "string" && value.length > 0 && value.startsWith("|");
1918
+ }
1919
+ /** Splits a supported unit string into its numeric and unit parts. */
1920
+ function split(valueWithUnit) {
1921
+ let match;
1922
+ let normalizedValue = valueWithUnit !== void 0 && valueWithUnit !== null ? String(valueWithUnit) : "";
1923
+ if (charCount("|", normalizedValue) > 1) {
1924
+ match = normalizedValue.split("|");
1925
+ normalizedValue = match.slice(0, -1).join("") + "|" + match.slice(-1);
1926
+ }
1927
+ if (normalizedValue.indexOf("|") >= 0) match = normalizedValue.split("|");
1928
+ else if (SPECIAL_NUMBERS_STRING.includes(normalizedValue)) match = [normalizedValue, ""];
1929
+ else {
1930
+ match = cleanNumStr(normalizedValue).match(UNIT_RE);
1931
+ if (match) match = match.slice(1);
1932
+ }
1933
+ if (!match) match = ["0", ""];
1934
+ if (match[1] == null) match[1] = "";
1935
+ return [match[0], match[1]];
1936
+ }
1937
+ /** Returns the numeric part of a unit string. */
1938
+ function getValue(valueWithUnit) {
1939
+ return split(valueWithUnit)[0];
1940
+ }
1941
+ /** Returns the unit part of a unit string. */
1942
+ function getUnit(valueWithUnit) {
1943
+ return split(valueWithUnit)[1];
1944
+ }
1945
+ /** Checks whether a value contains exactly one known unit suffix. */
1946
+ function isValueWithUnit(value) {
1947
+ if (!value) return false;
1948
+ const parts = String(value).split("|");
1949
+ return parts.length === 2 && KNOWN_UNITS.includes(parts[1]);
1950
+ }
1951
+ /** Joins a value and unit using the package unit separator. */
1952
+ function withUnit(value, unit, defaultValue = "") {
1953
+ if (value === null || value === "" || value === void 0) value = defaultValue;
1954
+ if (unit === null) return String(value);
1955
+ let [normalizedValue, normalizedUnit] = String(value).includes("|") ? split(String(value)) : [value, unit];
1956
+ if (!normalizedUnit) normalizedUnit = unit;
1957
+ return [normalizedValue, normalizedUnit].join("|");
1958
+ }
1959
+ /** Replaces a unit key in a unit string with its display label. */
1960
+ function withPrettyUnitLabel(valueWithUnits) {
1961
+ const [value, unit] = split(valueWithUnits);
1962
+ return `${value} ${LABELS[unit] ?? ""}`;
1963
+ }
1964
+ //#endregion
1965
+ //#region src/numbers/fractions/fractions.ts
1966
+ const normalizeFractionWhitespace = (value) => {
1967
+ return value.trim().replace(/\s+/g, " ");
1968
+ };
1969
+ /** Checks whether a string can be parsed as a fraction by fraction.js. */
1970
+ const isFraction = (value) => {
1971
+ if (typeof value !== "string" || !value.includes("/")) return false;
1972
+ try {
1973
+ new fraction_js.default(normalizeFractionWhitespace(value));
1974
+ return true;
1975
+ } catch (error) {
1976
+ return error.message === "Division by Zero";
1977
+ }
1978
+ };
1979
+ /** Converts a fraction to its decimal value, or returns `NaN` when it cannot be parsed. */
1980
+ function fraction(value) {
1981
+ if (value instanceof Array || value === null || value === void 0) return NaN;
1982
+ if (typeof value === "string") value = normalizeFractionWhitespace(value);
1983
+ if (value === "") return NaN;
1984
+ let result = NaN;
1985
+ let infinite = false;
1986
+ try {
1987
+ const fractionObject = new fraction_js.default(value);
1988
+ if (fractionObject !== void 0) result = fractionObject.valueOf();
1989
+ } catch (error) {
1990
+ if (error instanceof Error && error.message === "Division by Zero") infinite = true;
1991
+ }
1992
+ return infinite ? Infinity : result;
1993
+ }
1994
+ /** Converts a decimal value to a fractional string. */
1995
+ function asFraction(value) {
1996
+ if (typeof value === "string") value = normalizeFractionWhitespace(value);
1997
+ if (value === "") value = "0";
1998
+ return new fraction_js.default(value).toFraction(true);
1999
+ }
2000
+ /**
2001
+ * Converts a fraction string to a number.
2002
+ *
2003
+ * For compatibility, invalid inputs are returned unchanged and division by zero returns signed infinity.
2004
+ */
2005
+ function numFraction(value) {
2006
+ if (value instanceof Array || value === null || value === void 0 || value === "" || value === Infinity || value === -Infinity || value === "Infinity" || value === "-Infinity" || Number.isNaN(value) || value === "NaN") return value;
2007
+ if (typeof value === "string") value = normalizeFractionWhitespace(value);
2008
+ let result = value;
2009
+ try {
2010
+ const fractionObject = new fraction_js.default(value);
2011
+ if (fractionObject !== void 0) result = fractionObject.valueOf();
2012
+ } catch (error) {
2013
+ if (error.message === "Division by Zero") return value.charAt(0) === "-" ? -Infinity : Infinity;
2014
+ console.warn("Error in numFraction() method: ", value);
2015
+ }
2016
+ return result.valueOf();
2017
+ }
2018
+ //#endregion
2019
+ //#region src/numbers/scientific-notation/scientific-notation.ts
2020
+ const EXP_NOTATION_RE = /^[-+]?[0-9]*\.?[0-9]+(?:\/[0-9]*\.?[0-9]+)?(?:[eE][-+]?[0-9]+)?$/;
2021
+ /** Normalizes whitespace and mantissa syntax in a scientific-notation string. */
2022
+ const normalizeExponent = (input) => {
2023
+ return input.replace(/^([+-]?(?:\d+\.?\d*|\.\d+))[ ]*[eE][ ]*([+-]?[ ]*\d+)/, (_match, mantissa, exponent) => {
2024
+ let normalizedMantissa = mantissa.endsWith(".") ? mantissa.slice(0, -1) : mantissa;
2025
+ if (normalizedMantissa.startsWith(".")) normalizedMantissa = `0${normalizedMantissa}`;
2026
+ const normalizedExponent = exponent.replace(/[ ]+/g, "");
2027
+ return `${normalizedMantissa}e${normalizedExponent}`;
2028
+ });
2029
+ };
2030
+ /** Normalizes scientific notation while preserving an optional unit suffix. */
2031
+ function normalizeScientific(value) {
2032
+ if (typeof value !== "string") return value;
2033
+ const normalizedSpaces = value.replace(/\u00A0|\u2007|\u202F/g, " ").trim();
2034
+ if (isValueWithUnit(normalizedSpaces)) {
2035
+ const [number, unit] = split(normalizedSpaces);
2036
+ return `${normalizeExponent(number.trim())}|${unit.trim()}`;
2037
+ }
2038
+ const match = normalizedSpaces.match(/^([+-]?(?:\d+(?:\.\d*)?|\.\d+)\s*[eE]\s*[+-]?\s*\d+)\s+(.+)$/);
2039
+ if (match) return `${normalizeExponent(match[1])}|${match[2].trim()}`;
2040
+ return normalizeExponent(normalizedSpaces);
2041
+ }
2042
+ //#endregion
2043
+ //#region src/numbers/predicates.ts
2044
+ /** Checks whether a value is supported as a finite numeric or fraction input. */
2045
+ function isNumeric(value) {
2046
+ if (value === void 0 || value === null || Array.isArray(value) || typeof value === "object" || Number.isNaN(value) || value === "NaN" || value === Infinity || value === -Infinity || value === "Infinity" || value === "-Infinity") return false;
2047
+ if (isFraction(value)) return true;
2048
+ return typeof value === "string" ? !isNaN(parseFloat(value)) && (EXP_NOTATION_RE.test(value) || isFinite(value)) : isFinite(value);
2049
+ }
2050
+ const isNonNumerical = (value) => {
2051
+ return !isNumeric(value);
2052
+ };
2053
+ const isPercentage = (value) => {
2054
+ return typeof value === "string" && /^\d+(\.\d+)?%$/.test(value);
2055
+ };
2056
+ function allNumbers(values) {
2057
+ return !values.some((value) => typeof value !== "number");
2058
+ }
2059
+ //#endregion
2060
+ //#region src/numbers/parsing/parse-number.ts
2061
+ const countTrailingZeros = (value, decimalPartOnly = false) => {
2062
+ const condition = decimalPartOnly ? /0+((?=[|eE])|$)/ : /(0+|0+\.0+)((?=[|eE])|$)/;
2063
+ if (typeof value === "string" && (decimalPartOnly ? value.includes(".") || value.includes(",") : true)) return value?.match(condition)?.[0]?.replaceAll(/[.,]/g, "")?.length ?? 0;
2064
+ return 0;
2065
+ };
2066
+ const hasTrailingZeros = (value) => {
2067
+ return countTrailingZeros(value) > 0;
2068
+ };
2069
+ /**
2070
+ * Internal function to parse the value, unit, and type from a generic numeric input
2071
+ *
2072
+ * Accepts number types (1.234), stringified numbers ('1.234'), and unit numbers ('1.234|m')
2073
+ *
2074
+ * @param value
2075
+ * @returns object with number, unit, and type
2076
+ */
2077
+ const parseNumber = (value, preserveTrailingZeros = false) => {
2078
+ const isString = typeof value === "string";
2079
+ const hasUnit = isString && isValueWithUnit(value);
2080
+ const unit = hasUnit ? getUnit(value) : null;
2081
+ const cleaned = cleanNumStr(hasUnit ? getValue(value) : value);
2082
+ return {
2083
+ number: preserveTrailingZeros && hasTrailingZeros(value) ? cleaned : toNum(cleaned),
2084
+ unit,
2085
+ isString
2086
+ };
2087
+ };
2088
+ /**
2089
+ * Convert a number to a string safely, better than String(value)
2090
+ * String(0.0000002) returns '2e-7' which is unwanted if we need to preserve formatting
2091
+ *
2092
+ * @param value
2093
+ * @param [isScientific] whether to preserve scientific notation
2094
+ * @returns number or string output value
2095
+ */
2096
+ const safeStringifyNumber = (value, isScientific) => {
2097
+ return isScientific ? String(value) : toString(value);
2098
+ };
2099
+ /**
2100
+ * Internal function to unParse a value, unit, and type back to an output value
2101
+ *
2102
+ * Accepts number types (1.234), stringified numbers ('1.234'), and unit numbers ('1.234|m')
2103
+ *
2104
+ * @param args
2105
+ * @param args.value
2106
+ * @param args.unit
2107
+ * @param args.isString
2108
+ * @param args.isScientific
2109
+ * @returns number or string output value
2110
+ */
2111
+ const unParseNumber = ({ value, unit, isString, isScientific }) => {
2112
+ const convertedValue = typeof value === "number" && isString ? safeStringifyNumber(value, isScientific) : value;
2113
+ if (unit) return withUnit(convertedValue, unit);
2114
+ return convertedValue;
2115
+ };
2116
+ //#endregion
2117
+ //#region src/numbers/comparison/comparison.ts
2118
+ const DEFAULT_MAX_RELATIVE_DIFF = Number.EPSILON;
2119
+ const convertNumbers = (firstValue, secondValue) => {
2120
+ const { number: firstNumber, unit: firstUnit } = parseNumber(firstValue);
2121
+ const { number: secondNumber, unit: secondUnit } = parseNumber(secondValue);
2122
+ return {
2123
+ firstNumber,
2124
+ secondNumber: firstUnit && secondUnit && firstUnit !== secondUnit ? convertAndGetValue(secondNumber, firstUnit, secondUnit) : secondNumber
2125
+ };
2126
+ };
2127
+ const getToleranceNumber = (relativeDiff) => {
2128
+ if (relativeDiff !== null && relativeDiff !== void 0) {
2129
+ if (isNumeric(relativeDiff) && typeof relativeDiff === "number") return relativeDiff;
2130
+ if (isPercentage(relativeDiff)) {
2131
+ const percentageValue = toNum(relativeDiff?.toString().replace("%", ""));
2132
+ if (isNumeric(percentageValue)) return percentageValue / 100;
2133
+ }
2134
+ }
2135
+ return null;
2136
+ };
2137
+ /**
2138
+ * Determines whether two numbers are close in value with a tolerance
2139
+ * (mitigates excess JavaScript floating point precision quirks)
2140
+ */
2141
+ const isCloseTo = (firstValue, secondValue, options = { relativeDiff: DEFAULT_MAX_RELATIVE_DIFF }) => {
2142
+ const { relativeDiff, absoluteDiff } = options;
2143
+ const toleranceNumber = getToleranceNumber(relativeDiff ?? absoluteDiff);
2144
+ if (firstValue === null || secondValue === null) return false;
2145
+ const hasUnitFirstValue = isValueWithUnit(firstValue);
2146
+ const hasUnitSecondValue = isValueWithUnit(secondValue);
2147
+ if (hasUnitFirstValue && !hasUnitSecondValue || !hasUnitFirstValue && hasUnitSecondValue) throw new Error(`Parameters must either both have units or both not have units. Received "${firstValue}" and "${secondValue}"`);
2148
+ if (toleranceNumber === null) {
2149
+ console.warn("Tolerance number is not defined!");
2150
+ return firstValue === secondValue;
2151
+ }
2152
+ if (toleranceNumber <= 0 || toleranceNumber < Number.EPSILON) throw Error("Unpredictable results - toleranceNumber should be bigger than zero or less then EPSILON");
2153
+ const { firstNumber, secondNumber } = convertNumbers(firstValue, secondValue);
2154
+ if ((firstNumber === Infinity || firstNumber === "Infinity") && (secondNumber === Infinity || secondNumber === "Infinity") || (firstNumber === -Infinity || firstNumber === "-Infinity") && (secondNumber === -Infinity || secondNumber === "-Infinity")) return true;
2155
+ if (typeof firstNumber === "number" && typeof secondNumber === "number") {
2156
+ if (firstNumber === secondNumber) return true;
2157
+ if (absoluteDiff || firstNumber === 0 || secondNumber === 0) {
2158
+ const diff = Math.abs(firstNumber - secondNumber);
2159
+ return isCloseTo(diff, toleranceNumber, { relativeDiff: "1%" }) || diff < toleranceNumber;
2160
+ } else return 2 * Math.abs((firstNumber - secondNumber) / (firstNumber + secondNumber)) < toleranceNumber;
2161
+ }
2162
+ return false;
2163
+ };
2164
+ /**
2165
+ * Determines whether two numbers are close enough to be equal
2166
+ * or checks the firstValue is greater than the secondValue
2167
+ */
2168
+ const isCloseToOrGreaterThan = (firstValue, secondValue, options = { relativeDiff: DEFAULT_MAX_RELATIVE_DIFF }) => {
2169
+ if (firstValue === null || secondValue === null) return false;
2170
+ const { firstNumber, secondNumber } = convertNumbers(firstValue, secondValue);
2171
+ if (typeof firstNumber === "number" && typeof secondNumber === "number") return isCloseTo(firstNumber, secondNumber, options) || firstNumber > secondNumber;
2172
+ return false;
2173
+ };
2174
+ /**
2175
+ * Determines whether two numbers are close enough to be equal
2176
+ * or checks the firstValue is less than the secondValue
2177
+ */
2178
+ const isCloseToOrLessThan = (firstValue, secondValue, options = { relativeDiff: DEFAULT_MAX_RELATIVE_DIFF }) => {
2179
+ if (firstValue === null || secondValue === null) return false;
2180
+ const { firstNumber, secondNumber } = convertNumbers(firstValue, secondValue);
2181
+ if (typeof firstNumber === "number" && typeof secondNumber === "number") return isCloseTo(firstNumber, secondNumber, options) || firstNumber < secondNumber;
2182
+ return false;
2183
+ };
2184
+ /**
2185
+ * Determines whether two objects or arrays are deeply close equal (all nested child numbers)
2186
+ */
2187
+ const isDeepCloseTo = (a, b, options = { relativeDiff: DEFAULT_MAX_RELATIVE_DIFF }) => {
2188
+ if (Array.isArray(a) && Array.isArray(b)) {
2189
+ if (a.length !== b.length) return false;
2190
+ return a.every((a, i) => isDeepCloseTo(a, b[i], options));
2191
+ }
2192
+ if (typeof a === "object" && a !== null && typeof b === "object" && b !== null) {
2193
+ const aKeys = Object.keys(a);
2194
+ const bKeys = Object.keys(b);
2195
+ if (aKeys.length !== bKeys.length) return false;
2196
+ return aKeys.every((key) => isDeepCloseTo(a[key], b[key], options));
2197
+ }
2198
+ if (Number.isNaN(a) && Number.isNaN(b) || a === "" && b === "") return true;
2199
+ if (typeof a === "number" && typeof b === "number" || isValueWithUnit(a) && isValueWithUnit(b) || isValidNum(a) && isValidNum(b)) return isCloseTo(a, b, options);
2200
+ return true;
2201
+ };
2202
+ //#endregion
2203
+ //#region src/numbers/rounding/rounding.ts
2204
+ const DEFAULT_SIGNIFICANT_DIGITS = 4;
2205
+ /**
2206
+ * Rounds a number to N decimal places.
2207
+ *
2208
+ * @private (see round() for the public interface)
2209
+ * @param value
2210
+ * @param [n]
2211
+ * @returns rounded number
2212
+ */
2213
+ const roundNumber = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
2214
+ const factor = 10 ** n;
2215
+ return Math.round(value * factor) / factor;
2216
+ };
2217
+ /**
2218
+ * Rounds a numeric value to N decimal places.
2219
+ *
2220
+ * - accepts number types (1.234), stringified numbers ('1.234'), and unit numbers ('1.234|m')
2221
+ * - returns same type as input
2222
+ *
2223
+ * @param value - the value to round
2224
+ * @param [n] - the number of decimal places to round to
2225
+ * @returns rounded value, or input value when unable to round
2226
+ *
2227
+ * @example
2228
+ * round(3.14159265) -> 3.1416
2229
+ */
2230
+ const round = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
2231
+ if (typeof value === "number") return roundNumber(value, n);
2232
+ if (value === null || Number.isNaN(value) || value === Infinity || value === -Infinity || value === void 0) return value;
2233
+ const { number, unit, isString } = parseNumber(value);
2234
+ return unParseNumber({
2235
+ value: !isNumeric(number) || typeof number === "string" && number.endsWith(".") ? value : roundNumber(number, n),
2236
+ unit,
2237
+ isString,
2238
+ isScientific: isScientificStringNum(value)
2239
+ });
2240
+ };
2241
+ /**
2242
+ * Rounds a number to N significant digits.
2243
+ *
2244
+ * @private (see roundToPrecision() for the public interface)
2245
+ * @param value
2246
+ * @param [n] number of significant digits
2247
+ * @returns rounded number
2248
+ */
2249
+ const roundNumberToPrecision = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
2250
+ return Number(value.toPrecision(n));
2251
+ };
2252
+ /**
2253
+ * Rounds a number to N significant digits, preserving trailing decimal zeros
2254
+ *
2255
+ * @private (see roundByMagnitudeToFixed() for the public interface)
2256
+ * @param value
2257
+ * @param [n] number of significant digits
2258
+ * @returns rounded number as string
2259
+ */
2260
+ const roundNumberToFixedPrecision = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
2261
+ const [integerPart, decimalPart] = toNum(value).toPrecision(n).split(".");
2262
+ if (decimalPart) {
2263
+ const decimalDigits = n - integerPart.length;
2264
+ return `${integerPart}.${decimalPart.padEnd(decimalDigits, "0")}`;
2265
+ } else return integerPart;
2266
+ };
2267
+ /**
2268
+ * Rounds a number to N significant digits, excluding the integer part (only rounds decimal part)
2269
+ *
2270
+ * @private (see roundToPrecision() for the public interface)
2271
+ * @param value
2272
+ * @param [n] number of significant digits
2273
+ * @returns rounded number
2274
+ */
2275
+ const roundNumberToDecimalPrecision = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
2276
+ if (Math.abs(value) > 1) {
2277
+ const [integerPart, decimalPart] = formatDecimal(value, "").split(".");
2278
+ if (!decimalPart) return value;
2279
+ else {
2280
+ const roundedDecimalPart = Number(`0.${decimalPart}`).toPrecision(n).slice(1);
2281
+ return Number(integerPart + roundedDecimalPart);
2282
+ }
2283
+ }
2284
+ return roundNumberToPrecision(value, n);
2285
+ };
2286
+ /**
2287
+ * Rounds a numeric value to N significant digits.
2288
+ *
2289
+ * - accepts number types (1.234), stringified numbers ('1.234'), and unit numbers ('1.234|m')
2290
+ * - returns same type as input
2291
+ * - similar to Number.toPrecision() but safer
2292
+ * - does *not* append trailing zeros (unlike `Number(4).toPrecision(4)` -> '4.000')
2293
+ *
2294
+ * @param value - the value to round
2295
+ * @param [n] - the number of significant digits
2296
+ * @returns rounded value, or input value when unable to round
2297
+ *
2298
+ * @example
2299
+ * roundToPrecision(0.0000456789) -> 0.00004568
2300
+ */
2301
+ const roundToPrecision = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
2302
+ if (typeof value === "number") return roundNumberToPrecision(value, n);
2303
+ if (value === null || Number.isNaN(value) || value === Infinity || value === -Infinity || value === void 0) return value;
2304
+ const { number, unit, isString } = parseNumber(value);
2305
+ return unParseNumber({
2306
+ value: !isNumeric(number) || typeof number === "string" && number.endsWith(".") ? value : roundNumberToPrecision(number, n),
2307
+ unit,
2308
+ isString,
2309
+ isScientific: isScientificStringNum(value)
2310
+ });
2311
+ };
2312
+ /**
2313
+ * Rounds a numeric value to N significant digits (only the decimal part)
2314
+ *
2315
+ * - accepts number types (1.234), stringified numbers ('1.234'), and unit numbers ('1.234|m')
2316
+ * - returns same type as input
2317
+ * - unlike roundToPrecision(), acts only on the decimal part, not the integer part too
2318
+ *
2319
+ * @param value - the value to round
2320
+ * @param [n]- the number of significant digits
2321
+ * @returns rounded value, or input value when unable to round
2322
+ *
2323
+ * @example
2324
+ * roundToPrecision(1234.0000456789) -> 1234.00004568
2325
+ */
2326
+ const roundToDecimalPrecision = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
2327
+ if (typeof value === "number") return roundNumberToDecimalPrecision(value, n);
2328
+ if (value === null || Number.isNaN(value) || value === Infinity || value === -Infinity || value === void 0) return value;
2329
+ const { number, unit, isString } = parseNumber(value);
2330
+ return unParseNumber({
2331
+ value: !isNumeric(number) || typeof number === "string" && number.endsWith(".") ? value : roundNumberToDecimalPrecision(number, n),
2332
+ unit,
2333
+ isString,
2334
+ isScientific: isScientificStringNum(value)
2335
+ });
2336
+ };
2337
+ /**
2338
+ * Rounds a number to an appropriate number of digits, based on its size.
2339
+ *
2340
+ * @private (see roundByMagnitude() for the public interface)
2341
+ * @param value
2342
+ * @param [n] the number of significant digits
2343
+ * @param [toFixed] to fixed digits (i.e. with trailing zeros)
2344
+ * @returns rounded number
2345
+ */
2346
+ const roundNumberByMagnitude = (value, n = DEFAULT_SIGNIFICANT_DIGITS, toFixed = false) => {
2347
+ const noDecimalsAbove = 10 ** n;
2348
+ const result = noDecimalsAbove && value > noDecimalsAbove ? roundNumber(value, 0) : toFixed ? roundNumberToFixedPrecision(value, n) : roundNumberToPrecision(value, n);
2349
+ return toFixed ? String(result) : result;
2350
+ };
2351
+ /**
2352
+ * Rounds a numeric value to an appropriate number of digits, based on its size. It rounds to N significant digits,
2353
+ * but never rounds the integer part.
2354
+ *
2355
+ * - accepts number types (1.234), stringified numbers ('1.234'), and unit numbers ('1.234|m')
2356
+ * - returns same type as input
2357
+ *
2358
+ * @param value - the value to round
2359
+ * @param [n] - the number of significant digits
2360
+ * @returns rounded value, or input value when unable to round
2361
+ *
2362
+ * @example
2363
+ * roundByMagnitude(0.000123456789) -> 0.0001235
2364
+ * roundByMagnitude(1.123456789) -> 1.123
2365
+ * roundByMagnitude(19999.123456789) -> 19999
2366
+ */
2367
+ const roundByMagnitude = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
2368
+ if (typeof value === "number") return roundNumberByMagnitude(value, n);
2369
+ if (value === null || Number.isNaN(value) || value === Infinity || value === -Infinity || value === void 0) return value;
2370
+ const { number, unit, isString } = parseNumber(value);
2371
+ return unParseNumber({
2372
+ value: !isNumeric(number) || typeof number === "string" && number.endsWith(".") ? value : roundNumberByMagnitude(number, n),
2373
+ unit,
2374
+ isString,
2375
+ isScientific: isScientificStringNum(value)
2376
+ });
2377
+ };
2378
+ /**
2379
+ * Rounds a numeric value to an appropriate number of digits, based on its size. It rounds to N significant digits,
2380
+ * but never rounds the integer part. Similar to roundByMagnitude, but adds trailing zeros.
2381
+ *
2382
+ * - accepts number types (1.234), stringified numbers ('1.234'), and unit numbers ('1.234|m')
2383
+ * - returns string type (or original value and type when not possible to convert)
2384
+ *
2385
+ * @param value - the value to round
2386
+ * @param [n] - the number of significant digits
2387
+ * @returns rounded value as a string, or input value when unable to round
2388
+ *
2389
+ * @example
2390
+ * roundByMagnitudeToFixed(0.000120016789) -> 0.0001200
2391
+ */
2392
+ const roundByMagnitudeToFixed = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
2393
+ const toFixed = true;
2394
+ if (value === null || Number.isNaN(value) || value === Infinity || value === -Infinity || value === void 0) return value;
2395
+ if (typeof value === "number") return roundNumberByMagnitude(value, n, toFixed);
2396
+ const { number, unit } = parseNumber(value, true);
2397
+ return unParseNumber({
2398
+ value: !isNumeric(number) || typeof number === "string" && number.endsWith(".") ? value : roundNumberByMagnitude(number, n, toFixed),
2399
+ unit,
2400
+ isString: true,
2401
+ isScientific: isScientificStringNum(value)
2402
+ });
2403
+ };
2404
+ /**
2405
+ * Rounds a number to an appropriate number of digits, based on its size in relation to a range.
2406
+ *
2407
+ * @private (see roundByMagnitude() for the public interface)
2408
+ * @param value
2409
+ * @param min
2410
+ * @param max
2411
+ * @param [n] the minimum number of significant digits
2412
+ * @returns rounded number
2413
+ */
2414
+ const roundNumberByRange = (value, min, max, n = DEFAULT_SIGNIFICANT_DIGITS) => {
2415
+ if (isCloseToOrLessThan(max, min)) return value;
2416
+ const range = max - min;
2417
+ return roundNumber(value, Math.max(n, 0 - Math.floor(Math.log10(range))));
2418
+ };
2419
+ /**
2420
+ * Rounds a numeric value to an appropriate number of digits, based on its size within a range of values.
2421
+ *
2422
+ * - accepts number types (1.234), stringified numbers ('1.234'), and unit numbers ('1.234|m')
2423
+ * - returns same type as input
2424
+ *
2425
+ * @param value - the value to round
2426
+ * @param min - the min value in the range
2427
+ * @param max - the max value in the range
2428
+ * @param [n] - the minimum number of significant digits
2429
+ * @returns rounded value, or input value when unable to round
2430
+ *
2431
+ */
2432
+ const roundByRange = (value, min, max, n = DEFAULT_SIGNIFICANT_DIGITS) => {
2433
+ if (typeof value === "number") return roundNumberByRange(value, min, max, n);
2434
+ if (value === null || Number.isNaN(value) || value === Infinity || value === -Infinity || value === void 0) return value;
2435
+ const { number, unit, isString } = parseNumber(value);
2436
+ return unParseNumber({
2437
+ value: !isNumeric(number) || typeof number === "string" && number.endsWith(".") ? value : roundNumberByRange(number, min, max, n),
2438
+ unit,
2439
+ isString,
2440
+ isScientific: isScientificStringNum(value)
2441
+ });
2442
+ };
2443
+ /**
2444
+ * Rounds a numeric value to N fixed decimal digits.
2445
+ *
2446
+ * - accepts number types (1.234), stringified numbers ('1.234'), and unit numbers ('1.234|m')
2447
+ * - returns same type as input
2448
+ *
2449
+ * @param value - the value to round
2450
+ * @param [n] - the number of fixed decimal digits
2451
+ * @returns rounded value, or input value when unable to round
2452
+ *
2453
+ */
2454
+ const roundToFixed = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
2455
+ if (value === null || Number.isNaN(value) || value === Infinity || value === -Infinity || value === void 0) return value;
2456
+ if (typeof value === "number") return value.toFixed(n);
2457
+ const { number, unit, isString } = parseNumber(value);
2458
+ return unParseNumber({
2459
+ value: !isNumeric(number) || typeof number === "string" && number.endsWith(".") ? value : number.toFixed(n),
2460
+ unit,
2461
+ isString,
2462
+ isScientific: isScientificStringNum(value)
2463
+ });
2464
+ };
2465
+ //#endregion
2466
+ //#region src/numbers/format/display-number.ts
2467
+ const DEFAULT_AUTO_SCIENTIFIC_BELOW = 1e-4;
2468
+ const DEFAULT_AUTO_SCIENTIFIC_ABOVE = 1e7;
2469
+ const NUMBER_FORMAT_OPTIONS = { maximumFractionDigits: 20 };
2470
+ const formatEnglishNumber = (value) => {
2471
+ let numberFormat;
2472
+ try {
2473
+ numberFormat = new Intl.NumberFormat("en-US", NUMBER_FORMAT_OPTIONS);
2474
+ } catch {
2475
+ numberFormat = new Intl.NumberFormat(void 0, NUMBER_FORMAT_OPTIONS);
2476
+ }
2477
+ return numberFormat.format(value);
2478
+ };
2479
+ const superscriptSymbols = {
2480
+ "0": "⁰",
2481
+ "1": "¹",
2482
+ "2": "²",
2483
+ "3": "³",
2484
+ "4": "⁴",
2485
+ "5": "⁵",
2486
+ "6": "⁶",
2487
+ "7": "⁷",
2488
+ "8": "⁸",
2489
+ "9": "⁹",
2490
+ "+": "⁺",
2491
+ "-": "⁻"
2492
+ };
2493
+ const appendTrailingZeros = (value, numberOfZeros) => {
2494
+ const zeros = "0".repeat(numberOfZeros);
2495
+ return numberOfZeros > 0 && value !== "0" ? !value.includes(".") ? `${value}.${zeros}` : `${value}${zeros}` : value;
2496
+ };
2497
+ const formatDecimal = (value, thousandSeparator, preserveTrailingZeros = false) => {
2498
+ const convertedValue = formatEnglishNumber(toNum(value)).replaceAll(",", thousandSeparator);
2499
+ return preserveTrailingZeros ? appendTrailingZeros(convertedValue, countTrailingZeros(value, true)) : convertedValue;
2500
+ };
2501
+ const formatDecimalDisplayNumber = (value, options) => {
2502
+ const { nonBreakingSpace } = options ?? {};
2503
+ if (value === "") return value;
2504
+ if (value === null || value === void 0) return "";
2505
+ if (!isValidNum(value)) return trim(value.toString());
2506
+ return formatDecimal(value, options?.noThousandsSeparator ? "" : nonBreakingSpace ? " " : " ", options?.preserveTrailingZeros);
2507
+ };
2508
+ const formatScientificDisplayNumber = (value, options) => {
2509
+ const { roundScientificCoefficient, eNotation } = options ?? {};
2510
+ if (Number.isNaN(value)) return "Invalid";
2511
+ if (value === null || value === void 0) return "";
2512
+ if (!isValidNum(value) || value === "") return trim(value.toString());
2513
+ const sanitizedValue = toNum(value);
2514
+ if (!Number.isFinite(sanitizedValue)) return trim(value.toString());
2515
+ const power = eNotation ? "e" : "·10";
2516
+ const [coefficient, exponent] = sanitizedValue.toExponential().split("e");
2517
+ const roundedCoefficient = typeof roundScientificCoefficient === "number" ? round(coefficient, roundScientificCoefficient) : coefficient;
2518
+ const noExponent = exponent === "+0" || exponent === "-0";
2519
+ const formattedExponent = [...exponent.replaceAll("+", "")].map((c) => eNotation ? c : superscriptSymbols[c]).join("");
2520
+ return noExponent ? roundedCoefficient : `${roundedCoefficient}${power}${formattedExponent}`;
2521
+ };
2522
+ const formatDisplayNumber = (value, options) => {
2523
+ const abs = Math.abs(toNum(value));
2524
+ return (options?.scientific === "auto" && options?.autoScientificBelow && options?.autoScientificAbove ? abs < options?.autoScientificBelow || abs > options?.autoScientificAbove : options?.scientific) ? formatScientificDisplayNumber(value, options) : formatDecimalDisplayNumber(value, options);
2525
+ };
2526
+ /**
2527
+ * Displays a number with human-friendly formatting (use for non-editable display labels, text)
2528
+ *
2529
+ * Accepts number types (1.234), stringified numbers ('1.234'), and unit numbers ('1.234|m')
2530
+ *
2531
+ * @example
2532
+ * //returns '1 234.56'
2533
+ * displayNumber(1234.56)
2534
+ *
2535
+ * By default, adds thousands separators. Can be configured to display in scientific notation, and with formatted units.
2536
+ *
2537
+ * @param value
2538
+ * @param options
2539
+ * @returns formatted display number
2540
+ */
2541
+ const displayNumber = (value, options) => {
2542
+ const optionsWithDefaults = {
2543
+ scientific: options?.scientific ?? "auto",
2544
+ eNotation: options?.eNotation ?? false,
2545
+ autoScientificBelow: options?.autoScientificBelow ?? DEFAULT_AUTO_SCIENTIFIC_BELOW,
2546
+ autoScientificAbove: options?.autoScientificAbove ?? DEFAULT_AUTO_SCIENTIFIC_ABOVE,
2547
+ withUnit: options?.withUnit ?? false,
2548
+ nonBreakingSpace: options?.nonBreakingSpace ?? false,
2549
+ roundScientificCoefficient: options?.roundScientificCoefficient
2550
+ };
2551
+ const { withUnit } = optionsWithDefaults;
2552
+ if (value === null || value === void 0) return "";
2553
+ const { number, unit } = parseNumber(value);
2554
+ const formattedNumber = formatDisplayNumber(number, optionsWithDefaults);
2555
+ const formattedUnit = unit ? LABELS?.[unit] : "";
2556
+ return withUnit && unit ? formattedNumber === "" ? formattedUnit : `${formattedNumber} ${formattedUnit}` : formattedNumber;
2557
+ };
2558
+ /**
2559
+ * Displays a number with human-friendly formatting (use for non-editable display labels, text)
2560
+ *
2561
+ * Accepts number types (1.234), stringified numbers ('1.234'), and unit numbers ('1.234|m')
2562
+ *
2563
+ * @example
2564
+ * //returns '1 234.5600'
2565
+ * displayNumberToFixed('1234.5600')
2566
+ *
2567
+ * By default, adds thousands separators. Can be configured to display in scientific notation, and with formatted units.
2568
+ *
2569
+ * @param value
2570
+ * @param options
2571
+ * @returns formatted display number
2572
+ */
2573
+ const displayNumberToFixed = (value, options) => {
2574
+ const optionsWithDefaults = {
2575
+ scientific: options?.scientific ?? "auto",
2576
+ eNotation: options?.eNotation ?? false,
2577
+ autoScientificBelow: options?.autoScientificBelow ?? DEFAULT_AUTO_SCIENTIFIC_BELOW,
2578
+ autoScientificAbove: options?.autoScientificAbove ?? DEFAULT_AUTO_SCIENTIFIC_ABOVE,
2579
+ withUnit: options?.withUnit ?? false,
2580
+ nonBreakingSpace: options?.nonBreakingSpace ?? false,
2581
+ roundScientificCoefficient: options?.roundScientificCoefficient
2582
+ };
2583
+ const { withUnit } = optionsWithDefaults;
2584
+ if (value === null || value === void 0) return "";
2585
+ const { number, unit } = parseNumber(value, true);
2586
+ const formattedNumber = formatDisplayNumber(number, {
2587
+ ...optionsWithDefaults,
2588
+ preserveTrailingZeros: true
2589
+ });
2590
+ const formattedUnit = unit ? LABELS?.[unit] : "";
2591
+ return withUnit && unit ? formattedNumber === "" ? formattedUnit : `${formattedNumber} ${formattedUnit}` : formattedNumber;
2592
+ };
2593
+ /** @deprecated Use `displayNumber` instead. */
2594
+ const formatNumber = (number) => {
2595
+ return displayNumber(number);
2596
+ };
2597
+ //#endregion
2598
+ //#region src/numbers/numbers.ts
2599
+ const parseValue = (value) => {
2600
+ return typeof value === "string" && isValueWithUnit(value) ? getValue(value) : value;
2601
+ };
2602
+ /**
2603
+ * Checks whether a value can be converted to number type by the toNum() function
2604
+ *
2605
+ * @param value - value to be checked
2606
+ * @returns whether number can be converted by toNum() function
2607
+ *
2608
+ * @example
2609
+ * isValidNum('1 1/2') -> true
2610
+ * toNum('foobar|m') -> false
2611
+ */
2612
+ const isValidNum = (value) => {
2613
+ const parsedValue = parseValue(value);
2614
+ if (isEmptyString(parsedValue) || Number.isNaN(parsedValue) || parsedValue === Infinity || parsedValue === -Infinity) return true;
2615
+ else if (!(isNull(parsedValue) || isUndefined(parsedValue) || isTrailingPeriodSeparator(parsedValue) || isTrailingCommaSeparator(parsedValue) || isArray(parsedValue) || isObject(parsedValue))) {
2616
+ const cleanedValue = cleanNumStr(String(parsedValue));
2617
+ if (cleanedValue.includes("|")) return false;
2618
+ const number = isFraction(cleanedValue) ? numFraction(cleanedValue) : isNumeric(cleanedValue) ? parseFloat(cleanedValue) : cleanedValue;
2619
+ if (number === Infinity || number === -Infinity) return true;
2620
+ if (!isNumeric(number)) return false;
2621
+ if (!Number.isNaN(number)) return true;
2622
+ }
2623
+ return false;
2624
+ };
2625
+ /**
2626
+ * Checks whether a value is a valid number, in string representation with scientific notation (e.g. '1e3')
2627
+ *
2628
+ * Note - it's not possible to check whether *number* types are stored in scientific notation (all numbers are stored
2629
+ * the same way internally in floating-point formats, so there is no difference between 1000 and 1e3 internally).
2630
+ * Whether number types get displayed in scientific notation or not in the console is a browser-specific implementation
2631
+ * detail (display formatting) and not something we can check/rely on, so this function is only intended for checking
2632
+ * user-input values in string format. See https://stackoverflow.com/a/66005705/942635.
2633
+ *
2634
+ * @param value - value to be checked
2635
+ * @returns whether the value is a valid number in scientific notation
2636
+ *
2637
+ * @example
2638
+ * isValidNum('1e3') -> true
2639
+ * toNum(1000) -> false
2640
+ * toNum(1e3) -> false (we cannot check scientific notation of number types)
2641
+ */
2642
+ const isScientificStringNum = (value) => {
2643
+ if (typeof value === "string") return isValidNum(value) && value.toLowerCase().includes("e");
2644
+ return false;
2645
+ };
2646
+ /**
2647
+ * Converts a numeric value to number type (when possible).
2648
+ * - need to know if it's possible first? Call isValidNum()
2649
+ * - accepts number types (1.234), stringified numbers ('1.234'), fractions ('1/2'), and unit numbers ('1.234|m')
2650
+ * - returns the converted number if possible, otherwise returns the input value or default value when provided
2651
+ *
2652
+ * @param value - value to be converted to number type
2653
+ * @param [fallback] - optional fallback value (returned when not possible to convert)
2654
+ * @param [minimum] - optional minimum value
2655
+ * @returns valid number after conversion, or fallback, or returns the original input
2656
+ *
2657
+ * @example
2658
+ * toNum('1.2345) -> 1.2345
2659
+ * toNum('1.2345|m') -> 1.2345
2660
+ */
2661
+ const toNum = (value, fallback, minimum) => {
2662
+ const fallbackResult = fallback ?? value;
2663
+ const parsedValue = parseValue(value);
2664
+ if (!isValidNum(parsedValue)) return fallbackResult;
2665
+ else {
2666
+ const cleanedValue = cleanNumStr(String(parsedValue));
2667
+ const number = isFraction(cleanedValue) ? numFraction(cleanedValue) : isNumeric(cleanedValue) ? parseFloat(cleanedValue) : cleanedValue;
2668
+ if (number === Infinity || number === -Infinity) return number;
2669
+ if (Number.isNaN(number) || !isNumeric(number)) return fallbackResult;
2670
+ else if (minimum && number < minimum) return minimum;
2671
+ return number;
2672
+ }
2673
+ };
2674
+ /**
2675
+ * Convert a number to a string safely, better than String(value)
2676
+ * String(0.0000002) returns '2e-7' which is unwanted if we need to preserve formatting
2677
+ *
2678
+ * @param value
2679
+ * @returns number or string output value
2680
+ */
2681
+ const toString = (value) => {
2682
+ if (isValidNum(value)) {
2683
+ if (typeof value === "string") return value;
2684
+ if (typeof value === "number") {
2685
+ if (Number.isNaN(value) || !Number.isFinite(value)) return String(value);
2686
+ return formatDecimalDisplayNumber(value, { noThousandsSeparator: true });
2687
+ }
2688
+ }
2689
+ return value;
2690
+ };
2691
+ //#endregion
2692
+ //#region src/validate/ajv-validators.ts
2693
+ var import_ucs2length = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports) => {
2694
+ Object.defineProperty(exports, "__esModule", { value: true });
2695
+ function ucs2length(str) {
2696
+ const len = str.length;
2697
+ let length = 0;
2698
+ let pos = 0;
2699
+ let value;
2700
+ while (pos < len) {
2701
+ length++;
2702
+ value = str.charCodeAt(pos++);
2703
+ if (value >= 55296 && value <= 56319 && pos < len) {
2704
+ value = str.charCodeAt(pos);
2705
+ if ((value & 64512) === 56320) pos++;
2706
+ }
2707
+ }
2708
+ return length;
2709
+ }
2710
+ exports.default = ucs2length;
2711
+ ucs2length.code = "require(\"ajv/dist/runtime/ucs2length\").default";
2712
+ })))(), 1);
2713
+ import_ucs2length.default.default ?? import_ucs2length.default;
2714
+ const numberSchemaValidator = validate15;
2715
+ function validate15(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
2716
+ validate15.errors = null;
2717
+ let vErrors = null;
2718
+ let errors = 0;
2719
+ if (!(typeof data == "number" && isFinite(data))) {
2720
+ const err0 = {
2721
+ instancePath,
2722
+ schemaPath: "#/type",
2723
+ keyword: "type",
2724
+ params: { type: "number" },
2725
+ message: "must be number"
2726
+ };
2727
+ if (vErrors === null) vErrors = [err0];
2728
+ else vErrors.push(err0);
2729
+ errors++;
2730
+ }
2731
+ if (errors > 0) {
2732
+ const emErrs0 = [];
2733
+ for (const err1 of vErrors) if (err1.keyword !== "errorMessage" && !err1.emUsed && (err1.instancePath === instancePath || err1.instancePath.indexOf(instancePath) === 0 && err1.instancePath[instancePath.length] === "/") && err1.schemaPath.indexOf("#") === 0 && err1.schemaPath[1] === "/") {
2734
+ emErrs0.push(err1);
2735
+ err1.emUsed = true;
2736
+ }
2737
+ if (emErrs0.length) {
2738
+ const err2 = {
2739
+ instancePath,
2740
+ schemaPath: "#/errorMessage",
2741
+ keyword: "errorMessage",
2742
+ params: { errors: emErrs0 },
2743
+ message: "Must be a numerical value"
2744
+ };
2745
+ if (vErrors === null) vErrors = [err2];
2746
+ else vErrors.push(err2);
2747
+ errors++;
2748
+ }
2749
+ const emErrs1 = [];
2750
+ for (const err3 of vErrors) if (!err3.emUsed) emErrs1.push(err3);
2751
+ vErrors = emErrs1;
2752
+ errors = emErrs1.length;
2753
+ }
2754
+ validate15.errors = vErrors;
2755
+ return errors === 0;
2756
+ }
2757
+ //#endregion
2758
+ //#region src/validate/errors-transform.ts
2759
+ const transformErrors = (errors) => {
2760
+ return errors?.map(({ message }) => message);
2761
+ };
2762
+ //#endregion
2763
+ //#region src/units/validation.ts
2764
+ /** Normalizes repeated decimal dots and decimal commas. */
2765
+ function checkAndCleanDecimalComma(value) {
2766
+ const repeatedDots = /\.{2,}/;
2767
+ const comma = /,/;
2768
+ if (typeof value === "string") while (repeatedDots.test(value) || comma.test(value)) {
2769
+ value = value.replace(repeatedDots, ".");
2770
+ value = value.replace(comma, ".");
2771
+ }
2772
+ return value;
2773
+ }
2774
+ /** Cleans raw numeric input while retaining the unit from the previous value. */
2775
+ function validateAndClean(previousValue, nextText) {
2776
+ const unit = split(previousValue)[1];
2777
+ const cleanedValue = nextText.replace(/[^0-9.,-Ee]/g, "").replace(/^([^(e|E)]*[eE])|[eE]/g, "$1").replace(/^[E|e]*|[E|e]*$/g, "").replace(/,/g, ".").replace(/^([^.]*\.)|\./g, "$1").replace(/\.(?=e)/g, "").replace(/-|[eE]-/g, (match, offset) => offset === 0 || match.toLowerCase() === "e-" ? match : "");
2778
+ return !Number.isFinite(+cleanedValue) ? previousValue : `${cleanedValue}${unit ? "|" : ""}${unit}`;
2779
+ }
2780
+ /** Validates a numeric or unit-encoded value against the package number schema. */
2781
+ function validateNumber(value) {
2782
+ let normalizedValue = value;
2783
+ if (typeof value === "string" && isValueWithUnit(value)) normalizedValue = getValue(value);
2784
+ normalizedValue = checkAndCleanDecimalComma(normalizedValue);
2785
+ if (isNumeric(normalizedValue)) return {
2786
+ valid: numberSchemaValidator(toNum(normalizedValue)),
2787
+ errors: transformErrors(numberSchemaValidator.errors)
2788
+ };
2789
+ return {
2790
+ valid: numberSchemaValidator(normalizedValue),
2791
+ errors: transformErrors(numberSchemaValidator.errors)
2792
+ };
2793
+ }
2794
+ //#endregion
2795
+ //#region src/units/conversion.ts
2796
+ /** Converts a numeric value between compatible units. */
2797
+ function to(value, fromUnit, toUnit) {
2798
+ value = checkAndCleanDecimalComma(value);
2799
+ value = normalizeScientific(value);
2800
+ if (toUnit === "undefined") console.warn("Inconsistent \"to unit\" - debug call to \"Units.to()\"");
2801
+ if (fromUnit === "undefined") {
2802
+ fromUnit = toUnit;
2803
+ console.warn("Inconsistent \"from unit\" - debug call to \"Units.to()\"");
2804
+ }
2805
+ if (fromUnit === toUnit) return toNum(value);
2806
+ if (value === Infinity || value === "Infinity") return Infinity;
2807
+ if (value === -Infinity || value === "-Infinity") return -Infinity;
2808
+ if (isNonNumerical(value) && value !== "") return NaN;
2809
+ const conversion = KNOWN_CONVERSIONS[`${fromUnit}|${toUnit}`];
2810
+ if (conversion) return conversion(toNum(value));
2811
+ if (DEPRECATED_UNITS[fromUnit]) {
2812
+ console.warn(`Unit '${fromUnit}' is deprecated - use '${DEPRECATED_UNITS[fromUnit]}' instead.`);
2813
+ return to(value, DEPRECATED_UNITS[fromUnit], toUnit);
2814
+ }
2815
+ if (DEPRECATED_UNITS[toUnit]) {
2816
+ console.warn(`Unit '${toUnit}' is deprecated - use '${DEPRECATED_UNITS[toUnit]}' instead.`);
2817
+ return to(value, fromUnit, DEPRECATED_UNITS[toUnit]);
2818
+ }
2819
+ if (UNIT_ALIASES[toUnit]) return to(value, fromUnit, UNIT_ALIASES[toUnit]);
2820
+ if (UNIT_ALIASES[fromUnit]) return to(value, UNIT_ALIASES[fromUnit], toUnit);
2821
+ const intermediateFromUnit = INTERMEDIATE_CONVERSIONS[fromUnit];
2822
+ if (intermediateFromUnit) return to(to(value, fromUnit, intermediateFromUnit), intermediateFromUnit, toUnit);
2823
+ const intermediateToUnit = INTERMEDIATE_CONVERSIONS[toUnit];
2824
+ if (toUnit && intermediateToUnit && intermediateToUnit !== toUnit) return to(to(value, fromUnit, intermediateToUnit), intermediateToUnit, toUnit);
2825
+ console.error("no conversions found", value, fromUnit, "->", toUnit);
2826
+ throw new Error(`No conversions found: ${value} ${fromUnit} -> ${toUnit}`);
2827
+ }
2828
+ /** Converts a value with an optional unit suffix to the requested unit. */
2829
+ function unum(valueWithUnit, toUnit, fromUnit) {
2830
+ if (valueWithUnit == null || valueWithUnit === "") return 0;
2831
+ if (typeof valueWithUnit === "string" && valueWithUnit.startsWith("NaN") || typeof valueWithUnit === "number" && isNaN(valueWithUnit)) return NaN;
2832
+ const parts = split(cleanNumStr(normalizeScientific(valueWithUnit)).replaceAll("+", ""));
2833
+ if (!parts) {
2834
+ if (toUnit && fromUnit) return unum(valueWithUnit + fromUnit, toUnit);
2835
+ throw new Error(`unum: invalid number: ${valueWithUnit}`);
2836
+ }
2837
+ if (parts[0] == null) parts[0] = "0";
2838
+ if (parts[1]) fromUnit = parts[1];
2839
+ if (!fromUnit && toUnit !== fromUnit) throw new Error(`unum: unable to figure out unit: ${valueWithUnit} fromUnit ${fromUnit}`);
2840
+ if (toUnit === fromUnit) {
2841
+ const value = parts[0] ? toNum(parts[0]) : 0;
2842
+ if (value === Infinity || value === "Infinity") return Infinity;
2843
+ if (value === -Infinity || value === "-Infinity") return -Infinity;
2844
+ if (typeof value === "string" && EXP_NOTATION_RE.test(value)) return parseFloat(value);
2845
+ if (!isNumeric(value) && value !== Infinity && value !== -Infinity) throw new Error(`unum: invalid number: ${value}, ${typeof value}`);
2846
+ return cleanNum(value);
2847
+ }
2848
+ return to(parts[0], fromUnit, toUnit);
2849
+ }
2850
+ /** Alias for `unum`. */
2851
+ function convertAndGetValue(value, toUnit, fromUnit) {
2852
+ return unum(value, toUnit, fromUnit);
2853
+ }
2854
+ /** Converts a value while preserving string types and empty values. */
2855
+ function convertAndGetValueStrict(value, toUnit, fromUnit) {
2856
+ if (value === "" || value === null) return value;
2857
+ if (typeof value === "string" && isValueWithUnit(value) && getValue(value) === "") return "";
2858
+ const isString = typeof value === "string";
2859
+ const result = convertAndGetValue(value, toUnit, fromUnit);
2860
+ return isString ? toString(result) : result;
2861
+ }
2862
+ /** Converts a value to the base unit configured for a quantity. */
2863
+ function toBase(value, quantity) {
2864
+ const baseUnit = unitFromKey(quantity);
2865
+ return unum(value, baseUnit, split((value || "").toString())[1] || baseUnit);
2866
+ }
2867
+ /** Converts a value and appends the requested unit. */
2868
+ function unumWithUnit(value, toUnit, fromUnit) {
2869
+ return withUnit(unum(value, toUnit, fromUnit), toUnit);
2870
+ }
2871
+ /** Converts a unit value while retaining approximately the input precision. */
2872
+ function convertSamePrecision(valueWithUnit, toUnit, digits) {
2873
+ const validValueWithUnit = String(valueWithUnit);
2874
+ const parts = split(validValueWithUnit);
2875
+ const convertedNumber = !parts[1] || parts[1] == toUnit ? Number(parts[0]) : to(parts[0], String(parts[1]), toUnit);
2876
+ let prettyNumber = "0";
2877
+ let targetDigits = digits;
2878
+ if (convertedNumber !== 0) {
2879
+ if (!targetDigits) {
2880
+ if (parts[1] === toUnit) return validValueWithUnit;
2881
+ const digitParts = String(parts[0]).match(/^[-+.,0]*(\d*)[.,]?(\d*)/);
2882
+ targetDigits = digitParts ? Math.max(3, digitParts[1].length + digitParts[2].length) : 3;
2883
+ }
2884
+ const limit = Math.pow(10, --targetDigits);
2885
+ const absoluteNumber = Math.abs(convertedNumber);
2886
+ if (absoluteNumber >= 1e5 * limit || absoluteNumber * 1e4 * (1 + limit) < limit) prettyNumber = convertedNumber.toExponential(targetDigits);
2887
+ else if (absoluteNumber >= limit) prettyNumber = convertedNumber.toFixed();
2888
+ else {
2889
+ const magnitude = Math.floor(Math.log10(absoluteNumber));
2890
+ prettyNumber = convertedNumber.toFixed(targetDigits - magnitude);
2891
+ let index = prettyNumber.length;
2892
+ if (prettyNumber[--index] == "0") {
2893
+ while (prettyNumber[--index] == "0");
2894
+ prettyNumber = prettyNumber.slice(0, index + (prettyNumber[index] == "." ? 0 : 1));
2895
+ }
2896
+ }
2897
+ }
2898
+ return withUnit(prettyNumber, toUnit);
2899
+ }
2900
+ //#endregion
2901
+ //#region src/units/table-conversion.ts
2902
+ /** Converts every numeric column in a table to a requested unit row. */
2903
+ function convertTable(toUnitRow, table, defaultUnitRow, removeFinalUnitsRow = false) {
2904
+ if (!table || !table.length || !table[0].length) return table;
2905
+ if (!toUnitRow) toUnitRow = table[0];
2906
+ if (!defaultUnitRow) defaultUnitRow = toUnitRow;
2907
+ const firstCell = table[0][0];
2908
+ const firstCellParts = firstCell && split(`${firstCell}`);
2909
+ const tableHasUnits = !(firstCellParts && firstCellParts[0] && isNaN(firstCellParts[1])) && isNaN(table[0][0]);
2910
+ let rowIndex = tableHasUnits ? 1 : 0;
2911
+ const fromUnitRow = tableHasUnits ? table[0] : defaultUnitRow;
2912
+ const convertedTable = [toUnitRow];
2913
+ for (; rowIndex < table.length; rowIndex += 1) {
2914
+ const convertedColumns = Array(toUnitRow.length);
2915
+ const row = table[rowIndex];
2916
+ for (let unitIndex = 0; unitIndex < convertedColumns.length; unitIndex += 1) convertedColumns[unitIndex] = toUnitRow[unitIndex] && row[unitIndex] ? unum(row[unitIndex], toUnitRow[unitIndex], fromUnitRow[unitIndex]) : row[unitIndex];
2917
+ convertedTable.push(convertedColumns);
2918
+ }
2919
+ if (removeFinalUnitsRow) convertedTable.shift();
2920
+ return convertedTable;
2921
+ }
2922
+ //#endregion
2923
+ //#region src/units/formatting.ts
2924
+ /** Rounds a unit string and replaces the unit key with its display label. */
2925
+ function roundNumberWithLabel(value, numberOfDigits = 2) {
2926
+ return displayNumber(round(value, numberOfDigits), { withUnit: true });
2927
+ }
2928
+ /** Returns a value converted to every unit configured for a quantity. */
2929
+ function altUnitsList(value, quantity) {
2930
+ let valueWithUnit = value;
2931
+ if (!getUnit(value)) valueWithUnit = withUnit(value, unitFromQuantity(quantity) ?? "");
2932
+ return (ALT_UNITS[quantity] ?? []).map((unit) => [...split(convertSamePrecision(valueWithUnit, unit)), label(unit)]);
2933
+ }
2934
+ //#endregion
4
2935
  //#region src/numbers/rounding/number-digits.ts
5
2936
  /**
6
2937
  * Calculates a useful decimal precision for small values used by legacy rounding.
@@ -40,82 +2971,82 @@ const COSMETIC_ROUNDING_DEFAULT_PRECISION = 14;
40
2971
  * roundCosmetic('9750.000000000004|m') -> '9750|m'
41
2972
  */
42
2973
  const roundCosmetic = (value) => {
43
- if (require_conversion.isScientificStringNum(value)) return value;
44
- return require_conversion.roundToPrecision(value, COSMETIC_ROUNDING_DEFAULT_PRECISION);
2974
+ if (isScientificStringNum(value)) return value;
2975
+ return roundToPrecision(value, COSMETIC_ROUNDING_DEFAULT_PRECISION);
45
2976
  };
46
2977
  //#endregion
47
2978
  //#region src/index.ts
48
2979
  /* istanbul ignore file */
49
2980
  //#endregion
50
- exports.ALT_UNITS = require_conversion.ALT_UNITS;
51
- exports.DEPRECATED_UNITS = require_conversion.DEPRECATED_UNITS;
52
- exports.EXP_NOTATION_RE = require_conversion.EXP_NOTATION_RE;
53
- exports.INTERMEDIATE_CONVERSIONS = require_conversion.INTERMEDIATE_CONVERSIONS;
54
- exports.KNOWN_CONVERSIONS = require_conversion.KNOWN_CONVERSIONS;
55
- exports.KNOWN_UNITS = require_conversion.KNOWN_UNITS;
56
- exports.LABELS = require_conversion.LABELS;
57
- exports.QUANTITIES_DESCRIPTION = require_conversion.QUANTITIES_DESCRIPTION;
58
- exports.SEPARATOR = require_conversion.SEPARATOR;
59
- exports.UNITS_DESCRIPTION = require_conversion.UNITS_DESCRIPTION;
60
- exports.UNIT_ALIASES = require_conversion.UNIT_ALIASES;
61
- exports.UNIT_FROM_KEY = require_conversion.UNIT_FROM_KEY;
62
- exports.allNumbers = require_conversion.allNumbers;
63
- exports.altUnitsList = require_units.altUnitsList;
64
- exports.asFraction = require_conversion.asFraction;
65
- exports.charCount = require_conversion.charCount;
66
- exports.checkAndCleanDecimalComma = require_conversion.checkAndCleanDecimalComma;
67
- exports.cleanNum = require_conversion.cleanNum;
68
- exports.cleanNumStr = require_conversion.cleanNumStr;
69
- exports.convertAndGetValue = require_conversion.convertAndGetValue;
70
- exports.convertAndGetValueStrict = require_conversion.convertAndGetValueStrict;
71
- exports.convertSamePrecision = require_conversion.convertSamePrecision;
72
- exports.convertTable = require_units.convertTable;
73
- exports.displayNumber = require_conversion.displayNumber;
74
- exports.displayNumberToFixed = require_conversion.displayNumberToFixed;
75
- exports.formatNumber = require_conversion.formatNumber;
76
- exports.fraction = require_conversion.fraction;
77
- exports.getAltUnitsListByQuantity = require_conversion.getAltUnitsListByQuantity;
2981
+ exports.ALT_UNITS = ALT_UNITS;
2982
+ exports.DEPRECATED_UNITS = DEPRECATED_UNITS;
2983
+ exports.EXP_NOTATION_RE = EXP_NOTATION_RE;
2984
+ exports.INTERMEDIATE_CONVERSIONS = INTERMEDIATE_CONVERSIONS;
2985
+ exports.KNOWN_CONVERSIONS = KNOWN_CONVERSIONS;
2986
+ exports.KNOWN_UNITS = KNOWN_UNITS;
2987
+ exports.LABELS = LABELS;
2988
+ exports.QUANTITIES_DESCRIPTION = QUANTITIES_DESCRIPTION;
2989
+ exports.SEPARATOR = SEPARATOR;
2990
+ exports.UNITS_DESCRIPTION = UNITS_DESCRIPTION;
2991
+ exports.UNIT_ALIASES = UNIT_ALIASES;
2992
+ exports.UNIT_FROM_KEY = UNIT_FROM_KEY;
2993
+ exports.allNumbers = allNumbers;
2994
+ exports.altUnitsList = altUnitsList;
2995
+ exports.asFraction = asFraction;
2996
+ exports.charCount = charCount;
2997
+ exports.checkAndCleanDecimalComma = checkAndCleanDecimalComma;
2998
+ exports.cleanNum = cleanNum;
2999
+ exports.cleanNumStr = cleanNumStr;
3000
+ exports.convertAndGetValue = convertAndGetValue;
3001
+ exports.convertAndGetValueStrict = convertAndGetValueStrict;
3002
+ exports.convertSamePrecision = convertSamePrecision;
3003
+ exports.convertTable = convertTable;
3004
+ exports.displayNumber = displayNumber;
3005
+ exports.displayNumberToFixed = displayNumberToFixed;
3006
+ exports.formatNumber = formatNumber;
3007
+ exports.fraction = fraction;
3008
+ exports.getAltUnitsListByQuantity = getAltUnitsListByQuantity;
78
3009
  exports.getNumberOfDigitsToShow = getNumberOfDigitsToShow;
79
- exports.getQuantities = require_conversion.getQuantities;
80
- exports.getUnit = require_conversion.getUnit;
81
- exports.getUnitsForQuantity = require_conversion.getUnitsForQuantity;
82
- exports.getValue = require_conversion.getValue;
83
- exports.isCloseTo = require_conversion.isCloseTo;
84
- exports.isCloseToOrGreaterThan = require_conversion.isCloseToOrGreaterThan;
85
- exports.isCloseToOrLessThan = require_conversion.isCloseToOrLessThan;
86
- exports.isDeepCloseTo = require_conversion.isDeepCloseTo;
87
- exports.isEmptyValueWithUnit = require_conversion.isEmptyValueWithUnit;
88
- exports.isFraction = require_conversion.isFraction;
89
- exports.isNonNumerical = require_conversion.isNonNumerical;
90
- exports.isNumeric = require_conversion.isNumeric;
91
- exports.isScientificStringNum = require_conversion.isScientificStringNum;
92
- exports.isValidNum = require_conversion.isValidNum;
93
- exports.isValueWithUnit = require_conversion.isValueWithUnit;
94
- exports.label = require_conversion.label;
95
- exports.numFraction = require_conversion.numFraction;
96
- exports.round = require_conversion.round;
97
- exports.roundByMagnitude = require_conversion.roundByMagnitude;
98
- exports.roundByMagnitudeToFixed = require_conversion.roundByMagnitudeToFixed;
99
- exports.roundByRange = require_conversion.roundByRange;
3010
+ exports.getQuantities = getQuantities;
3011
+ exports.getUnit = getUnit;
3012
+ exports.getUnitsForQuantity = getUnitsForQuantity;
3013
+ exports.getValue = getValue;
3014
+ exports.isCloseTo = isCloseTo;
3015
+ exports.isCloseToOrGreaterThan = isCloseToOrGreaterThan;
3016
+ exports.isCloseToOrLessThan = isCloseToOrLessThan;
3017
+ exports.isDeepCloseTo = isDeepCloseTo;
3018
+ exports.isEmptyValueWithUnit = isEmptyValueWithUnit;
3019
+ exports.isFraction = isFraction;
3020
+ exports.isNonNumerical = isNonNumerical;
3021
+ exports.isNumeric = isNumeric;
3022
+ exports.isScientificStringNum = isScientificStringNum;
3023
+ exports.isValidNum = isValidNum;
3024
+ exports.isValueWithUnit = isValueWithUnit;
3025
+ exports.label = label;
3026
+ exports.numFraction = numFraction;
3027
+ exports.round = round;
3028
+ exports.roundByMagnitude = roundByMagnitude;
3029
+ exports.roundByMagnitudeToFixed = roundByMagnitudeToFixed;
3030
+ exports.roundByRange = roundByRange;
100
3031
  exports.roundCosmetic = roundCosmetic;
101
- exports.roundNumberWithLabel = require_units.roundNumberWithLabel;
102
- exports.roundToDecimalPrecision = require_conversion.roundToDecimalPrecision;
103
- exports.roundToFixed = require_conversion.roundToFixed;
104
- exports.roundToPrecision = require_conversion.roundToPrecision;
105
- exports.showAltUnitsList = require_conversion.showAltUnitsList;
106
- exports.split = require_conversion.split;
107
- exports.stripLeadingZeros = require_conversion.stripLeadingZeros;
108
- exports.to = require_conversion.to;
109
- exports.toBase = require_conversion.toBase;
110
- exports.toNum = require_conversion.toNum;
111
- exports.toString = require_conversion.toString;
112
- exports.unitFromKey = require_conversion.unitFromKey;
113
- exports.unitFromQuantity = require_conversion.unitFromQuantity;
114
- exports.unum = require_conversion.unum;
115
- exports.unumWithUnit = require_conversion.unumWithUnit;
116
- exports.validateAndClean = require_conversion.validateAndClean;
117
- exports.validateNumber = require_conversion.validateNumber;
118
- exports.withPrettyUnitLabel = require_conversion.withPrettyUnitLabel;
119
- exports.withUnit = require_conversion.withUnit;
3032
+ exports.roundNumberWithLabel = roundNumberWithLabel;
3033
+ exports.roundToDecimalPrecision = roundToDecimalPrecision;
3034
+ exports.roundToFixed = roundToFixed;
3035
+ exports.roundToPrecision = roundToPrecision;
3036
+ exports.showAltUnitsList = showAltUnitsList;
3037
+ exports.split = split;
3038
+ exports.stripLeadingZeros = stripLeadingZeros;
3039
+ exports.to = to;
3040
+ exports.toBase = toBase;
3041
+ exports.toNum = toNum;
3042
+ exports.toString = toString;
3043
+ exports.unitFromKey = unitFromKey;
3044
+ exports.unitFromQuantity = unitFromQuantity;
3045
+ exports.unum = unum;
3046
+ exports.unumWithUnit = unumWithUnit;
3047
+ exports.validateAndClean = validateAndClean;
3048
+ exports.validateNumber = validateNumber;
3049
+ exports.withPrettyUnitLabel = withPrettyUnitLabel;
3050
+ exports.withUnit = withUnit;
120
3051
 
121
3052
  //# sourceMappingURL=index.cjs.map