@oliasoft-open-source/units 4.3.0-beta-2 → 4.3.0-beta-4

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.js CHANGED
@@ -1,2514 +1,2 @@
1
- import Fraction from 'fraction.js';
2
-
3
- const options = { maximumFractionDigits: 20 };
4
- function convertNumberToLocale(number, countryCode) {
5
- let numberFormat;
6
- try {
7
- if (countryCode) {
8
- numberFormat = new Intl.NumberFormat(countryCode, options);
9
- }
10
- } catch {
11
- numberFormat = new Intl.NumberFormat(void 0, options);
12
- }
13
- return numberFormat.format(number);
14
- }
15
-
16
- const parseValue = (value) => {
17
- const isString = typeof value === "string";
18
- const hasUnit = isString && isValueWithUnit(value);
19
- return hasUnit ? getValue(value) : value;
20
- };
21
- const isValidNum = (value) => {
22
- const parsedValue = parseValue(value);
23
- if (isEmptyString(parsedValue) || Number.isNaN(parsedValue) || parsedValue === Infinity || parsedValue === -Infinity) {
24
- return true;
25
- } else {
26
- if (!(isNull(parsedValue) || isUndefined(parsedValue) || isTrailingPeriodSeparator(parsedValue) || isTrailingCommaSeparator(parsedValue) || isArray(parsedValue) || isObject(parsedValue))) {
27
- const cleanedValue = cleanNumStr(String(parsedValue));
28
- if (cleanedValue.includes(SEPARATOR)) {
29
- return false;
30
- }
31
- const number = isFraction(cleanedValue) ? numFraction(cleanedValue) : isNumeric(cleanedValue) ? parseFloat(cleanedValue) : cleanedValue;
32
- if (number === Infinity || number === -Infinity) {
33
- return true;
34
- }
35
- if (!isNumeric(number)) {
36
- return false;
37
- }
38
- if (!Number.isNaN(number)) {
39
- return true;
40
- }
41
- }
42
- }
43
- return false;
44
- };
45
- const isScientificStringNum = (value) => {
46
- if (typeof value === "string") {
47
- return isValidNum(value) && value.toLowerCase().includes("e");
48
- }
49
- return false;
50
- };
51
- const toNum = (value, fallback, minimum) => {
52
- const fallbackResult = fallback ?? value;
53
- const parsedValue = parseValue(value);
54
- if (!isValidNum(parsedValue)) {
55
- return fallbackResult;
56
- } else {
57
- const cleanedValue = cleanNumStr(String(parsedValue));
58
- const number = isFraction(cleanedValue) ? numFraction(cleanedValue) : isNumeric(cleanedValue) ? parseFloat(cleanedValue) : cleanedValue;
59
- if (number === Infinity || number === -Infinity) {
60
- return number;
61
- }
62
- if (Number.isNaN(number) || !isNumeric(number)) {
63
- return fallbackResult;
64
- } else if (minimum && number < minimum) {
65
- return minimum;
66
- }
67
- return number;
68
- }
69
- };
70
- const toString = (value) => {
71
- if (isValidNum(value)) {
72
- if (typeof value === "string") {
73
- return value;
74
- }
75
- if (typeof value === "number") {
76
- if (Number.isNaN(value) || !Number.isFinite(value)) {
77
- return String(value);
78
- }
79
- return formatDecimalDisplayNumber(value, { noThousandsSeparator: true });
80
- }
81
- }
82
- return value;
83
- };
84
-
85
- const countTrailingZeros = (value, decimalPartOnly = false) => {
86
- const condition = decimalPartOnly ? /0+((?=[|eE])|$)/ : /(0+|0+\.0+)((?=[|eE])|$)/;
87
- if (typeof value === "string" && (decimalPartOnly ? value.includes(".") || value.includes(",") : true)) {
88
- return value?.match(condition)?.[0]?.replaceAll(/[.,]/g, "")?.length ?? 0;
89
- }
90
- return 0;
91
- };
92
- const hasTrailingZeros = (value) => {
93
- return countTrailingZeros(value) > 0;
94
- };
95
- const parseNumber = (value, preserveTrailingZeros = false) => {
96
- const isString = typeof value === "string";
97
- const hasUnit = isString && isValueWithUnit(value);
98
- const unit = hasUnit ? getUnit(value) : null;
99
- const cleaned = cleanNumStr(hasUnit ? getValue(value) : value);
100
- const number = preserveTrailingZeros && hasTrailingZeros(value) ? cleaned : toNum(cleaned);
101
- return {
102
- number,
103
- unit,
104
- isString
105
- };
106
- };
107
- const safeStringifyNumber = (value, isScientific) => {
108
- return isScientific ? String(value) : String(toString(value));
109
- };
110
- const unParseNumber = ({
111
- value,
112
- unit,
113
- isString,
114
- isScientific
115
- }) => {
116
- const convertedValue = typeof value === "number" && isString ? safeStringifyNumber(value, isScientific) : value;
117
- if (unit) {
118
- return withUnit(convertedValue, unit);
119
- }
120
- return convertedValue;
121
- };
122
-
123
- const DEFAULT_MAX_RELATIVE_DIFF = Number.EPSILON;
124
- const convertNumbers = (firstValue, secondValue) => {
125
- const { number: firstNumber, unit: firstUnit } = parseNumber(firstValue);
126
- const { number: secondNumber, unit: secondUnit } = parseNumber(secondValue);
127
- const differentUnits = firstUnit && secondUnit && firstUnit !== secondUnit;
128
- const convertedSecondNumber = differentUnits ? convertAndGetValue(secondNumber, firstUnit, secondUnit) : secondNumber;
129
- return {
130
- firstNumber,
131
- secondNumber: convertedSecondNumber
132
- };
133
- };
134
- const getToleranceNumber = (relativeDiff) => {
135
- if (relativeDiff !== null && relativeDiff !== void 0) {
136
- if (isNumeric(relativeDiff) && typeof relativeDiff === "number") {
137
- return relativeDiff;
138
- }
139
- if (isPercentage(relativeDiff)) {
140
- const percentageValue = toNum(relativeDiff?.toString().replace("%", ""));
141
- if (isNumeric(percentageValue)) {
142
- return percentageValue / 100;
143
- }
144
- }
145
- }
146
- return null;
147
- };
148
- const isCloseTo = (firstValue, secondValue, options = { relativeDiff: DEFAULT_MAX_RELATIVE_DIFF }) => {
149
- const { relativeDiff, absoluteDiff } = options;
150
- const diff = relativeDiff ?? absoluteDiff;
151
- const toleranceNumber = getToleranceNumber(diff);
152
- if (firstValue === null || secondValue === null) {
153
- return false;
154
- }
155
- const hasUnitFirstValue = isValueWithUnit(firstValue);
156
- const hasUnitSecondValue = isValueWithUnit(secondValue);
157
- if (hasUnitFirstValue && !hasUnitSecondValue || !hasUnitFirstValue && hasUnitSecondValue) {
158
- throw new Error(`Parameters must either both have units or both not have units. Received "${firstValue}" and "${secondValue}"`);
159
- }
160
- if (toleranceNumber === null) {
161
- console.warn("Tolerance number is not defined!");
162
- return firstValue === secondValue;
163
- }
164
- if (toleranceNumber <= 0 || toleranceNumber < Number.EPSILON) {
165
- throw Error("Unpredictable results - toleranceNumber should be bigger than zero or less then EPSILON");
166
- }
167
- const { firstNumber, secondNumber } = convertNumbers(firstValue, secondValue);
168
- if ((firstNumber === Infinity || firstNumber === "Infinity") && (secondNumber === Infinity || secondNumber === "Infinity") || (firstNumber === -Infinity || firstNumber === "-Infinity") && (secondNumber === -Infinity || secondNumber === "-Infinity")) {
169
- return true;
170
- }
171
- if (typeof firstNumber === "number" && typeof secondNumber === "number") {
172
- if (firstNumber === secondNumber) return true;
173
- if (absoluteDiff || firstNumber === 0 || secondNumber === 0) {
174
- const diff2 = Math.abs(firstNumber - secondNumber);
175
- return isCloseTo(diff2, toleranceNumber, { relativeDiff: "1%" }) || diff2 < toleranceNumber;
176
- } else {
177
- return 2 * Math.abs((firstNumber - secondNumber) / (firstNumber + secondNumber)) < toleranceNumber;
178
- }
179
- }
180
- return false;
181
- };
182
- const isCloseToOrGreaterThan = (firstValue, secondValue, options = { relativeDiff: DEFAULT_MAX_RELATIVE_DIFF }) => {
183
- if (firstValue === null || secondValue === null) {
184
- return false;
185
- }
186
- const { firstNumber, secondNumber } = convertNumbers(firstValue, secondValue);
187
- if (typeof firstNumber === "number" && typeof secondNumber === "number") {
188
- return isCloseTo(firstNumber, secondNumber, options) || firstNumber > secondNumber;
189
- }
190
- return false;
191
- };
192
- const isCloseToOrLessThan = (firstValue, secondValue, options = { relativeDiff: DEFAULT_MAX_RELATIVE_DIFF }) => {
193
- if (firstValue === null || secondValue === null) {
194
- return false;
195
- }
196
- const { firstNumber, secondNumber } = convertNumbers(firstValue, secondValue);
197
- if (typeof firstNumber === "number" && typeof secondNumber === "number") {
198
- return isCloseTo(firstNumber, secondNumber, options) || firstNumber < secondNumber;
199
- }
200
- return false;
201
- };
202
- const isDeepCloseTo = (a, b, options = { relativeDiff: DEFAULT_MAX_RELATIVE_DIFF }) => {
203
- if (Array.isArray(a) && Array.isArray(b)) {
204
- if (a.length !== b.length) {
205
- return false;
206
- }
207
- return a.every((a2, i) => isDeepCloseTo(a2, b[i], options));
208
- }
209
- if (typeof a === "object" && a !== null && typeof b === "object" && b !== null) {
210
- const aKeys = Object.keys(a);
211
- const bKeys = Object.keys(b);
212
- if (aKeys.length !== bKeys.length) {
213
- return false;
214
- }
215
- return aKeys.every((key) => isDeepCloseTo(a[key], b[key], options));
216
- }
217
- if (Number.isNaN(a) && Number.isNaN(b) || a === "" && b === "") {
218
- return true;
219
- }
220
- if (typeof a === "number" && typeof b === "number" || isValueWithUnit(a) && isValueWithUnit(b) || isValidNum(a) && isValidNum(b)) {
221
- return isCloseTo(a, b, options);
222
- }
223
- return true;
224
- };
225
-
226
- const DEFAULT_SIGNIFICANT_DIGITS = 4;
227
- const roundNumber = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
228
- const factor = 10 ** n;
229
- return Math.round(value * factor) / factor;
230
- };
231
- const round = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
232
- if (typeof value === "number") {
233
- return roundNumber(value, n);
234
- }
235
- if (value === null || Number.isNaN(value) || value === Infinity || value === -Infinity || value === void 0) {
236
- return value;
237
- }
238
- const { number, unit, isString } = parseNumber(value);
239
- const result = !isNumeric(number) || typeof number === "string" && number.endsWith(".") ? value : roundNumber(number, n);
240
- return unParseNumber({
241
- value: result,
242
- unit,
243
- isString,
244
- isScientific: isScientificStringNum(value)
245
- });
246
- };
247
- const roundNumberToPrecision = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
248
- return Number(value.toPrecision(n));
249
- };
250
- const roundNumberToFixedPrecision = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
251
- const roundedValue = toNum(value).toPrecision(n);
252
- const [integerPart, decimalPart] = roundedValue.split(".");
253
- if (decimalPart) {
254
- const decimalDigits = n - integerPart.length;
255
- return `${integerPart}.${decimalPart.padEnd(decimalDigits, "0")}`;
256
- } else {
257
- return integerPart;
258
- }
259
- };
260
- const roundNumberToDecimalPrecision = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
261
- if (Math.abs(value) > 1) {
262
- const [integerPart, decimalPart] = formatDecimal(value, "").split(".");
263
- if (!decimalPart) {
264
- return value;
265
- } else {
266
- const roundedDecimalPart = Number(`0.${decimalPart}`).toPrecision(n).slice(1);
267
- return Number(integerPart + roundedDecimalPart);
268
- }
269
- }
270
- return roundNumberToPrecision(value, n);
271
- };
272
- const roundToPrecision = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
273
- if (typeof value === "number") {
274
- return roundNumberToPrecision(value, n);
275
- }
276
- if (value === null || Number.isNaN(value) || value === Infinity || value === -Infinity || value === void 0) {
277
- return value;
278
- }
279
- const { number, unit, isString } = parseNumber(value);
280
- const result = !isNumeric(number) || typeof number === "string" && number.endsWith(".") ? value : roundNumberToPrecision(number, n);
281
- return unParseNumber({
282
- value: result,
283
- unit,
284
- isString,
285
- isScientific: isScientificStringNum(value)
286
- });
287
- };
288
- const roundToDecimalPrecision = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
289
- if (typeof value === "number") {
290
- return roundNumberToDecimalPrecision(value, n);
291
- }
292
- if (value === null || Number.isNaN(value) || value === Infinity || value === -Infinity || value === void 0) {
293
- return value;
294
- }
295
- const { number, unit, isString } = parseNumber(value);
296
- const result = !isNumeric(number) || typeof number === "string" && number.endsWith(".") ? value : roundNumberToDecimalPrecision(number, n);
297
- return unParseNumber({
298
- value: result,
299
- unit,
300
- isString,
301
- isScientific: isScientificStringNum(value)
302
- });
303
- };
304
- const roundNumberByMagnitude = (value, n = DEFAULT_SIGNIFICANT_DIGITS, toFixed = false) => {
305
- const noDecimalsAbove = 10 ** n;
306
- const result = noDecimalsAbove && value > noDecimalsAbove ? roundNumber(value, 0) : toFixed ? roundNumberToFixedPrecision(value, n) : roundNumberToPrecision(value, n);
307
- return toFixed ? String(result) : result;
308
- };
309
- const roundByMagnitude = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
310
- if (typeof value === "number") {
311
- return roundNumberByMagnitude(value, n);
312
- }
313
- if (value === null || Number.isNaN(value) || value === Infinity || value === -Infinity || value === void 0) {
314
- return value;
315
- }
316
- const { number, unit, isString } = parseNumber(value);
317
- const result = !isNumeric(number) || typeof number === "string" && number.endsWith(".") ? value : roundNumberByMagnitude(number, n);
318
- return unParseNumber({
319
- value: result,
320
- unit,
321
- isString,
322
- isScientific: isScientificStringNum(value)
323
- });
324
- };
325
- const roundByMagnitudeToFixed = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
326
- const toFixed = true;
327
- if (value === null || Number.isNaN(value) || value === Infinity || value === -Infinity || value === void 0) {
328
- return value;
329
- }
330
- if (typeof value === "number") {
331
- return roundNumberByMagnitude(value, n, toFixed);
332
- }
333
- const { number, unit } = parseNumber(value, true);
334
- const result = !isNumeric(number) || typeof number === "string" && number.endsWith(".") ? value : roundNumberByMagnitude(number, n, toFixed);
335
- return unParseNumber({
336
- value: result,
337
- unit,
338
- isString: true,
339
- isScientific: isScientificStringNum(value)
340
- });
341
- };
342
- const roundNumberByRange = (value, min, max, n = DEFAULT_SIGNIFICANT_DIGITS) => {
343
- if (isCloseToOrLessThan(max, min)) {
344
- return value;
345
- }
346
- const range = max - min;
347
- const scale = Math.floor(Math.log10(range));
348
- const precision = Math.max(n, 0 - scale);
349
- return roundNumber(value, precision);
350
- };
351
- const roundByRange = (value, min, max, n = DEFAULT_SIGNIFICANT_DIGITS) => {
352
- if (typeof value === "number") {
353
- return roundNumberByRange(value, min, max, n);
354
- }
355
- if (value === null || Number.isNaN(value) || value === Infinity || value === -Infinity || value === void 0) {
356
- return value;
357
- }
358
- const { number, unit, isString } = parseNumber(value);
359
- const result = !isNumeric(number) || typeof number === "string" && number.endsWith(".") ? value : roundNumberByRange(number, min, max, n);
360
- return unParseNumber({
361
- value: result,
362
- unit,
363
- isString,
364
- isScientific: isScientificStringNum(value)
365
- });
366
- };
367
- const roundToFixed = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
368
- if (value === null || Number.isNaN(value) || value === Infinity || value === -Infinity || value === void 0) {
369
- return value;
370
- }
371
- if (typeof value === "number") {
372
- return value.toFixed(n);
373
- }
374
- const { number, unit, isString } = parseNumber(value);
375
- const result = !isNumeric(number) || typeof number === "string" && number.endsWith(".") ? value : number.toFixed(n);
376
- return unParseNumber({
377
- value: result,
378
- unit,
379
- isString,
380
- isScientific: isScientificStringNum(value)
381
- });
382
- };
383
-
384
- const DEFAULT_AUTO_SCIENTIFIC_BELOW = 1e-4;
385
- const DEFAULT_AUTO_SCIENTIFIC_ABOVE = 1e7;
386
- const superscriptSymbols = {
387
- "0": "\u2070",
388
- "1": "\xB9",
389
- "2": "\xB2",
390
- "3": "\xB3",
391
- "4": "\u2074",
392
- "5": "\u2075",
393
- "6": "\u2076",
394
- "7": "\u2077",
395
- "8": "\u2078",
396
- "9": "\u2079",
397
- "+": "\u207A",
398
- "-": "\u207B"
399
- };
400
- const appendTrailingZeros = (value, numberOfZeros) => {
401
- const zeros = "0".repeat(numberOfZeros);
402
- return numberOfZeros > 0 && value !== "0" ? !value.includes(".") ? `${value}.${zeros}` : `${value}${zeros}` : value;
403
- };
404
- const formatDecimal = (value, thousandSeparator, preserveTrailingZeros = false) => {
405
- const convertedValue = convertNumberToLocale(toNum(value), "en-US").replaceAll(",", thousandSeparator);
406
- return preserveTrailingZeros ? appendTrailingZeros(
407
- convertedValue,
408
- countTrailingZeros(value, true)
409
- ) : convertedValue;
410
- };
411
- const formatDecimalDisplayNumber = (value, options) => {
412
- const { nonBreakingSpace } = options ?? {};
413
- if (value === "") {
414
- return value;
415
- }
416
- if (value === null || value === void 0) {
417
- return "";
418
- }
419
- if (!isValidNum(value)) {
420
- return trim(value.toString());
421
- }
422
- const space = options?.noThousandsSeparator ? "" : nonBreakingSpace ? "\u2007" : " ";
423
- return formatDecimal(value, space, options?.preserveTrailingZeros);
424
- };
425
- const formatScientificDisplayNumber = (value, options) => {
426
- const {
427
- roundScientificCoefficient,
428
- eNotation
429
- } = options ?? {};
430
- if (Number.isNaN(value)) {
431
- return "Invalid";
432
- }
433
- if (value === null || value === void 0) {
434
- return "";
435
- }
436
- if (!isValidNum(value) || value === "") {
437
- return trim(value.toString());
438
- }
439
- const sanitizedValue = toNum(value);
440
- if (!Number.isFinite(sanitizedValue)) {
441
- return trim(value.toString());
442
- }
443
- const power = eNotation ? "e" : "\xB710";
444
- const [coefficient, exponent] = sanitizedValue.toExponential().split("e");
445
- const roundedCoefficient = typeof roundScientificCoefficient === "number" ? round(coefficient, roundScientificCoefficient) : coefficient;
446
- const noExponent = exponent === "+0" || exponent === "-0";
447
- const formattedExponent = [...exponent.replaceAll("+", "")].map((c) => eNotation ? c : superscriptSymbols[c]).join("");
448
- return noExponent ? roundedCoefficient : `${roundedCoefficient}${power}${formattedExponent}`;
449
- };
450
- const formatDisplayNumber = (value, options) => {
451
- const abs = Math.abs(toNum(value));
452
- const formatScientific = options?.scientific === "auto" && options?.autoScientificBelow && options?.autoScientificAbove ? abs < options?.autoScientificBelow || abs > options?.autoScientificAbove : options?.scientific;
453
- return formatScientific ? formatScientificDisplayNumber(value, options) : formatDecimalDisplayNumber(value, options);
454
- };
455
- const displayNumber = (value, options) => {
456
- const optionsWithDefaults = {
457
- scientific: options?.scientific ?? "auto",
458
- eNotation: options?.eNotation ?? false,
459
- autoScientificBelow: options?.autoScientificBelow ?? DEFAULT_AUTO_SCIENTIFIC_BELOW,
460
- autoScientificAbove: options?.autoScientificAbove ?? DEFAULT_AUTO_SCIENTIFIC_ABOVE,
461
- withUnit: options?.withUnit ?? false,
462
- nonBreakingSpace: options?.nonBreakingSpace ?? false,
463
- roundScientificCoefficient: options?.roundScientificCoefficient
464
- };
465
- const { withUnit } = optionsWithDefaults;
466
- if (value === null || value === void 0) {
467
- return "";
468
- }
469
- const { number, unit } = parseNumber(value);
470
- const formattedNumber = formatDisplayNumber(number, optionsWithDefaults);
471
- const formattedUnit = unit ? LABELS?.[unit] : "";
472
- return withUnit && unit ? formattedNumber === "" ? formattedUnit : `${formattedNumber} ${formattedUnit}` : formattedNumber;
473
- };
474
- const displayNumberToFixed = (value, options) => {
475
- const optionsWithDefaults = {
476
- scientific: options?.scientific ?? "auto",
477
- eNotation: options?.eNotation ?? false,
478
- autoScientificBelow: options?.autoScientificBelow ?? DEFAULT_AUTO_SCIENTIFIC_BELOW,
479
- autoScientificAbove: options?.autoScientificAbove ?? DEFAULT_AUTO_SCIENTIFIC_ABOVE,
480
- withUnit: options?.withUnit ?? false,
481
- nonBreakingSpace: options?.nonBreakingSpace ?? false,
482
- roundScientificCoefficient: options?.roundScientificCoefficient
483
- };
484
- const { withUnit } = optionsWithDefaults;
485
- if (value === null || value === void 0) {
486
- return "";
487
- }
488
- const preserveTrailingZeros = true;
489
- const { number, unit } = parseNumber(value, preserveTrailingZeros);
490
- const formattedNumber = formatDisplayNumber(number, {
491
- ...optionsWithDefaults,
492
- preserveTrailingZeros: true
493
- });
494
- const formattedUnit = unit ? LABELS?.[unit] : "";
495
- return withUnit && unit ? formattedNumber === "" ? formattedUnit : `${formattedNumber} ${formattedUnit}` : formattedNumber;
496
- };
497
-
498
- const isNull = (str) => str === null;
499
- const isUndefined = (str) => str === void 0;
500
- const isArray = (str) => str && str.constructor === Array;
501
- const isObject = (str) => str && str.constructor === Object;
502
- const isEmptyString = (str) => str === "";
503
- const isTrailingPeriodSeparator = (str) => str && str[str.length - 1] === ".";
504
- const isTrailingCommaSeparator = (str) => str && str[str.length - 1] === ",";
505
- const isPercentage = (value) => typeof value === "string" && /^\d+(\.\d+)?%$/.test(value);
506
- function isEmptyValueWithUnit(val) {
507
- return typeof val === "string" && val.length > 0 && val.startsWith("|");
508
- }
509
- const trimWhiteSpace = (value) => value.trim().replace(/\s+/g, " ");
510
- const isFraction = (value) => {
511
- if (typeof value !== "string") {
512
- return false;
513
- }
514
- if (!value.includes("/")) {
515
- return false;
516
- }
517
- try {
518
- new Fraction(trimWhiteSpace(value));
519
- return true;
520
- } catch (error) {
521
- return error.message === "Division by Zero";
522
- }
523
- };
524
- function isNumeric(v) {
525
- if (v === void 0 || v === null || Array.isArray(v) || typeof v === "object" || Number.isNaN(v) || v === "NaN" || v === Infinity || v === -Infinity || v === "Infinity" || v === "-Infinity") {
526
- return false;
527
- }
528
- if (isFraction(v)) {
529
- return true;
530
- }
531
- const parsed = parseFloat(v);
532
- return typeof v === "string" ? !isNaN(parsed) && (EXP_NOTATION_RE.test(v) || isFinite(v)) : isFinite(v);
533
- }
534
- function allNumbers(arr) {
535
- return !arr.some((val) => typeof val !== "number");
536
- }
537
- const formatNumber = (number) => displayNumber(number);
538
- function charCount(chr, str) {
539
- const single_char = (chr + "")[0];
540
- let total = 0;
541
- let last_location = str.indexOf(single_char, 0) + 1;
542
- while (last_location > 0) {
543
- last_location = str.indexOf(single_char, last_location) + 1;
544
- total += 1;
545
- }
546
- return total;
547
- }
548
- function getNumberOfDigitsToShow(num, maxNumDigits = 20) {
549
- const defaultDigits = Math.min(4, maxNumDigits);
550
- let digits = defaultDigits;
551
- if (typeof num !== "number") {
552
- return defaultDigits;
553
- }
554
- const numStr = String(num);
555
- const RegExForExponentialNumber = /-?[0-9.,]*[Ee]-?[0-9]+/;
556
- if (RegExForExponentialNumber.test(numStr)) {
557
- while (Math.abs(num) * 10 ** digits < 1 && digits < maxNumDigits) {
558
- digits++;
559
- }
560
- return Math.min(digits + (defaultDigits - 1), maxNumDigits);
561
- }
562
- if (num > 1 || num < -1) {
563
- return defaultDigits;
564
- }
565
- for (let i = 2; i < numStr.length; i++) {
566
- const element = numStr[i];
567
- if (element !== "0") {
568
- return Math.min(maxNumDigits, digits + i - 2);
569
- }
570
- }
571
- return digits;
572
- }
573
- function fraction(str) {
574
- if (str instanceof Array || str === null || str === void 0) {
575
- return NaN;
576
- }
577
- if (typeof str === "string") {
578
- str = trimWhiteSpace(str);
579
- }
580
- if (str === "") {
581
- return NaN;
582
- }
583
- let result = NaN;
584
- let infinite = false;
585
- try {
586
- const fractionObject = new Fraction(str);
587
- if (fractionObject !== void 0) {
588
- result = fractionObject.valueOf();
589
- }
590
- } catch (e) {
591
- if (e instanceof Error && e.message === "Division by Zero") {
592
- infinite = true;
593
- }
594
- }
595
- return infinite ? Infinity : result;
596
- }
597
- function asFraction(str) {
598
- if (typeof str === "string") {
599
- str = trimWhiteSpace(str);
600
- }
601
- if (str === "") {
602
- str = "0";
603
- }
604
- return new Fraction(str).toFraction(true);
605
- }
606
- function numFraction(str) {
607
- if (str instanceof Array || str === null || str === void 0 || str === "" || str === Infinity || str === -Infinity || str === "Infinity" || str === "-Infinity" || Number.isNaN(str) || str === "NaN") {
608
- return str;
609
- }
610
- if (typeof str === "string") {
611
- str = trimWhiteSpace(str);
612
- }
613
- let result = str;
614
- try {
615
- const fractionObject = new Fraction(str);
616
- if (fractionObject !== void 0) {
617
- result = fractionObject.valueOf();
618
- }
619
- } catch (error) {
620
- if (error.message === "Division by Zero") {
621
- const minus = str.charAt(0) === "-";
622
- return minus ? -Infinity : Infinity;
623
- }
624
- console.warn("Error in numFraction() method: ", str);
625
- }
626
- return result.valueOf();
627
- }
628
- const trim = (value) => value.trim().replace(/[\t\r\n]/g, "");
629
- function cleanNumStr(str) {
630
- let cleanString = trim(str + "");
631
- const slashCount = charCount("/", cleanString);
632
- const spaceCount = charCount(" ", cleanString) + charCount("\xA0", cleanString);
633
- let dotcount = charCount(".", cleanString);
634
- let commacount = charCount(",", cleanString);
635
- if (slashCount === 0 && spaceCount > 0) {
636
- cleanString = cleanString.replace(/\s/g, "");
637
- }
638
- if (commacount > 1) {
639
- cleanString = cleanString.replace(/,/g, "");
640
- }
641
- if (dotcount > 1) {
642
- cleanString = cleanString.replace(/\./g, "");
643
- }
644
- commacount = charCount(",", cleanString);
645
- dotcount = charCount(".", cleanString);
646
- if (dotcount === 1 && commacount === 1) {
647
- if (cleanString.indexOf(",") > cleanString.indexOf(".")) {
648
- cleanString = cleanString.replace(".", "");
649
- cleanString = cleanString.replace(",", ".");
650
- } else {
651
- cleanString = cleanString.replace(",", "");
652
- }
653
- if (cleanString.indexOf(".") === 0) {
654
- cleanString = 0 + cleanString;
655
- }
656
- return cleanString;
657
- }
658
- if (!dotcount && commacount) {
659
- cleanString = cleanString.replace(",", ".");
660
- }
661
- if (cleanString.indexOf(".") === 0) {
662
- cleanString = 0 + cleanString;
663
- }
664
- return cleanString;
665
- }
666
- const stripLeadingZeros = (value) => {
667
- const isMinus = value?.[0] === "-";
668
- const matchMinus = /^-/mg;
669
- const matchLeadingZeros = /^(?:0+(?=[1-9])|0+(?=0))/mg;
670
- const cleanedValue = value.replace(matchMinus, "").replace(matchLeadingZeros, "");
671
- return isMinus ? `-${cleanedValue}` : cleanedValue;
672
- };
673
- function cleanNum(str) {
674
- if (typeof str === "number") {
675
- return str;
676
- }
677
- return parseFloat(cleanNumStr(str));
678
- }
679
- const isNonNumerical = (value) => !isNumeric(value);
680
- const { abs, exp, sqrt } = Math;
681
- function newton(f, df, x0, tol = 1e-8, max_iter = 30) {
682
- let X = x0;
683
- let iter = 0;
684
- let err = 1;
685
- while (err > tol && iter < max_iter) {
686
- const X_new = X - f(X) / df(X);
687
- err = abs(f(X_new) - f(X));
688
- if (err < tol) {
689
- return [X_new, true, iter];
690
- } else {
691
- X = X_new;
692
- }
693
- iter++;
694
- }
695
- return [x0, false, iter];
696
- }
697
- function erf(z) {
698
- const t = 1 / (1 + 0.5 * abs(z));
699
- const ans = 1 - t * exp(-(z ** 2) - 1.26551223 + t * (1.00002368 + t * (0.37409196 + t * (0.09678418 + t * (-0.18628806 + t * (0.27886807 + t * (-1.13520398 + t * (1.48851587 + t * (-0.82215223 + t * 0.17087277)))))))));
700
- return z >= 0 ? ans : -ans;
701
- }
702
- function get_k_from_conf_int(a) {
703
- const f = (k) => a - erf(k / sqrt(2));
704
- const df = (k) => -sqrt(2 / Math.PI) * exp(-0.5 * k ** 2);
705
- const [t0] = newton(f, df, 1);
706
- return t0;
707
- }
708
- function get_conf_int_from_k(k) {
709
- return erf(k / sqrt(2));
710
- }
711
-
712
- const LABELS = Object.freeze({
713
- in: "in",
714
- mm: "mm",
715
- cm: "cm",
716
- m: "m",
717
- microM: "\u03BCm",
718
- km: "km",
719
- ft: "ft",
720
- usft: "usft",
721
- in2: "in\xB2",
722
- cm2: "cm\xB2",
723
- m2: "m\xB2",
724
- kg: "kg",
725
- tonnes: "t",
726
- mt: "mt",
727
- kip: "kip",
728
- bbl: "bbl",
729
- m3: "m\xB3",
730
- Mm3: "Mm\xB3",
731
- MMSCF: "MMSCF",
732
- lbm: "lbm",
733
- "kg/mol": "kg/mol",
734
- "lbf/mol": "lbf/mol",
735
- sg: "sg",
736
- ppg: "ppg",
737
- "kg/m3": "kg/m\xB3",
738
- "lbm/ft3": "lbm/ft\xB3",
739
- s: "s",
740
- min: "min",
741
- h: "h",
742
- d: "d",
743
- month: "month",
744
- year: "year",
745
- "bbl/ft": "bbl/ft",
746
- lpm: "L/min",
747
- lps: "L/s",
748
- bpm: "bbl/min",
749
- "m3/min": "m\xB3/min",
750
- "m3/s": "m\xB3/s",
751
- MMSCFD: "MMSCFD",
752
- bar: "Bar",
753
- Pa: "Pa",
754
- kPa: "kPa",
755
- MPa: "MPa",
756
- GPa: "GPa",
757
- kPsi: "Psi",
758
- ksi: "ksi",
759
- "lbf/100ft2": "lbf/100ft\xB2",
760
- "1/Pa": "Pa\u207B\xB9",
761
- "1/kPa": "kPa\u207B\xB9",
762
- "1/MPa": "MPa\u207B\xB9",
763
- "1/GPa": "GPa\u207B\xB9",
764
- "1/psi": "psi\u207B\xB9",
765
- "kPa/m": "kPa/m",
766
- "1/bar": "bar\u207B\xB9",
767
- klbf: "klbf",
768
- "psi/ft": "Psi/ft",
769
- "bar/100m": "bar/100m",
770
- "psi/100ft": "psi/100ft",
771
- "kPa/100m": "kPa/100m",
772
- C: "\xB0C",
773
- F: "\xB0F",
774
- K: "K",
775
- "C/100m": "\xB0C/100m",
776
- "C/m": "\xB0C/m",
777
- "Pa/C": "Pa/\xB0C",
778
- "Bar/C": "Bar/\xB0C",
779
- "psi/F": "psi/\xB0F",
780
- "psi/C": "psi/\xB0C",
781
- "F/100ft": "\xB0F/100ft",
782
- "F/ft": "\xB0F/ft",
783
- "K/100m": "K/100m",
784
- "K/m": "K/m",
785
- "lbf/ft": "lbf/ft",
786
- N: "N",
787
- kN: "kN",
788
- "N/m": "N/m",
789
- "daN/m": "daN/m",
790
- lbf: "lbf",
791
- kgf: "kgf",
792
- rad: "rad",
793
- "BTU/lbm": "BTU/lbm",
794
- ppf: "ppf",
795
- "kg/m": "kg/m",
796
- "E-06/degC": "10\u207B\u2076/\xB0C",
797
- "E-06/degF": "10\u207B\u2076/\xB0F",
798
- "1/K": "K\u207B\xB9",
799
- km2: "km\xB2",
800
- ft2: "ft\xB2",
801
- mm2: "mm\xB2",
802
- mile2: "mile\xB2",
803
- ft3: "ft\xB3",
804
- "g/cm3": "g/cm\xB3",
805
- Sm3: "Sm\xB3",
806
- "ft3/s": "ft\xB3/s",
807
- "ft3/d": "ft\xB3/d",
808
- "m3/d": "m\xB3/d",
809
- "1/m3/d": "1/m\xB3/d",
810
- "s/m3": "s/m\xB3",
811
- "1/MMSCFD": "1/MMSCFD",
812
- "bbl/d": "bbl/d",
813
- tonneForce: "tonne-force",
814
- USGal: "US gal",
815
- "g/mol": "g/mol",
816
- Nm: "N\u22C5m",
817
- kNm: "kN\u22C5m",
818
- ftlbf: "ft\u22C5lbf",
819
- "J/(kg*degC)": "J/(kg\u22C5\xB0C)",
820
- "J/(kg*degK)": "J/(kg\u22C5K)",
821
- "J/(s*m*degK)": "J/(s\u22C5m\u22C5K)",
822
- "BTU/(lbm*degF)": "BTU/(lbm\u22C5\xB0F)",
823
- "BTU/(h*ft*degF)": "BTU/(h\u22C5ft\u22C5\xB0F)",
824
- l: "L",
825
- "l/m": "L/m",
826
- "kJ/kg": "kJ/kg",
827
- "J/kg": "J/kg",
828
- deg: "\xB0",
829
- "W/(mK)": "W/(m\u22C5K)",
830
- psi: "psi",
831
- "deg/100ft": "\xB0/100ft",
832
- "deg/30m": "\xB0/30m",
833
- "deg/10m": "\xB0/10m",
834
- "%": "%",
835
- Hz: "Hz",
836
- "1/s": "1/s",
837
- rpm: "rpm",
838
- "Pa/m": "Pa/m",
839
- "bar/m": "bar/m",
840
- gpm: "gpm",
841
- "kg/s": "kg/s",
842
- "lbm/s": "lbm/s",
843
- "deg/m": "\xB0/m",
844
- "deg/ft": "\xB0/ft",
845
- "rad/m": "rad/m",
846
- "rad/ft": "rad/ft",
847
- "dyn/cm": "dyn/cm",
848
- "mN/m": "mN/m",
849
- "m/s": "m/s",
850
- "ft/s": "ft/s",
851
- "m/min": "m/min",
852
- "ft/min": "ft/min",
853
- "m/h": "m/h",
854
- "ft/h": "ft/h",
855
- mph: "mph",
856
- "km/h": "km/h",
857
- "m/s2": "m/s\xB2",
858
- "ft/s2": "ft/s\xB2",
859
- "Pa*s": "Pa\u22C5s",
860
- P: "P",
861
- "mPa*s": "mPa\u22C5s",
862
- cP: "cP",
863
- W: "W",
864
- hhp: "hhp",
865
- hp: "hp",
866
- kW: "kW",
867
- MW: "MW",
868
- "BTU/h": "BTU/h",
869
- "W/m2": "W/m\xB2",
870
- "hhp/in2": "hhp/in\xB2",
871
- "hhp/ft2": "hhp/ft\xB2",
872
- "Mm3/d": "Mm\xB3/d",
873
- "STB/d": "STB/d",
874
- "Sm3/d": "Sm\xB3/d",
875
- "MSm3/d": "MSm\xB3/d",
876
- "SCF/STB": "SCF / STB",
877
- "Sm3/Sm3": "Sm\xB3 / Sm\xB3",
878
- "SCF/d": "SCF/d",
879
- STB: "STB",
880
- SCF: "SCF",
881
- MSm3: "MSm\xB3",
882
- Gsg: "sg",
883
- Gppg: "ppg",
884
- "Gkg/m3": "kg/m\xB3",
885
- "Glbm/ft3": "lbm/ft\xB3",
886
- "lb/ft3": "lb/ft\xB3",
887
- "\xB0N": "\xB0N",
888
- "\xB0S": "\xB0S",
889
- "\xB0W": "\xB0W",
890
- "\xB0E": "\xB0E",
891
- fr: " ",
892
- mD: "mD",
893
- CI: "CI",
894
- Sigma: "\u03C3",
895
- "Sm3/d/bar": "Sm\xB3/d/bar",
896
- "STB/d/psi": "STB/d/psi",
897
- "m3/s/bar": "m\xB3/s/bar",
898
- "lb/ft": "lb/ft",
899
- "E-09/bar": "10\u207B\u2079/bar",
900
- "E-10/psi": "10\u207B\xB9\u2070/psi",
901
- "E-14/pa": "10\u207B\xB9\u2074/pa",
902
- "m3/m": " m\xB3/m",
903
- "cm3/m": "cm\xB3/m",
904
- "mm3/m": "mm\xB3/m",
905
- "ft3/ft": "ft\xB3/ft",
906
- "in3/ft": "in\xB3/ft",
907
- lk: "lk",
908
- ftCla: "ftCla",
909
- lkCla: "lkCla",
910
- ftSe: "ftSe",
911
- ydSe: "ydSe",
912
- chSe: "chSe",
913
- "chSe(T)": "chSe(T)",
914
- ftGC: "ftGC",
915
- ydInd: "ydInd",
916
- "d/stand": "d/stand",
917
- "h/stand": "h/stand",
918
- "min/stand": "min/stand",
919
- "s/stand": "s/stand",
920
- "m3/t": "m3/t",
921
- "L/100kg": "L/100kg"
922
- });
923
- const ALT_UNITS = Object.freeze({
924
- acceleration: ["ft/s2", "m/s2"],
925
- angleGradient: ["deg/30m", "rad/m", "deg/m", "deg/ft", "rad/ft", "deg/100ft", "deg/10m"],
926
- angles: ["deg", "rad"],
927
- areaOther: ["in2", "ft2", "mm2", "cm2", "m2", "mile2", "km2"],
928
- areaTubular: ["in2", "cm2", "ft2", "m2"],
929
- blowoutFlowRate: [
930
- "lpm",
931
- "bpm",
932
- "m3/min",
933
- "ft3/s",
934
- "m3/s",
935
- "MMSCFD",
936
- "ft3/d",
937
- "m3/d",
938
- "bbl/d",
939
- "Mm3/d",
940
- "STB/d",
941
- "Sm3/d",
942
- "MSm3/d",
943
- "SCF/d"
944
- ],
945
- blowoutGasFlowRate: ["MMSCFD", "Sm3/d", "MSm3/d", "SCF/d"],
946
- blowoutOilFlowRate: ["Sm3/d", "STB/d"],
947
- deg: ["deg", "rad"],
948
- density: ["sg", "ppg", "kg/m3", "lbm/ft3", "g/cm3", "lb/ft3", "kPa/m"],
949
- densityGas: ["Gsg", "Gppg", "Gkg/m3", "Glbm/ft3"],
950
- densityOil: ["sg", "ppg", "kg/m3", "lbm/ft3"],
951
- densityOilGas: ["ppg", "kg/m3", "lbm/ft3"],
952
- densitySolid: ["sg", "ppg", "kg/m3", "lbm/ft3"],
953
- depth: ["m", "ft"],
954
- diameters: ["in", "m", "cm", "ft", "mm"],
955
- distance: ["m", "ft"],
956
- dls: ["deg/10m", "deg/30m", "deg/100ft"],
957
- doglegSeverity: ["deg/10m", "deg/30m", "deg/100ft"],
958
- duration: ["s", "h", "d", "min"],
959
- durationShort: ["s", "min", "h", "d"],
960
- durationLong: ["min", "h", "d", "month", "year"],
961
- flowrate: [
962
- "lpm",
963
- "gpm",
964
- "bpm",
965
- "ft3/d",
966
- "ft3/s",
967
- "m3/s",
968
- "m3/d",
969
- "m3/min",
970
- "Mm3/d",
971
- "bbl/d",
972
- "MMSCFD",
973
- "STB/d",
974
- "Sm3/d",
975
- "MSm3/d",
976
- "SCF/d"
977
- ],
978
- fluidCompressibility: ["1/bar", "1/psi", "1/Pa", "1/kPa", "1/MPa", "1/GPa"],
979
- force: ["tonnes", "lbf", "kgf", "N", "kN", "tonneForce", "klbf"],
980
- forceGradient: ["lbf/ft", "N/m"],
981
- frequency: ["Hz"],
982
- gasVolume: ["MMSCF", "Sm3", "MSm3", "SCF"],
983
- gor: ["Sm3/Sm3", "SCF/STB"],
984
- height: ["m", "ft"],
985
- intensity: ["W/m2", "hhp/in2", "hhp/ft2"],
986
- interfacialTension: ["dyn/cm", "N/m", "lbf/ft", "mN/m"],
987
- latitude: ["\xB0N", "\xB0S"],
988
- length: ["m", "cm", "ft", "km", "in", "mm"],
989
- linearCapacity: ["l/m", "bbl/ft"],
990
- longitude: ["\xB0E", "\xB0W"],
991
- massFlowRate: ["kg/s", "lbm/s"],
992
- moleWeight: ["kg/mol", "lbf/mol", "g/mol"],
993
- oilVolume: ["STB", "Sm3"],
994
- percentage: ["%", "fr"],
995
- permeability: ["mD", "m2"],
996
- power: ["hp", "W", "hhp", "MW", "kW", "BTU/h"],
997
- pressure: ["bar", "psi", "Pa", "kPa", "MPa", "ksi", "GPa", "lbf/100ft2"],
998
- pressureGradient: ["bar/100m", "Pa/m", "bar/m", "psi/100ft", "psi/ft", "kPa/m"],
999
- pressurechange: ["bar", "psi", "Pa", "MPa", "kPa"],
1000
- gasliftFlowRate: ["STB/d", "Sm3/d", "SCF/d"],
1001
- productionFlowRate: ["MMSCFD", "STB/d", "Sm3/d", "MSm3/d", "SCF/d"],
1002
- productionFlowRateOil: ["MMSCFD", "STB/d", "Sm3/d", "MSm3/d", "SCF/d"],
1003
- productionFlowRateGas: ["MMSCFD", "STB/d", "Sm3/d", "MSm3/d", "SCF/d"],
1004
- injectionFlowRate: ["lpm", "lps", "bpm", "gpm", "MMSCFD", "STB/d", "Sm3/d", "MSm3/d", "SCF/d"],
1005
- pumpRate: ["lpm", "lps", "bpm", "m3/s", "ft3/s", "gpm"],
1006
- rotationalSpeed: ["rpm", "Hz"],
1007
- roughness: ["m", "microM", "in"],
1008
- rpm: ["rpm", "Hz"],
1009
- sdstats: ["CI", "Sigma"],
1010
- specificHeatCapacity: [
1011
- "J/(kg*degC)",
1012
- "J/(kg*degK)",
1013
- "BTU/(lbm*degF)"
1014
- ],
1015
- speed: ["km/h", "ft/min", "mph", "ft/h", "ft/s", "m/min", "m/s", "m/h"],
1016
- inverseStandSpeed: ["d/stand", "h/stand", "min/stand", "s/stand"],
1017
- rop: ["ft/h", "ft/min", "ft/s", "km/h", "m/h", "m/min", "m/s", "mph"],
1018
- stress: ["MPa", "kPa", "psi", "bar", "Pa", "ksi", "lbf/100ft2"],
1019
- temperature: ["C", "F", "K"],
1020
- pressurePerTemperature: ["Pa/C", "Bar/C", "psi/F", "psi/C"],
1021
- tempgrad: ["C/100m", "F/100ft", "K/100m", "C/m", "F/ft", "K/m"],
1022
- thermalConductivity: [
1023
- "BTU/(h*ft*degF)",
1024
- "W/(mK)"
1025
- ],
1026
- thermalExpansionCoefficient: ["E-06/degC", "E-06/degF", "1/K"],
1027
- torque: ["Nm", "ftlbf", "kNm"],
1028
- torqueGradient: ["N", "lbf", "tonnes"],
1029
- turbulentSkin: ["s/m3", "1/m3/d", "1/MMSCFD"],
1030
- viscosity: ["Pa*s", "P", "mPa*s", "cP"],
1031
- inflowProductivityIndex: ["Sm3/d/bar", "STB/d/psi", "m3/s/bar"],
1032
- volume: [
1033
- "m3",
1034
- "bbl",
1035
- "Mm3",
1036
- "l",
1037
- "USGal",
1038
- "ft3",
1039
- "STB",
1040
- "Sm3",
1041
- "MMSCF",
1042
- "MSm3",
1043
- "SCF"
1044
- ],
1045
- kickToleranceVolume: [
1046
- "m3",
1047
- "bbl",
1048
- "USGal",
1049
- "ft3",
1050
- "STB",
1051
- "Sm3",
1052
- "SCF"
1053
- ],
1054
- weight: ["tonnes", "kg", "lbf", "mt", "kip", "N"],
1055
- weightGradient: ["ppf", "kg/m"],
1056
- wgrad: ["sg", "ppg"],
1057
- wltubulars: ["ppf", "kg/m"],
1058
- youngsModulus: ["Pa", "psi"],
1059
- massPerLength: ["kg/m", "lb/ft"],
1060
- wearFactor: ["E-09/bar", "E-10/psi", "E-14/pa"],
1061
- volumeGradient: ["m3/m", "cm3/m", "mm3/m", "ft3/ft", "in3/ft"],
1062
- shearStress: ["Pa", "lbf/100ft2"],
1063
- location: ["lk", "ftCla", "lkCla", "ftSe", "ydSe", "chSe", "chSe(T)", "ftGC", "ydInd", "ft", "m", "usft"],
1064
- mixingRequirements: ["m3/t", "L/100kg"],
1065
- entalphy: ["J/kg", "kJ/kg", "BTU/lbm"]
1066
- });
1067
- const UNIT_FROM_KEY = Object.freeze({
1068
- density: "sg",
1069
- densityGas: "Gsg",
1070
- densityOil: "sg",
1071
- densityOilGas: "kg/m3",
1072
- densitySolid: "kg/m3",
1073
- length: "m",
1074
- roughness: "m",
1075
- speed: "m/s",
1076
- diameters: "in",
1077
- duration: "s",
1078
- durationShort: "h",
1079
- durationLong: "d",
1080
- pressurechange: "bar",
1081
- temperature: "C",
1082
- tempgrad: "C/100m",
1083
- volume: "m3",
1084
- kickToleranceVolume: "m3",
1085
- weight: "kg",
1086
- force: "N",
1087
- wgrad: "sg",
1088
- wltubulars: "ppf",
1089
- flowrate: "lpm",
1090
- permeability: "mD",
1091
- // MilliDarcy
1092
- interfacialTension: "dyn/cm",
1093
- // Dynes per centimeter
1094
- deg: "deg",
1095
- dls: "deg/30m",
1096
- percentage: "%",
1097
- latitude: "\xB0N",
1098
- longitude: "\xB0E",
1099
- torque: "Nm",
1100
- rpm: "rpm",
1101
- testSingleUnit: "m",
1102
- //test value for a unit with no alt_units
1103
- turbulentSkin: "1/m3/d",
1104
- pressurePerTemperature: "Pa/C",
1105
- sdstats: "Sigma",
1106
- acceleration: "m/s2",
1107
- massFlowRate: "kg/s",
1108
- angleGradient: "deg/m",
1109
- viscosity: "Pa*s",
1110
- weightGradient: "kg/m",
1111
- intensity: "W/m2",
1112
- gor: "Sm3/Sm3",
1113
- inflowProductivityIndex: "Sm3/d/bar",
1114
- wearFactor: "E-09/psi",
1115
- location: "m",
1116
- inverseStandSpeed: "s/stand",
1117
- mixingRequirements: "m3/t",
1118
- entalphy: "J/kg",
1119
- shearStress: "Pa",
1120
- volumeGradient: "m3/m"
1121
- });
1122
- const C = Object.freeze({
1123
- g: 0.0980665175317196,
1124
- ft_to_m: 0.3048,
1125
- inch_to_m: 0.0254,
1126
- lbf_to_kg: 0.45359237,
1127
- // https://en.wikipedia.org/wiki/Pound_(force)
1128
- kg_to_lbf: 2.20462262184877,
1129
- // https://en.wikipedia.org/wiki/Pound_(force)
1130
- ppf_to_kgm: 0.45359237 / 0.3048,
1131
- kg_cm3: 0.0293984025938081,
1132
- bar_to_psi: 14.503773773022,
1133
- // https://en.wikipedia.org/wiki/Pound_per_square_inch
1134
- bar_to_pascal: 1e5,
1135
- sg_to_ppg: 8.345404265,
1136
- bbl_to_m3: 0.158987294928,
1137
- // https://en.wikipedia.org/wiki/Unit_of_volume
1138
- USGal_to_m3: 0.003785411784,
1139
- // https://en.wikipedia.org/wiki/Unit_of_volume
1140
- kelvin_to_degrees: 273.15,
1141
- tonnes_to_pascal: 9806.65,
1142
- therm_exp_coeff: 1242e-8,
1143
- psi_to_pascal: 6894.757293168361,
1144
- // ((0.45359237 kg x 9.80665 m/s²)/lbf) / (0.0254 m/in)²
1145
- ft3_to_m3: 0.028316846592,
1146
- // https://en.wikipedia.org/wiki/Unit_of_volume
1147
- ft3_to_in3: 1728,
1148
- // https://en.wikipedia.org/wiki/Cubic_inch
1149
- day_to_second: 60 * 60 * 24,
1150
- m3_per_m_to_ft3_per_ft: 10.763910416709722,
1151
- // https://www.wolframalpha.com/input?i=cubic+meter+per+meter++to+feet+cubic+per+foot&assumption=%7B%22F%22%2C+%22UnitsConversion2%22%2C+%22fromValue%22%7D+-%3E%220.100000000000000000%22
1152
- in3_per_ft_to_m3_per_m: 537633333333e-16
1153
- // 1 / m3_per_m_to_ft3_per_ft / ft3_to_in3 = 0.000053763333333333334 https://www.wolframalpha.com/input?i=cubic+meter+per+meter++to+feet+cubic+per+foot&assumption=%7B%22F%22%2C+%22UnitsConversion2%22%2C+%22fromValue%22%7D+-%3E%220.100000000000000000%22
1154
- });
1155
- const KNOWN_CONVERSIONS = Object.freeze({
1156
- // LENGTH
1157
- "m|mm": (val) => val * 1e3,
1158
- "m|cm": (val) => val * 100,
1159
- "m|km": (val) => val / 1e3,
1160
- "m|ft": (val) => val / C.ft_to_m,
1161
- "m|in": (val) => val / C.inch_to_m,
1162
- "m|microM": (val) => val * 1e6,
1163
- "mm|m": (val) => val / 1e3,
1164
- "cm|m": (val) => val / 100,
1165
- "km|m": (val) => val * 1e3,
1166
- "ft|m": (val) => val * C.ft_to_m,
1167
- "in|m": (val) => val * C.inch_to_m,
1168
- "microM|m": (val) => val / 1e6,
1169
- // AREA
1170
- "m2|mm2": (val) => val * 1e6,
1171
- "m2|cm2": (val) => val * 1e4,
1172
- "m2|km2": (val) => val / 1e6,
1173
- "m2|in2": (val) => val * 1550.0031,
1174
- "m2|ft2": (val) => val * 10.76391,
1175
- "m2|mile2": (val) => val * 3861022e-13,
1176
- "mm2|m2": (val) => val / 1e6,
1177
- "cm2|m2": (val) => val / 1e4,
1178
- "km2|m2": (val) => val * 1e6,
1179
- "in2|m2": (val) => val / 1550.0031,
1180
- "ft2|m2": (val) => val / 10.76391,
1181
- "mile2|m2": (val) => val / 3861022e-13,
1182
- // VOLUME
1183
- "m3|bbl": (val) => val / C.bbl_to_m3,
1184
- "m3|ft3": (val) => val / C.ft3_to_m3,
1185
- "m3|l": (val) => val * 1e3,
1186
- "m3|Mm3": (val) => val / 1e6,
1187
- "m3|USGal": (val) => val / C.USGal_to_m3,
1188
- "bbl|m3": (val) => val * C.bbl_to_m3,
1189
- "ft3|m3": (val) => val * C.ft3_to_m3,
1190
- "Mm3|m3": (val) => val * 1e6,
1191
- "l|m3": (val) => val / 1e3,
1192
- "USGal|m3": (val) => val * C.USGal_to_m3,
1193
- "m3|Sm3": (val) => val * 1,
1194
- "m3|STB": (val) => val * 6.289512957422142,
1195
- // 42089843750 / 6692067261 = 6.289512957422142, // https://www.wolframalpha.com/input?i=stb
1196
- "Sm3|m3": (val) => val * 1,
1197
- "STB|m3": (val) => val * 0.1589948230919721,
1198
- //6692067261 / 42089843750 = 0.15899482309197216, // https://www.wolframalpha.com/input?i=stb
1199
- "m3|MMSCF": (val) => val * 1e6 / C.ft3_to_m3,
1200
- "m3|MSm3": (val) => val * 1e-6,
1201
- "m3|SCF": (val) => val / C.ft3_to_m3,
1202
- "MMSCF|m3": (val) => val * 1e-6 * C.ft3_to_m3,
1203
- "MSm3|m3": (val) => val * 1e6,
1204
- "SCF|m3": (val) => val * C.ft3_to_m3,
1205
- // DENSITY
1206
- "kg/m3|sg": (val) => val * 1e-3,
1207
- "kg/m3|g/cm3": (val) => val * 1e-3,
1208
- "kg/m3|lbm/ft3": (val) => val / 16.01846337,
1209
- "kg/m3|lb/ft3": (val) => val / 16.01846337,
1210
- "kg/m3|ppg": (val) => val * 0.008345404265,
1211
- "sg|kg/m3": (val) => val * 1e3,
1212
- "g/cm3|kg/m3": (val) => val * 1e3,
1213
- "lbm/ft3|kg/m3": (val) => val * 16.01846337,
1214
- "lb/ft3|kg/m3": (val) => val * 16.01846337,
1215
- "ppg|kg/m3": (val) => val / 0.008345404265,
1216
- "sg|kPa/m": (val) => val * 9.81,
1217
- "kPa/m|sg": (val) => val / 9.81,
1218
- // GAS DENSITY
1219
- "Gkg/m3|Gsg": (val) => val / 1.225,
1220
- "Gkg/m3|Glbm/ft3": (val) => val / 16.0176516725,
1221
- "Gkg/m3|Gppg": (val) => val / 119.8659491193,
1222
- "Gsg|Gkg/m3": (val) => val * 1.225,
1223
- "Glbm/ft3|Gkg/m3": (val) => val * 16.0176516725,
1224
- "Gppg|Gkg/m3": (val) => val * 119.8659491193,
1225
- // WLTUBULARS
1226
- "ppf|kg/m": (val) => val * 0.45359237 / 0.3048,
1227
- "kg/m|ppf": (val) => val * 1 / (0.45359237 / 0.3048),
1228
- "kg/m|lbf/ft": (val) => val / 0.67196897675131,
1229
- "lbf/ft|kg/m": (val) => val * 0.67196897675131,
1230
- // PRESSURE / STRESS
1231
- "Pa|psi": (val) => val / C.psi_to_pascal,
1232
- "psi|Pa": (val) => val * C.psi_to_pascal,
1233
- "Pa|bar": (val) => val * 1e-5,
1234
- "Pa|kPa": (val) => val * 1e-3,
1235
- "Pa|MPa": (val) => val * 1e-6,
1236
- "Pa|GPa": (val) => val * 1e-9,
1237
- "bar|Pa": (val) => val * 1e5,
1238
- "kPa|Pa": (val) => val * 1e3,
1239
- "MPa|Pa": (val) => val * 1e6,
1240
- "GPa|Pa": (val) => val * 1e9,
1241
- "psi|ksi": (val) => val / 1e3,
1242
- "ksi|psi": (val) => val * 1e3,
1243
- "psi|lbf/100ft2": (val) => val * 14400,
1244
- // psi = lbf/in², 1 ft² = 144 in² https://en.wikipedia.org/wiki/Square_foot
1245
- "lbf/100ft2|psi": (val) => val / 14400,
1246
- // FLUID COMPRESSIBILITY
1247
- "1/psi|1/Pa": (val) => val / C.psi_to_pascal,
1248
- "1/bar|1/Pa": (val) => val * 1e-5,
1249
- "1/kPa|1/Pa": (val) => val * 1e-3,
1250
- "1/MPa|1/Pa": (val) => val * 1e-6,
1251
- "1/GPa|1/Pa": (val) => val * 1e-9,
1252
- "1/Pa|1/psi": (val) => val * C.psi_to_pascal,
1253
- "1/Pa|1/bar": (val) => val * 1e5,
1254
- "1/Pa|1/kPa": (val) => val * 1e3,
1255
- "1/Pa|1/MPa": (val) => val * 1e6,
1256
- "1/Pa|1/GPa": (val) => val * 1e9,
1257
- // TEMPERATURE
1258
- "C|F": (val) => val * 1.8 + 32,
1259
- "F|C": (val) => (val - 32) * 5 / 9,
1260
- "K|C": (val) => val - C.kelvin_to_degrees,
1261
- "C|K": (val) => val + C.kelvin_to_degrees,
1262
- // TEMPERATURE GRADIENT
1263
- "C/100m|F/100ft": (val) => val * 1.8 * C.ft_to_m,
1264
- "F/100ft|C/100m": (val) => val * 5 / 9 / C.ft_to_m,
1265
- "C/100m|C/m": (val) => val / 100,
1266
- "C/m|C/100m": (val) => val * 100,
1267
- "C/100m|F/ft": (val) => val * 1.8 / 100 * C.ft_to_m,
1268
- "F/ft|C/100m": (val) => val * 5 / 9 * 100 / C.ft_to_m,
1269
- "C/100m|K/m": (val) => val / 100,
1270
- "K/m|C/100m": (val) => val * 100,
1271
- "K/100m|C/100m": (val) => val,
1272
- "C/100m|K/100m": (val) => val,
1273
- // PRESSURE PER TEMPERATURE
1274
- "Pa/C|Bar/C": (val) => val * 1e-5,
1275
- "Pa/C|psi/F": (val) => val / 1.8 / C.psi_to_pascal,
1276
- "Pa/C|psi/C": (val) => val / C.psi_to_pascal,
1277
- // https://en.wikipedia.org/wiki/Pound_per_square_inch
1278
- "Bar/C|Pa/C": (val) => val * 1e5,
1279
- "psi/F|Pa/C": (val) => val * 1.8 * C.psi_to_pascal,
1280
- "psi/C|Pa/C": (val) => val * C.psi_to_pascal,
1281
- // ((0.45359237 kg x 9.80665 m/s²)/lbf) / (0.0254 m/in)²
1282
- "psi/F|psi/C": (val) => val * 1.8,
1283
- "psi/C|psi/F": (val) => val / 1.8,
1284
- // WEIGHTf
1285
- "kg|kgf": (val) => val,
1286
- "kg|lbf": (val) => val * C.kg_to_lbf,
1287
- "kg|t": (val) => val / 1e3,
1288
- "kg|tonnes": (val) => val / 1e3,
1289
- "kg|mt": (val) => val / 1e3,
1290
- /*
1291
- 1 kip = 1000 lbf - https://en.wikipedia.org/wiki/Kip_(unit)
1292
- */
1293
- "kg|kip": (val) => val * C.kg_to_lbf * 1e-3,
1294
- "kgf|kg": (val) => val,
1295
- "lbf|kg": (val) => val * C.lbf_to_kg,
1296
- "t|kg": (val) => val * 1e3,
1297
- "tonnes|kg": (val) => val * 1e3,
1298
- "mt|kg": (val) => val * 1e3,
1299
- "kip|kg": (val) => val * 1e3 * C.lbf_to_kg,
1300
- "tonnes|lbf": (val) => val * 1e3 * C.kg_to_lbf,
1301
- "lbf|tonnes": (val) => val * C.lbf_to_kg / 1e3,
1302
- "t|lbf": (val) => val * 1e3 * C.kg_to_lbf,
1303
- "lbf|t": (val) => val * C.lbf_to_kg / 1e3,
1304
- "mt|lbf": (val) => val * 1e3 * C.kg_to_lbf,
1305
- "lbf|mt": (val) => val / (1e3 * C.kg_to_lbf),
1306
- "kgf|lbf": (val) => val * C.kg_to_lbf,
1307
- "lbf|kgf": (val) => val * C.lbf_to_kg,
1308
- "kg|g": (val) => val * 1e3,
1309
- "g|kg": (val) => val / 1e3,
1310
- "kgf|t": (val) => val / 1e3,
1311
- "t|kgf": (val) => val * 1e3,
1312
- "kgf|tonnes": (val) => val / 1e3,
1313
- "tonnes|kgf": (val) => val * 1e3,
1314
- // MASS PER LENGTH
1315
- "kg/m|lb/ft": (val) => val * 1.4881639435695537,
1316
- "lb/ft|kg/m": (val) => val * 0.6719689751395069,
1317
- "kg|N": (val) => val * C.g * 100,
1318
- "N|kg": (val) => val / (C.g * 100),
1319
- // DISTANCE PER TIME
1320
- "m/s|km/h": (val) => val * 3.6,
1321
- "km/h|m/s": (val) => val / 3.6,
1322
- "m/s|ft/s": (val) => val / C.ft_to_m,
1323
- "m/s|ft/min": (val) => val * 60 / C.ft_to_m,
1324
- "m/s|ft/h": (val) => val * 3600 / C.ft_to_m,
1325
- "m/s|m/min": (val) => val * 60,
1326
- "m/s|m/h": (val) => val * 3600,
1327
- "ft/s|m/s": (val) => val * C.ft_to_m,
1328
- "ft/min|m/s": (val) => val * C.ft_to_m / 60,
1329
- "ft/h|m/s": (val) => val * C.ft_to_m / 3600,
1330
- "m/min|m/s": (val) => val / 60,
1331
- "m/h|m/s": (val) => val / 3600,
1332
- "m/s|mph": (val) => val * 2.2369362920544,
1333
- "mph|m/s": (val) => val / 2.2369362920544,
1334
- "ft/h|ft/d": (val) => val * 24,
1335
- "ft/d|ft/h": (val) => val / 24,
1336
- "ft/h|m/h": (val) => val * C.ft_to_m,
1337
- "m/h|ft/h": (val) => val / C.ft_to_m,
1338
- "ft/d|m/h": (val) => val * C.ft_to_m / 24,
1339
- "m/h|ft/d": (val) => val * 24 / C.ft_to_m,
1340
- "ft/d|m/d": (val) => val * C.ft_to_m,
1341
- "m/d|ft/d": (val) => val / C.ft_to_m,
1342
- "m/h|m/d": (val) => val * 24,
1343
- "m/d|m/h": (val) => val / 24,
1344
- // LINEAR CAPACITY
1345
- "l/m|bbl/ft": (val) => val * 0.0019171343228277056,
1346
- "bbl/ft|l/m": (val) => val / 0.0019171343228277056,
1347
- // FLOW RATES
1348
- "m3/s|ft3/s": (val) => val / C.ft3_to_m3,
1349
- "m3/s|lpm": (val) => val * 6e4,
1350
- "m3/s|bpm": (val) => val * 377.388646,
1351
- "m3/s|m3/min": (val) => val * 60,
1352
- "m3/s|m3/d": (val) => val * C.day_to_second,
1353
- "m3/s|bbl/d": (val) => val * 543439.6505653338,
1354
- "m3/s|ft3/d": (val) => val * C.day_to_second / C.ft3_to_m3,
1355
- "m3/s|gpm": (val) => val * 25e11 / 157725491,
1356
- // https://www.wolframalpha.com/input?i=m3%2Fs+
1357
- "m3/s|MMSCFD": (val) => val / 0.32774128,
1358
- "m3/s|STB/d": (val) => val * 1346875e8 / 247854343,
1359
- "m3/s|Sm3/d": (val) => val * C.day_to_second,
1360
- "m3/s|MSm3/d": (val) => val / 11.59722222222222,
1361
- "m3/s|SCF/d": (val) => val * 3.0511872047366146e6,
1362
- "ft3/s|m3/s": (val) => val * C.ft3_to_m3,
1363
- "lpm|m3/s": (val) => val / 6e4,
1364
- "lps|lpm": (val) => val * 60,
1365
- "lpm|lps": (val) => val / 60,
1366
- "bpm|m3/s": (val) => val / 377.388646,
1367
- "m3/d|m3/s": (val) => val / C.day_to_second,
1368
- "m3/min|m3/s": (val) => val / 60,
1369
- "bbl/d|m3/s": (val) => val / C.day_to_second * C.bbl_to_m3,
1370
- "ft3/d|m3/s": (val) => val / C.day_to_second * C.ft3_to_m3,
1371
- "ft3/d|m3/d": (val) => val * C.ft3_to_m3,
1372
- "m3/d|ft3/d": (val) => val / C.ft3_to_m3,
1373
- "m3/d|ft3/s": (val) => val / C.ft3_to_m3 / C.day_to_second,
1374
- "gpm|m3/s": (val) => val * 157725491 / 25e11,
1375
- // https://www.wolframalpha.com/input?i=m3%2Fs+
1376
- "MMSCFD|m3/s": (val) => val * 0.32774128,
1377
- "Mm3/d|m3/d": (val) => val * 1e6,
1378
- "m3/d|Mm3/d": (val) => val * 1e-6,
1379
- /*
1380
- exact formula is 247854343 / 134687500000000 = 0.0000018402178598607888 - https://www.wolframalpha.com/input?i=STB%2Fd
1381
- STB has a lot of intermediate conversions, so to avoid delta during conversions trip we have to store 2 more digits
1382
- */
1383
- "STB/d|m3/s": (val) => val * 184021785986e-17,
1384
- "Sm3/d|m3/d": (val) => val,
1385
- // At a pressure of 101.325 kPa (760 Torr) and DIN 1343: a temperature of 273.15 K (0°C/32°F) | NOTE: Thomas suggested that we leep those conversions 1to1,
1386
- "m3/d|Sm3/d": (val) => val,
1387
- // because the calculated rate is the rate at standard conditions
1388
- "Sm3/d|m3/s": (val) => val / C.day_to_second,
1389
- "MSm3/d|Sm3/d": (val) => val * 1e6,
1390
- "Sm3/d|MSm3/d": (val) => val * 1e-6,
1391
- "MSm3/d|m3/s": (val) => val * 11.59722222222222,
1392
- "SCF/d|m3/s": (val) => val * 32774128e-14,
1393
- // TURBULENT SKIN
1394
- "1/m3/d|1/MMSCFD": (val) => val * 28316.85,
1395
- "1/MMSCFD|1/m3/d": (val) => val / 28316.85,
1396
- "s/m3|1/m3/d": (val) => val / 86400,
1397
- "1/m3/d|s/m3": (val) => val * 86400,
1398
- // MASS FLOW RATES
1399
- "kg/s|lbm/s": (val) => val * 2.20462262,
1400
- "lbm/s|kg/s": (val) => val / 2.20462262,
1401
- // PERMEABILITY
1402
- "mD|m2": (val) => val * 9869233e-19,
1403
- // https://en.wikipedia.org/wiki/Darcy_(unit)
1404
- "m2|mD": (val) => val / 9869233e-19,
1405
- // GRADIENTS - Force / INTERFACIAL TENSION:
1406
- "N/m|lbf/ft": (val) => val * 0.22480894387096 * C.ft_to_m,
1407
- "lbf/ft|N/m": (val) => val / 0.22480894387096 / C.ft_to_m,
1408
- "dyn/cm|mN/m": (val) => val,
1409
- "mN/m|dyn/cm": (val) => val,
1410
- "dyn/cm|N/m": (val) => val * 1e-3,
1411
- "N/m|dyn/cm": (val) => val * 1e3,
1412
- "mN/m|N/m": (val) => val * 1e-3,
1413
- "N/m|mN/m": (val) => val * 1e3,
1414
- // TORQUE
1415
- "Nm|ftlbf": (val) => val * 0.737562058700684,
1416
- "Nm|kNm": (val) => val / 1e3,
1417
- "kNm|Nm": (val) => val * 1e3,
1418
- "ftlbf|Nm": (val) => val / 0.737562058700684,
1419
- // FORCE
1420
- "N|kN": (val) => val * 1e-3,
1421
- "N|kgf": (val) => val * 2e4 / 196133,
1422
- // https://www.wolframalpha.com/input?i=newtons
1423
- "N|lbf": (val) => val * 2e12 / 8896443230521,
1424
- // https://www.wolframalpha.com/input?i=newtons
1425
- "kN|lbf": (val) => val * 1e3 * 2e12 / 8896443230521,
1426
- "N|tonneForce": (val) => val * 20 / 196133,
1427
- // https://www.wolframalpha.com/input?i=tonneForce
1428
- "kN|N": (val) => val / 1e-3,
1429
- "kgf|N": (val) => val * 196133 / 2e4,
1430
- // https://www.wolframalpha.com/input?i=kgf
1431
- "lbf|N": (val) => val * 8896443230521 / 2e12,
1432
- // https://www.wolframalpha.com/input?i=newtons
1433
- "lbf|kN": (val) => val * 8896443230521 / (2e12 * 1e3),
1434
- "lbf|tonneForce": (val) => val * 45359237 / 1e11,
1435
- // https://www.wolframalpha.com/input?i=tonneForce
1436
- "klbf|tonneForce": (val) => val * 45359237 / (1e11 * 1e-3),
1437
- "tonneForce|N": (val) => val * 196133 / 20,
1438
- // https://www.wolframalpha.com/input?i=tonneForce
1439
- "tonneForce|lbf": (val) => val * 1e11 / 45359237,
1440
- //https://www.wolframalpha.com/input?i=tonneForce
1441
- "tonneForce|klbf": (val) => val * 1e11 / (45359237 * 1e3),
1442
- // https://www.wolframalpha.com/input?i=tonneForce
1443
- "klbf|lbf": (val) => val * 1e3,
1444
- "lbf|klbf": (val) => val / 1e3,
1445
- // DURATION
1446
- "s|min": (val) => val / 60,
1447
- "s|h": (val) => val / 3600,
1448
- "s|d": (val) => val / (24 * 3600),
1449
- "min|s": (val) => val * 60,
1450
- "h|s": (val) => val * 3600,
1451
- "d|s": (val) => val * 24 * 3600,
1452
- "year|d": (val) => val * 365.25,
1453
- "d|year": (val) => val / 365.25,
1454
- "year|month": (val) => val * 12,
1455
- "month|year": (val) => val / 12,
1456
- "month|d": (val) => val * 30.4375,
1457
- "d|month": (val) => val / 30.4375,
1458
- // TIME/STAND DURATION
1459
- "s/stand|min/stand": (val) => val / 60,
1460
- "s/stand|h/stand": (val) => val / 3600,
1461
- "s/stand|d/stand": (val) => val / 86400,
1462
- "min/stand|s/stand": (val) => val * 60,
1463
- "h/stand|s/stand": (val) => val * 3600,
1464
- "d/stand|s/stand": (val) => val * 86400,
1465
- "min/stand|h/stand": (val) => val / 60,
1466
- "min/stand|d/stand": (val) => val / 1440,
1467
- "h/stand|min/stand": (val) => val * 60,
1468
- "h/stand|d/stand": (val) => val / 24,
1469
- "d/stand|min/stand": (val) => val * 1440,
1470
- "d/stand|h/stand": (val) => val * 24,
1471
- // PERCENTAGE / FRACTIONS
1472
- "%|fr": (val) => val * 0.01,
1473
- "fr|%": (val) => val / 0.01,
1474
- // DEGREES
1475
- "deg|rad": (val) => val * Math.PI / 180,
1476
- "rad|deg": (val) => val * 180 / Math.PI,
1477
- // POWER
1478
- "W|hp": (val) => val / 745.699872,
1479
- "hp|W": (val) => val * 745.699872,
1480
- "W|kW": (val) => val / 1e3,
1481
- "W|MW": (val) => val / 1e6,
1482
- "kW|W": (val) => val * 1e3,
1483
- "MW|W": (val) => val * 1e6,
1484
- "W|BTU/h": (val) => val * 3.4121416351331,
1485
- "BTU/h|W": (val) => val / 3.4121416351331,
1486
- "hhp|hp": (val) => val,
1487
- // hydraulic horsepower is just horsepower
1488
- "hp|hhp": (val) => val,
1489
- // NAVIGATION
1490
- "\xB0N|\xB0S": (val) => val,
1491
- "\xB0S|\xB0N": (val) => val,
1492
- "\xB0W|\xB0E": (val) => val,
1493
- "\xB0E|\xB0W": (val) => val,
1494
- // Specific Heat Capacity
1495
- "BTU/(Kg*K)|BTU/(lbm*degF)": (val) => val / 4186.798188,
1496
- "BTU/(lbm*degF)|J/(kg*degC)": (val) => val * 4186.798188,
1497
- "BTU/(lbm*degF)|BTU/(Kg*K)": (val) => val * 4186.798188,
1498
- "J/(kg*degK)|J/(kg*degC)": (val) => val,
1499
- "J/(kg*degC)|BTU/(lbm*degF)": (val) => val / 4186.798188,
1500
- "J/(kg*degC)|J/(kg*degK)": (val) => val,
1501
- "J/(kg*degC)|J/(s*m*degK)": (val) => val,
1502
- // Thermal conductivity
1503
- "BTU/(h*ft*degF)|W/(mK)": (val) => val * 1.7295772056,
1504
- "BTU/(h*ft*degF)|J/(s*m*degK)": (val) => val * 1.7295772056,
1505
- "W/(mK)|BTU/(h*ft*degF)": (val) => val / 1.7295772056,
1506
- "W/(mK)|J/(s*m*degK)": (val) => val,
1507
- "W/(m*degK)|J/(s*m*degK)": (val) => val,
1508
- "W/(m*degK)|BTU/(h*ft*degF)": (val) => val / 1.7295772056,
1509
- "J/(s*m*degK)|BTU/(h*ft*degF)": (val) => val / 1.7295772056,
1510
- "J/(s*m*degK)|W/(m*degK)": (val) => val,
1511
- "J/(s*m*degK)|W/(mK)": (val) => val,
1512
- "J/(s*m*degK)|J/(kg*degC)": (val) => val,
1513
- // THERMAL EXPANSION
1514
- "E-06/degF|E-06/degC": (val) => val * 1.8,
1515
- "E-06/degC|E-06/degF": (val) => val / 1.8,
1516
- "E-06/degC|1/K": (val) => val / 1e6,
1517
- "1/K|E-06/degC": (val) => val * 1e6,
1518
- // FREQUENCY
1519
- "rpm|Hz": (val) => val / 60,
1520
- "Hz|rpm": (val) => val * 60,
1521
- // Confidence interval
1522
- "CI|Sigma": (val) => get_k_from_conf_int(val),
1523
- "Sigma|CI": (val) => get_conf_int_from_k(val),
1524
- // Mole weight:
1525
- "g/mol|kg/mol": (val) => val / 1e3,
1526
- "kg/mol|g/mol": (val) => val * 1e3,
1527
- "lbf/mol|kg/mol": (val) => val / C.kg_to_lbf,
1528
- "kg/mol|lbf/mol": (val) => val * C.kg_to_lbf,
1529
- // Acceleration:
1530
- "m/s2|ft/s2": (val) => val / C.ft_to_m,
1531
- "ft/s2|m/s2": (val) => val * C.ft_to_m,
1532
- // Viscosity:
1533
- "Pa*s|P": (val) => val * 10,
1534
- "P|Pa*s": (val) => val / 10,
1535
- "mPa*s|Pa*s": (val) => val / 1e3,
1536
- "Pa*s|mPa*s": (val) => val * 1e3,
1537
- "cP|Pa*s": (val) => val * 1e-3,
1538
- "Pa*s|cP": (val) => val / 1e-3,
1539
- // GRADIENTS - Pressure:
1540
- "Pa/m|bar/m": (val) => val * 1e-5,
1541
- "bar/m|Pa/m": (val) => val * 1e5,
1542
- "Pa/m|kPa/m": (val) => val / 1e3,
1543
- "kPa/m|Pa/m": (val) => val * 1e3,
1544
- "Pa/m|bar/100m": (val) => val * 1e-3,
1545
- "bar/100m|Pa/m": (val) => val * 1e3,
1546
- "bar/m|bar/100m": (val) => val * 100,
1547
- "bar/100m|bar/m": (val) => val / 100,
1548
- "psi/ft|Pa/m": (val) => val * C.psi_to_pascal / C.ft_to_m,
1549
- "Pa/m|psi/ft": (val) => val / C.psi_to_pascal * C.ft_to_m,
1550
- "psi/100ft|Pa/m": (val) => val * 68.9475729 / C.ft_to_m,
1551
- "Pa/m|psi/100ft": (val) => val / 68.9475729 * C.ft_to_m,
1552
- // Gradients - Angles:
1553
- "deg/30m|deg/100ft": (val) => val * (100 * C.ft_to_m / 30),
1554
- "deg/100ft|deg/30m": (val) => val / (100 * C.ft_to_m / 30),
1555
- "deg/30m|deg/m": (val) => val / 30,
1556
- "deg/m|deg/30m": (val) => val * 30,
1557
- "deg/100ft|deg/ft": (val) => val / 100,
1558
- "deg/ft|deg/100ft": (val) => val * 100,
1559
- "deg/100ft|deg/m": (val) => val / (100 * C.ft_to_m),
1560
- "deg/m|deg/100ft": (val) => val * (100 * C.ft_to_m),
1561
- "deg/ft|deg/m": (val) => val / C.ft_to_m,
1562
- "deg/m|deg/ft": (val) => val * C.ft_to_m,
1563
- "deg/m|rad/m": (val) => val * Math.PI / 180,
1564
- "rad/m|deg/m": (val) => val * 180 / Math.PI,
1565
- "rad/ft|deg/m": (val) => val * 180 / Math.PI / C.ft_to_m,
1566
- "deg/m|rad/ft": (val) => val * Math.PI / 180 * C.ft_to_m,
1567
- "deg/10m|deg/100ft": (val) => val * (10 * C.ft_to_m),
1568
- "deg/100ft|deg/10m": (val) => val / (10 * C.ft_to_m),
1569
- "deg/10m|deg/m": (val) => val / 10,
1570
- "deg/m|deg/10m": (val) => val * 10,
1571
- "deg/30m|deg/10m": (val) => val / 3,
1572
- "deg/10m|deg/30m": (val) => val * 3,
1573
- "deg/10m|rad/m": (val) => val * Math.PI / 180 / 10,
1574
- "rad/m|deg/10m": (val) => val * 180 / Math.PI * 10,
1575
- // intensity
1576
- "W/m2|hhp/in2": (val) => val * (1 / 745.699872 / 1550.0031),
1577
- "W/m2|hhp/ft2": (val) => val * (1 / 745.699872 / 10.76391),
1578
- "hhp/in2|W/m2": (val) => val / (1 / 745.699872 / 1550.0031),
1579
- "hhp/ft2|W/m2": (val) => val / (1 / 745.699872 / 10.76391),
1580
- // Gas Oil Ratio:
1581
- "SCF/STB|Sm3/Sm3": (val) => val * 0.178099173553719,
1582
- // 431 / 2420 = 0.17809917355371901 - https://www.wolframalpha.com/input?i=Standard+Cubic+Feet+per+Stock+Tank+Barrel
1583
- "Sm3/Sm3|SCF/STB": (val) => val * 5.614849187935035,
1584
- // 2420 / 431 = 5.614849187935035
1585
- // Inflow Productivity Index
1586
- "Sm3/d/bar|m3/s/bar": (val) => val / 86400,
1587
- "STB/d/psi|m3/s/bar": (val) => val / 37468.77736,
1588
- "m3/s/bar|Sm3/d/bar": (val) => val * 86400,
1589
- "m3/s/bar|STB/d/psi": (val) => val * 37468.77736,
1590
- "E-10/psi|E-09/bar": (val) => val * 1.450377378,
1591
- "E-10/psi|E-14/pa": (val) => val * 1.450377378,
1592
- "E-14/pa|E-10/psi": (val) => val / 1.450377378,
1593
- "E-09/bar|E-10/psi": (val) => val / 1.450377378,
1594
- "E-14/pa|1/Pa": (val) => val / Math.pow(10, 14),
1595
- "E-09/bar|1/bar": (val) => val / Math.pow(10, 9),
1596
- "E-10/psi|1/psi": (val) => val / Math.pow(10, 10),
1597
- "1/Pa|E-14/pa": (val) => val * Math.pow(10, 14),
1598
- "1/bar|E-09/bar": (val) => val * Math.pow(10, 9),
1599
- "1/psi|E-10/psi": (val) => val * Math.pow(10, 10),
1600
- // volumeGradient
1601
- "m3/m|cm3/m": (val) => val * 10 ** 6,
1602
- "m3/m|mm3/m": (val) => val * 10 ** 9,
1603
- "m3/m|ft3/ft": (val) => val * C.m3_per_m_to_ft3_per_ft,
1604
- "m3/m|in3/ft": (val) => val * C.m3_per_m_to_ft3_per_ft * C.ft3_to_in3,
1605
- "cm3/m|m3/m": (val) => val * 1e-6,
1606
- "cm3/m|mm3/m": (val) => val * 1e3,
1607
- "cm3/m|ft3/ft": (val) => val * C.m3_per_m_to_ft3_per_ft * 1e-6,
1608
- "cm3/m|in3/ft": (val) => val * C.m3_per_m_to_ft3_per_ft * 1e-6 * C.ft3_to_in3,
1609
- "mm3/m|m3/m": (val) => val * 1e-9,
1610
- "mm3/m|cm3/m": (val) => val * 1e-3,
1611
- "mm3/m|ft3/ft": (val) => val * C.m3_per_m_to_ft3_per_ft * 1e-9,
1612
- "mm3/m|in3/ft": (val) => val * C.m3_per_m_to_ft3_per_ft * 1e-9 * C.ft3_to_in3,
1613
- "ft3/ft|m3/m": (val) => val * 0.09290304,
1614
- "ft3/ft|cm3/m": (val) => val * 92903.04,
1615
- "ft3/ft|mm3/m": (val) => val * 92903040,
1616
- "ft3/ft|in3/ft": (val) => val * 1728,
1617
- "in3/ft|m3/m": (val) => val * C.in3_per_ft_to_m3_per_m,
1618
- "in3/ft|cm3/m": (val) => val * C.in3_per_ft_to_m3_per_m * 1e6,
1619
- "in3/ft|mm3/m": (val) => val * C.in3_per_ft_to_m3_per_m * 1e9,
1620
- "in3/ft|ft3/ft": (val) => val / C.ft3_to_in3,
1621
- // shearStress
1622
- "Pa|lbf/100ft2": (val) => val * 2.088543423315013,
1623
- // (100 * 185806080000) / 8896443230521 = 2.088543423315013 - https://www.wolframalpha.com/input?i=Pa+unit
1624
- "lbf/100ft2|Pa": (val) => val * 0.4788025898033584,
1625
- // 8896443230521 / (185806080000 * 100) = 0.47880258980335844, // https://www.wolframalpha.com/input?i=Pa+unit
1626
- // GIS Location Systems
1627
- "usft|m": (val) => val * 0.30480060960121924,
1628
- "lk|m": (val) => val * 0.201168,
1629
- "ftCla|m": (val) => val * 0.3047972651151,
1630
- "lkCla|m": (val) => val * 0.2011057269733667,
1631
- "ftGC|m": (val) => val * 0.30479971018150875,
1632
- "ydInd|m": (val) => val * 0.9143985307444408,
1633
- "ftSe|m": (val) => val * (12 / 39.370147),
1634
- "ydSe|m": (val) => val * 0.9143991154275526,
1635
- "chSe|m": (val) => val * 20.11676512155263,
1636
- "chSe(T)|m": (val) => val * 20.116756,
1637
- "m|usft": (val) => val / 0.30480060960121924,
1638
- "m|lk": (val) => val / 0.201168,
1639
- "m|ftCla": (val) => val / 0.3047972651151,
1640
- "m|lkCla": (val) => val / 0.2011057269733667,
1641
- "m|ftGC": (val) => val / 0.30479971018150875,
1642
- "m|ydInd": (val) => val / 0.9143985307444408,
1643
- "m|ftSe": (val) => val / (12 / 39.370147),
1644
- "m|ydSe": (val) => val / 0.9143991154275526,
1645
- "m|chSe": (val) => val / 20.11676512155263,
1646
- "m|chSe(T)": (val) => val / 20.116756,
1647
- // Mixing Requirements
1648
- "m3/t|L/100kg": (val) => val * 100,
1649
- "L/100kg|m3/t": (val) => val * 0.01,
1650
- //entalphy
1651
- "kJ/kg|J/kg": (val) => val * 1e3,
1652
- "J/kg|kJ/kg": (val) => val / 1e3,
1653
- "BTU/lbm|J/kg": (val) => val * 2326,
1654
- "J/kg|BTU/lbm": (val) => val / 2326
1655
- });
1656
- const DEPRECATED_UNITS = Object.freeze({
1657
- "N-m": "Nm",
1658
- "ft-lbf": "ftlbf",
1659
- "BTU/hr": "BTU/h",
1660
- "BTU/(htf*degF)": "BTU/(h*ft*degF)",
1661
- "BTU/(hft*degF)": "BTU/(h*ft*degF)"
1662
- });
1663
- const UNIT_ALIASES = Object.freeze({
1664
- "lbs/ft": "lb/ft",
1665
- "lbm/ft": "lb/ft",
1666
- // pound-mass per feet
1667
- ftUS: "usft"
1668
- // US feet, GIS interpretation
1669
- });
1670
- const INTERMEDIATE_CONVERSIONS = Object.freeze({
1671
- // LENGTH
1672
- mm: "m",
1673
- cm: "m",
1674
- km: "m",
1675
- ft: "m",
1676
- in: "m",
1677
- microM: "m",
1678
- // WEIGHT
1679
- lbf: "kg",
1680
- t: "kg",
1681
- tonnes: "kg",
1682
- mt: "kg",
1683
- kip: "kg",
1684
- // POWER
1685
- kW: "W",
1686
- MW: "W",
1687
- hp: "W",
1688
- hhp: "hp",
1689
- // AREA
1690
- mm2: "m2",
1691
- cm2: "m2",
1692
- km2: "m2",
1693
- in2: "m2",
1694
- ft2: "m2",
1695
- mile2: "m2",
1696
- // VOLUME
1697
- bbl: "m3",
1698
- ft3: "m3",
1699
- Mm3: "m3",
1700
- l: "m3",
1701
- USGal: "m3",
1702
- Sm3: "m3",
1703
- STB: "m3",
1704
- MMSCF: "m3",
1705
- MSm3: "m3",
1706
- SCF: "m3",
1707
- // FORCE
1708
- kN: "N",
1709
- kgf: "N",
1710
- tonneForce: "N",
1711
- klbf: "lbf",
1712
- // PRESSURE
1713
- psi: "Pa",
1714
- bar: "Pa",
1715
- kPa: "Pa",
1716
- MPa: "Pa",
1717
- ksi: "psi",
1718
- "lbf/100ft2": "psi",
1719
- // Pressure gradients:
1720
- "psi/100ft": "Pa/m",
1721
- "psi/ft": "Pa/m",
1722
- "bar/100m": "Pa/m",
1723
- "bar/m": "Pa/m",
1724
- "Pa/m": "kPa/m",
1725
- // DENSITY
1726
- sg: "kg/m3",
1727
- "g/cm3": "kg/m3",
1728
- "lbm/ft3": "kg/m3",
1729
- "lb/ft3": "kg/m3",
1730
- ppg: "kg/m3",
1731
- "kPa/m": "sg",
1732
- // GAS DENSITY
1733
- Gsg: "Gkg/m3",
1734
- Gppg: "Gkg/m3",
1735
- "Glbm/ft3": "Gkg/m3",
1736
- // FLUID COMPRESSIBILITY
1737
- "1/psi": "1/Pa",
1738
- "1/bar": "1/Pa",
1739
- "1/kPa": "1/Pa",
1740
- "1/MPa": "1/Pa",
1741
- "1/GPa": "1/Pa",
1742
- // DISTANCE PER TIME
1743
- "ft/s": "m/s",
1744
- "ft/min": "m/s",
1745
- "ft/h": "m/s",
1746
- "m/min": "m/s",
1747
- "m/h": "m/s",
1748
- mph: "m/s",
1749
- // FLOW RATE
1750
- "ft3/s": "m3/s",
1751
- lpm: "m3/s",
1752
- lps: "lpm",
1753
- bpm: "m3/s",
1754
- "m3/d": "m3/s",
1755
- "bbl/d": "m3/s",
1756
- "ft3/d": "m3/s",
1757
- "STB/d": "m3/s",
1758
- "Sm3/d": "m3/s",
1759
- gpm: "m3/s",
1760
- MMSCFD: "m3/s",
1761
- "Mm3/d": "m3/d",
1762
- "m3/min": "m3/s",
1763
- "MSm3/d": "m3/s",
1764
- "lbf/ft": "N/m",
1765
- // DURATION
1766
- min: "s",
1767
- h: "s",
1768
- d: "s",
1769
- month: "d",
1770
- year: "d",
1771
- //Specific Heat Capacity
1772
- "J/(kg*degK)": "J/(kg*degC)",
1773
- "BTU/(lbm*degF)": "J/(kg*degC)",
1774
- "BTU/(Kg*K)": "J/(kg*degC)",
1775
- //Thermal conductivity
1776
- "BTU/(h*ft*degF)": "J/(s*m*degK)",
1777
- "W/(m*degK)": "J/(s*m*degK)",
1778
- "W/(mK)": "J/(s*m*degK)",
1779
- // Temperature:
1780
- K: "C",
1781
- // Temp grad:
1782
- "C/m": "C/100m",
1783
- "F/ft": "C/100m",
1784
- "K/m": "C/100m",
1785
- "F/100ft": "C/100m",
1786
- "K/100m": "C/100m",
1787
- // Pressure Per Temperature
1788
- "Bar/C": "Pa/C",
1789
- // Turbulent skin
1790
- "s/m3": "1/m3/d",
1791
- "1/MMSCFD": "1/m3/d",
1792
- // Visosity:
1793
- P: "Pa*s",
1794
- "mPa*s": "Pa*s",
1795
- cP: "Pa*s",
1796
- // Intensity:
1797
- "hhp/in2": "W/m2",
1798
- "hhp/ft2": "W/m2",
1799
- // Inflow Productivity Index:
1800
- "Sm3/d/bar": "m3/s/bar",
1801
- "STB/d/psi": "m3/s/bar",
1802
- // Angle gradients:
1803
- "deg/100ft": "deg/m",
1804
- "deg/30m": "deg/m",
1805
- "deg/10m": "deg/m",
1806
- "deg/ft": "deg/m",
1807
- "rad/ft": "deg/m",
1808
- // Mole weight:
1809
- "lbf/mol": "kg/mol",
1810
- "g/mol": "kg/mol",
1811
- // Thermal expansion
1812
- "1/K": "E-06/degC",
1813
- "E-09/bar": "E-10/psi",
1814
- "E-14/pa": "E-10/psi",
1815
- "1/Pa": "E-14/pa",
1816
- // TORQUE
1817
- kNm: "Nm",
1818
- ftlbf: "Nm",
1819
- // GIS Location Systems
1820
- lk: "m",
1821
- ftCla: "m",
1822
- lkCla: "m",
1823
- ftSe: "m",
1824
- ydSe: "m",
1825
- chSe: "m",
1826
- "chSe(T)": "m",
1827
- ftGC: "m",
1828
- ydInd: "m",
1829
- //Entalphy
1830
- "BTU/lbm": "J/kg"
1831
- });
1832
- const KNOWN_UNITS = Object.freeze(Array.from(new Set(Object.values(ALT_UNITS).flat())));
1833
- const SPECIAL_NUMBERS = [NaN, -Infinity, Infinity];
1834
- const SPECIAL_NUMBERS_STRING = SPECIAL_NUMBERS.map((number) => number.toString());
1835
- const QUANTITIES_DESCRIPTION = {
1836
- density: "Density",
1837
- length: "Length",
1838
- duration: "Duration",
1839
- temperature: "Temperature",
1840
- tempgrad: "Temperature Gradient",
1841
- volume: "Volume",
1842
- weight: "Weight",
1843
- angles: "Angles",
1844
- depth: "Depth",
1845
- distance: "Distances",
1846
- height: "Height",
1847
- diameters: "Diameters",
1848
- doglegSeverity: "Dogleg severity",
1849
- fluidCompressibility: "Fluid Compressibility",
1850
- force: "Force",
1851
- gasVolume: "Gas volume",
1852
- oilVolume: "Oil volume",
1853
- moleWeight: "Mole weight",
1854
- linearCapacity: "Linear Capacity",
1855
- stress: "Stress",
1856
- thermalConductivity: "Thermal conductivity",
1857
- specificHeatCapacity: "Specific heat capacity",
1858
- thermalExpansionCoefficient: "Thermal expansion coefficient",
1859
- youngsModulus: "Youngs Modulus",
1860
- torque: "Torque",
1861
- areaOther: "Area - Other",
1862
- areaTubular: "Area - Tubular",
1863
- pumpRate: "Pump Rate",
1864
- pressure: "Pressure",
1865
- blowoutFlowRate: "Flowrate (blowout)",
1866
- percentage: "Percentage",
1867
- frequency: "Frequency",
1868
- torqueGradient: "Torque gradient",
1869
- pressureGradient: "Pressure gradient",
1870
- flowrate: "Volumetric flow rate",
1871
- massFlowRate: "Mass flow rate",
1872
- angleGradient: "Angle gradient",
1873
- weightGradient: "Weight gradient",
1874
- forceGradient: "Force gradient",
1875
- interfacialTension: "Interfacial tension",
1876
- acceleration: "Acceleration",
1877
- viscosity: "Viscosity",
1878
- power: "Power",
1879
- intensity: "Power intensity",
1880
- gasliftFlowRate: "Flowrate (Gas lift)",
1881
- productionFlowRate: "Flowrate (production)",
1882
- productionFlowRateOil: "Flowrate for Oil (production)",
1883
- productionFlowRateGas: "Flowrate for Gas (production)",
1884
- injectionFlowRate: "Flowrate (injection)",
1885
- blowoutOilFlowRate: "Flowrate for Oil (blowout)",
1886
- blowoutGasFlowRate: "Flowrate for Gas (blowout)",
1887
- gor: "Gas Oil Ratio",
1888
- rotationalSpeed: "Rotational Speed",
1889
- densityGas: "Density for gas",
1890
- inflowProductivityIndex: "Inflow productivity index",
1891
- latitude: "Latitude",
1892
- longitude: "Longitude",
1893
- permeability: "Permeability",
1894
- sdstats: "sdstats",
1895
- roughness: "Material Roughness",
1896
- wltubulars: "Tubular weight",
1897
- speed: "Velocity",
1898
- inverseStandSpeed: "Inverse Stand velocity",
1899
- rop: "Rate of Penetration (ROP)",
1900
- densityOil: "Density for oil",
1901
- densityOilGas: "Density for oil/gas",
1902
- kickToleranceVolume: "Volume for kick tolerance",
1903
- densitySolid: "Density for solid",
1904
- massPerLength: "Mass Per Length",
1905
- durationShort: "Duration (TempSim short)",
1906
- durationLong: "Duration (TempSim long)",
1907
- wearFactor: "Wear factor",
1908
- turbulentSkin: "Turbulent skin",
1909
- pressurePerTemperature: "Pressure per temperature",
1910
- location: "Location coordinates length",
1911
- mixingRequirements: "Ratio between water and cement",
1912
- Entalphy: "Entalphy",
1913
- shearStress: "Shear Stress, force parallel to surface",
1914
- volumeGradient: "Rate of Volume change per unit",
1915
- deg: "Degree, a unit of angular measurement",
1916
- dls: "Dogleg Severity, measure of wellbore curvature changes per unit length",
1917
- wgrad: "Weight Gradient, change in weight per unit length",
1918
- entalphy: "Entalphy, total heat content of a system",
1919
- pressurechange: "Change in pressure over time or between two points",
1920
- 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"
1921
- };
1922
- const UNITS_DESCRIPTION = {
1923
- in: "Inches",
1924
- mm: "Milimeters",
1925
- cm: "Centimeters",
1926
- m: "Meters",
1927
- km: "Kilometers",
1928
- ft: "Feets",
1929
- usft: "US Feets",
1930
- in2: "Square inches",
1931
- cm2: "Square centimeters",
1932
- m2: "Square meters",
1933
- kg: "Kilograms",
1934
- tonnes: "Tonnes",
1935
- mt: "Metric tonnes",
1936
- kip: "Kip",
1937
- bbl: "Barrels",
1938
- Mm3: "Mega cubic meters",
1939
- MMSCF: "Million Standard Cubic Feet",
1940
- lbm: "Pound mass",
1941
- "kg/mol": "Kilograms per mole",
1942
- "lbf/mol": "Pounds per mole",
1943
- sg: "Specific gravity",
1944
- ppg: "Pounds per gallon",
1945
- "kg/m3": "Kilogram per cubic meters",
1946
- "lbm/ft3": "Pounds per cubic foot",
1947
- s: "Seconds",
1948
- min: "Minutes",
1949
- h: "Hours",
1950
- d: "Days",
1951
- month: "Months",
1952
- year: "Years",
1953
- "bbl/ft": "Barrels per foot",
1954
- lpm: "Litres per minute",
1955
- bpm: "Barrels per minute",
1956
- "m3/min": "Cubic meters per minute",
1957
- "m3/s": "Cubic meters per second",
1958
- MMSCFD: "Million Standard Cubic Feet per day",
1959
- "1/MMSCFD": "Inverse Million Standard Cubic Feet per day",
1960
- bar: "Bar",
1961
- Pa: "Pascals",
1962
- kPa: "Kilopascals",
1963
- MPa: "Megapascals",
1964
- kPsi: "Kilo pounds per square inch",
1965
- "kPa/m": "Kilopascals per meter",
1966
- "psi/ft": "Psi per foot",
1967
- "bar/100m": "Bars per 100m",
1968
- "psi/100ft": "Psi per 100ft",
1969
- "kPa/100m": "Kilopascals per 100m",
1970
- C: "Degrees Celsius",
1971
- F: "Degrees Fahrenheit",
1972
- K: "Kelvins",
1973
- "C/100m": "Degrees Celsius per 100m",
1974
- "F/100ft": "Degrees Fahrenheit per 100m",
1975
- "K/100m": "Kelvins per 100m",
1976
- "lbf/ft": "Pound force / foot",
1977
- "Pa/C": "Pascal per celsius",
1978
- "Bar/C": "Bar per celsius",
1979
- "psi/F": "Psi per fahrenheit",
1980
- "psi/C": "Psi per celsius",
1981
- N: "Newtons",
1982
- kN: "Kilo Newtons",
1983
- "N/m": "Newtons per meter",
1984
- "daN/m": "Decanewtons per meter",
1985
- lbf: "Pound force",
1986
- kgf: "Kilogram force",
1987
- rad: "Radians",
1988
- "BTU/lbm": "British Thermal Units per pound",
1989
- ppf: "Pound per foot",
1990
- "kg/m": "Kilograms per meter",
1991
- "E-06/degC": "Micro per degree Celsius",
1992
- "E-06/degF": "Micro per degree Fahrenheit",
1993
- km2: "Square kilometers",
1994
- ft2: "Square feet",
1995
- mm2: "Square millimeters",
1996
- mile2: "Square miles",
1997
- ft3: "Cubic feet",
1998
- "g/cm3": "Grams per cubic centimeter",
1999
- Sm3: "Standard cubic meter",
2000
- "ft3/s": "Cubic feet per second",
2001
- "ft3/d": "Cubic feet per day",
2002
- "m3/d": "Cubic meter per day",
2003
- "1/m3/d": "Inverse Cubic meter per day",
2004
- "s/m3": "Seconds per cubic meters",
2005
- "bbl/d": "Barrels per day",
2006
- tonneForce: "Tonne force",
2007
- USGal: "US gallon",
2008
- "g/mol": "Grams per mol",
2009
- Nm: "Newton meter",
2010
- kNm: "Kilo Newton meter",
2011
- ftlbf: "Foot pound",
2012
- "J/(kg*degC)": "Joules per kilogram degree Celsius",
2013
- "J/(kg*degK)": "Joules per kilogram degree Kelwin",
2014
- "BTU/(lbm*degF)": "British Thermal Unit per pound Fahrenheit",
2015
- "BTU/(h*ft*degF)": "British Thermal Units per hour feet degree Fahrenheit",
2016
- l: "Litres",
2017
- "l/m": "Litres per meter",
2018
- "kJ/kg": "Kilo joules per kilogram",
2019
- "J/kg": "Joules per kilogram",
2020
- deg: "Degrees",
2021
- "W/(mK)": "Watts per milli Kelvin",
2022
- psi: "Pounds per square inch",
2023
- "1/bar": "1/bar",
2024
- "1/psi": "1/psi",
2025
- "deg/100ft": "Degrees per 100ft",
2026
- "deg/10m": "Degrees per 10m",
2027
- "deg/30m": "Degrees per 30m",
2028
- "%": "Percent",
2029
- Hz: "Hertz",
2030
- "1/s": "Inverse second",
2031
- rpm: "Revolutions per minute",
2032
- "Pa/m": "Pascal per meter",
2033
- "bar/m": "Bar per meter",
2034
- gpm: "Gallons per minute",
2035
- "kg/s": "Kilograms per second",
2036
- "lbm/s": "Pound mass per second",
2037
- "deg/m": "Degrees per meter",
2038
- "deg/ft": "Degrees per foot",
2039
- "rad/m": "Radians per meter",
2040
- "rad/ft": "Radians per foot",
2041
- "dyn/cm": "Dyn per centimeter",
2042
- "mN/m": "Millinewtons per meter",
2043
- "1/kPa": "1/kPa",
2044
- m3: "Cubic meters",
2045
- "m/s": "Meters per second",
2046
- "ft/s": "Feet per second",
2047
- "m/min": "Meters per minute",
2048
- "ft/min": "Feet per min",
2049
- "m/h": "Meters per hour",
2050
- "ft/h": "Feet per hour",
2051
- mph: "Miles per hour",
2052
- "km/h": "Kilometers per hour",
2053
- "m/s2": "Meters per second squared",
2054
- "ft/s2": "Feet per second squared",
2055
- "Pa*s": "Pascal seconds",
2056
- P: "Poise (dyne second per square centimeter)",
2057
- "mPa*s": "Millipascal seconds",
2058
- cP: "Centi Poise",
2059
- W: "Watts",
2060
- hhp: "Hydraulic horsepower",
2061
- hp: "Horsepower",
2062
- kW: "Kilowatts",
2063
- MW: "Megawatts",
2064
- "BTU/h": "British Thermal Units per hour",
2065
- "hhp/in2": "Hydraulic horsepower per square inch",
2066
- "hhp/ft2": "Hydraulic horsepower per square feet",
2067
- "Mm3/d": "Mega cubic meters per day",
2068
- "STB/d": "Stock Tank Barrel per day",
2069
- "Sm3/d": "Standard cubic meters per day",
2070
- "MSm3/d": "Mega standard cubic meters per day",
2071
- "SCF/STB": "Standard Cubic Feet per Stock Tank Barrel",
2072
- "Sm3/Sm3": "Standard cubic meters per Standard cubic meter",
2073
- "SCF/d": "Standard cubic feet per day",
2074
- STB: "Stock Tank Barrel",
2075
- SCF: "Standard Cubic Feet",
2076
- Gsg: "Gas - specific gravity",
2077
- Gppg: "Gas - pounds per gallon",
2078
- "Gkg/m3": "Gas - kilogram per cubic meters",
2079
- "Glbm/ft3": "Gas - pounds per cubic foot",
2080
- MSm3: "Mega standard cubic meters",
2081
- "m3/s/bar": "Cubic per second per bar",
2082
- "Sm3/d/bar": "Standard cubic per day per bar",
2083
- "STB/d/psi": "Standard barrels per day per psi",
2084
- klbf: "kilopound force",
2085
- "1/Pa": "1/Pascal",
2086
- "1/MPa": "1/MPa",
2087
- ksi: "Kilopound per square inch",
2088
- "lbf/100ft2": "Pounds per 100 square foot",
2089
- "lb/ft3": "lb/ft3",
2090
- "\xB0N": "\xB0N (latitude)",
2091
- "\xB0S": "\xB0S (latitude)",
2092
- "\xB0W": "\xB0W (longitude)",
2093
- "\xB0E": "\xB0E (longitude)",
2094
- fr: "Fraction",
2095
- mD: "Millidarcy",
2096
- Sigma: "Sigma",
2097
- CI: "Confidence Interval",
2098
- "J/(s*m*degK)": "Joules per second meter Kelvin",
2099
- "C/m": "Degrees Celsius per meter",
2100
- "F/ft": "Degrees Fahrenheit per meter",
2101
- "K/m": "Kelvin per meter",
2102
- microM: "Micro meter",
2103
- "W/m2": "Watt per square meter",
2104
- "1/K": "Inverse Kelvin",
2105
- "lb/ft": "Pound Per Feet",
2106
- "E-09/bar": "Nano per bar",
2107
- "E-10/psi": "10\u207B\xB9\u2070 per psi",
2108
- "E-14/pa": "10\u207B\xB9\u2074 per pascal",
2109
- lk: "Link",
2110
- ftCla: "Clark`s foot",
2111
- lkCla: "Clark`s link",
2112
- ftSe: "British foot (Sears 1922)",
2113
- ydSe: "British yard (Sears 1922)",
2114
- chSe: "British chain (Sears 1922)",
2115
- "chSe(T)": "British chain (Sears 1922 Truncated)",
2116
- ftGC: "Gold Coast foot",
2117
- ydInd: "Indian yard",
2118
- "d/stand": "Day per stand",
2119
- "h/stand": "Hour per stand",
2120
- "min/stand": "Minute per stand",
2121
- "s/stand": "Second per stand",
2122
- "m3/t": "Cubic meter per ton",
2123
- "L/100kg": "Liter per 100kg",
2124
- GPa: "Gigapascals, unit of pressure",
2125
- "cm3/m": "Cubic cm per meter",
2126
- "in3/ft": "Cubic inches per foot",
2127
- "ft3/ft": "Cubic feet per foot",
2128
- "m3/m": "Cubic meters per meter",
2129
- "mm3/m": "Cubic millimeters per meter",
2130
- "1/GPa": "Inverse gigapascal",
2131
- lps: "Liters per second"
2132
- };
2133
-
2134
- var ucs2length = {};
2135
-
2136
- var hasRequiredUcs2length;
2137
-
2138
- function requireUcs2length () {
2139
- if (hasRequiredUcs2length) return ucs2length;
2140
- hasRequiredUcs2length = 1;
2141
- Object.defineProperty(ucs2length, "__esModule", { value: true });
2142
- function ucs2length$1(str) {
2143
- const len = str.length;
2144
- let length = 0;
2145
- let pos = 0;
2146
- let value;
2147
- while (pos < len) {
2148
- length++;
2149
- value = str.charCodeAt(pos++);
2150
- if (value >= 55296 && value <= 56319 && pos < len) {
2151
- value = str.charCodeAt(pos);
2152
- if ((value & 64512) === 56320)
2153
- pos++;
2154
- }
2155
- }
2156
- return length;
2157
- }
2158
- ucs2length.default = ucs2length$1;
2159
- ucs2length$1.code = 'require("ajv/dist/runtime/ucs2length").default';
2160
- return ucs2length;
2161
- }
2162
-
2163
- const numberSchemaValidator = validate15;
2164
- function validate15(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
2165
- let vErrors = null;
2166
- let errors = 0;
2167
- if (!(typeof data == "number" && isFinite(data))) {
2168
- const err0 = { instancePath, schemaPath: "#/type", keyword: "type", params: { type: "number" }, message: "must be number" };
2169
- if (vErrors === null) {
2170
- vErrors = [err0];
2171
- } else {
2172
- vErrors.push(err0);
2173
- }
2174
- errors++;
2175
- }
2176
- if (errors > 0) {
2177
- const emErrs0 = [];
2178
- for (const err1 of vErrors) {
2179
- if (err1.keyword !== "errorMessage" && !err1.emUsed && (err1.instancePath === instancePath || err1.instancePath.indexOf(instancePath) === 0 && err1.instancePath[instancePath.length] === "/") && err1.schemaPath.indexOf("#") === 0 && err1.schemaPath["#".length] === "/") {
2180
- emErrs0.push(err1);
2181
- err1.emUsed = true;
2182
- }
2183
- }
2184
- if (emErrs0.length) {
2185
- const err2 = { instancePath, schemaPath: "#/errorMessage", keyword: "errorMessage", params: { errors: emErrs0 }, message: "Must be a numerical value" };
2186
- if (vErrors === null) {
2187
- vErrors = [err2];
2188
- } else {
2189
- vErrors.push(err2);
2190
- }
2191
- errors++;
2192
- }
2193
- const emErrs1 = [];
2194
- for (const err3 of vErrors) {
2195
- if (!err3.emUsed) {
2196
- emErrs1.push(err3);
2197
- }
2198
- }
2199
- vErrors = emErrs1;
2200
- errors = emErrs1.length;
2201
- }
2202
- validate15.errors = vErrors;
2203
- return errors === 0;
2204
- }
2205
- requireUcs2length().default;
2206
-
2207
- const transformErrors = (errors) => {
2208
- return errors?.map(({ message }) => message);
2209
- };
2210
-
2211
- const SEPARATOR = "|";
2212
- const UNIT_RE = /^(-?[0-9., /]*?(?:e[-+]?[0-9]+)?)([^0-9-., /].*)?$/;
2213
- const EXP_NOTATION_RE = /^[-+]?[0-9]*\.?[0-9]+(?:\/[0-9]*\.?[0-9]+)?(?:[eE][-+]?[0-9]+)?$/;
2214
- function showAltUnitsList(quantityKey) {
2215
- return ALT_UNITS[quantityKey];
2216
- }
2217
- function getUnitsForQuantity(quantity) {
2218
- return showAltUnitsList(quantity);
2219
- }
2220
- function getQuantities() {
2221
- return Object.keys(ALT_UNITS);
2222
- }
2223
- function label(unitKey) {
2224
- return LABELS[unitKey];
2225
- }
2226
- function unitFromKey(quantity) {
2227
- return UNIT_FROM_KEY[quantity];
2228
- }
2229
- function unitFromQuantity(quantity) {
2230
- return unitFromKey(quantity);
2231
- }
2232
- function getAltUnitsListByQuantity(quantity) {
2233
- const quantityUnitList = showAltUnitsList(quantity);
2234
- return quantityUnitList ? quantityUnitList.map((unit) => ({ unit, label: label(unit) })) : void 0;
2235
- }
2236
- function checkAndCleanDecimalComma(val) {
2237
- const RegExForMultiDots = /\.{2,}/;
2238
- const RegexFindComma = /,/;
2239
- if (typeof val === "string") {
2240
- while (RegExForMultiDots.test(val) || RegexFindComma.test(val)) {
2241
- val = val.replace(RegExForMultiDots, ".");
2242
- val = val.replace(RegexFindComma, ".");
2243
- }
2244
- }
2245
- return val;
2246
- }
2247
- function to(value, fromUnit, toUnit) {
2248
- value = checkAndCleanDecimalComma(value);
2249
- if (toUnit === "undefined") {
2250
- console.warn('Inconsistent "to unit" - debug call to "Units.to()"');
2251
- }
2252
- if (fromUnit === "undefined") {
2253
- fromUnit = toUnit;
2254
- console.warn('Inconsistent "from unit" - debug call to "Units.to()"');
2255
- }
2256
- if (fromUnit === toUnit) {
2257
- return toNum(value);
2258
- }
2259
- if (value === Infinity || value === "Infinity") {
2260
- return Infinity;
2261
- }
2262
- if (value === -Infinity || value === "-Infinity") {
2263
- return -Infinity;
2264
- }
2265
- if (isNonNumerical(value) && value !== "") {
2266
- return NaN;
2267
- }
2268
- const conv = KNOWN_CONVERSIONS[fromUnit + "|" + toUnit];
2269
- if (conv) {
2270
- return conv(toNum(value));
2271
- }
2272
- if (DEPRECATED_UNITS[fromUnit]) {
2273
- console.warn(
2274
- `Unit '${fromUnit}' is deprecated - use '${DEPRECATED_UNITS[fromUnit]}' instead.`
2275
- );
2276
- return to(value, DEPRECATED_UNITS[fromUnit], toUnit);
2277
- }
2278
- if (DEPRECATED_UNITS[toUnit]) {
2279
- console.warn(
2280
- `Unit '${toUnit}' is deprecated - use '${DEPRECATED_UNITS[toUnit]}' instead.`
2281
- );
2282
- return to(value, fromUnit, DEPRECATED_UNITS[toUnit]);
2283
- }
2284
- if (UNIT_ALIASES[toUnit]) {
2285
- return to(value, fromUnit, UNIT_ALIASES[toUnit]);
2286
- }
2287
- if (UNIT_ALIASES[fromUnit]) {
2288
- return to(value, UNIT_ALIASES[fromUnit], toUnit);
2289
- }
2290
- const int_from = INTERMEDIATE_CONVERSIONS[fromUnit];
2291
- if (int_from) {
2292
- const int_val = to(value, fromUnit, int_from);
2293
- return to(int_val, int_from, toUnit);
2294
- } else {
2295
- const int_to = INTERMEDIATE_CONVERSIONS[toUnit];
2296
- if (toUnit && int_to && int_to !== toUnit) {
2297
- const int_val = to(value, fromUnit, int_to);
2298
- return to(int_val, int_to, toUnit);
2299
- }
2300
- }
2301
- console.error("no conversions found", value, fromUnit, "->", toUnit);
2302
- throw new Error(
2303
- "No conversions found: " + value + " " + fromUnit + " -> " + toUnit
2304
- );
2305
- }
2306
- function split(numWithUnit) {
2307
- let m;
2308
- let vu = numWithUnit !== void 0 && numWithUnit !== null ? String(numWithUnit) : "";
2309
- if (charCount(SEPARATOR, vu) > 1) {
2310
- m = vu.split(SEPARATOR);
2311
- vu = m.slice(0, -1).join("") + SEPARATOR + m.slice(-1);
2312
- }
2313
- if (vu.indexOf(SEPARATOR) >= 0) {
2314
- m = vu.split(SEPARATOR);
2315
- } else if (SPECIAL_NUMBERS_STRING.includes(vu)) {
2316
- m = [vu, ""];
2317
- } else {
2318
- m = cleanNumStr(vu).match(UNIT_RE);
2319
- if (m) {
2320
- m = m.slice(1);
2321
- }
2322
- }
2323
- if (!m) m = ["0", ""];
2324
- if (m[1] == null) m[1] = "";
2325
- return [m[0], m[1]];
2326
- }
2327
- function getValue(numWithUnit) {
2328
- return split(numWithUnit)[0];
2329
- }
2330
- function getUnit(numWithUnit) {
2331
- return split(numWithUnit)[1];
2332
- }
2333
- function unum(numWithUnit, toUnit, fromUnit) {
2334
- if (numWithUnit == null || numWithUnit === "") {
2335
- return 0;
2336
- }
2337
- if (typeof numWithUnit === "string" && numWithUnit.startsWith("NaN") || typeof numWithUnit === "number" && isNaN(numWithUnit)) {
2338
- return NaN;
2339
- }
2340
- const cleanStr = cleanNumStr(numWithUnit).replaceAll("+", "");
2341
- const m = split(cleanStr);
2342
- if (!m) {
2343
- if (toUnit && fromUnit) return unum(numWithUnit + fromUnit, toUnit);
2344
- else throw new Error("unum: invalid number: " + numWithUnit);
2345
- }
2346
- if (m[0] == null) m[0] = "0";
2347
- if (m[1]) fromUnit = m[1];
2348
- if (!fromUnit && toUnit !== fromUnit) {
2349
- throw new Error(`unum: unable to figure out unit: ${numWithUnit} fromUnit ${fromUnit}`);
2350
- }
2351
- if (toUnit === fromUnit) {
2352
- const v = m[0] ? toNum(m[0]) : 0;
2353
- if (v === Infinity || v === "Infinity") {
2354
- return Infinity;
2355
- }
2356
- if (v === -Infinity || v === "-Infinity") {
2357
- return -Infinity;
2358
- }
2359
- if (typeof v === "string" && EXP_NOTATION_RE.test(v)) {
2360
- return parseFloat(v);
2361
- }
2362
- if (!isNumeric(v) && v !== Infinity && v !== -Infinity) {
2363
- throw new Error("unum: invalid number: " + v + ", " + typeof v);
2364
- }
2365
- return cleanNum(v);
2366
- }
2367
- return to(m[0], fromUnit, toUnit);
2368
- }
2369
- function isValueWithUnit(value) {
2370
- if (!value) {
2371
- return false;
2372
- }
2373
- const splittedValue = String(value).split(SEPARATOR);
2374
- return splittedValue.length === 2 && KNOWN_UNITS.includes(splittedValue[1]);
2375
- }
2376
- function convertAndGetValue(numWithUnit, toUnit, fromUnit) {
2377
- return unum(numWithUnit, toUnit, fromUnit);
2378
- }
2379
- function convertAndGetValueStrict(value, toUnit, fromUnit) {
2380
- if (value === "" || value === null) {
2381
- return value;
2382
- }
2383
- if (typeof value === "string" && isValueWithUnit(value) && getValue(value) === "") {
2384
- return "";
2385
- }
2386
- const isString = typeof value === "string";
2387
- const result = convertAndGetValue(value, toUnit, fromUnit);
2388
- return isString ? String(toString(result)) : result;
2389
- }
2390
- function toBase(value, quantity) {
2391
- const to_unit = unitFromKey(quantity);
2392
- const m = split((value || "").toString());
2393
- return unum(value, to_unit, m[1] || to_unit);
2394
- }
2395
- function convertTable(toUnitRow, table, defaultUnitRow, removeFinalUnitsRow = false) {
2396
- if (!table || !table.length || !table[0].length) return table;
2397
- if (!toUnitRow) toUnitRow = table[0];
2398
- if (!defaultUnitRow) defaultUnitRow = toUnitRow;
2399
- const firstCell = table[0][0];
2400
- const splittedFirstCell = firstCell && split(`${firstCell}`);
2401
- const unitNum = splittedFirstCell && splittedFirstCell[0] && isNaN(splittedFirstCell[1]);
2402
- const tableHasUnits = !unitNum && isNaN(table[0][0]);
2403
- let ix = tableHasUnits ? 1 : 0;
2404
- const fromunitrow = tableHasUnits ? table[0] : defaultUnitRow;
2405
- const newTable = [toUnitRow];
2406
- for (; ix < table.length; ix++) {
2407
- const cols = Array(toUnitRow.length);
2408
- const coli = table[ix];
2409
- for (let uix = 0; uix < cols.length; uix++) {
2410
- cols[uix] = toUnitRow[uix] && coli[uix] ? unum(coli[uix], toUnitRow[uix], fromunitrow[uix]) : coli[uix];
2411
- }
2412
- newTable.push(cols);
2413
- }
2414
- if (removeFinalUnitsRow) newTable.shift();
2415
- return newTable;
2416
- }
2417
- function roundNumberWithLabel(value, n = 2) {
2418
- return displayNumber(
2419
- round(value, n),
2420
- { withUnit: true }
2421
- );
2422
- }
2423
- function withUnit(value, unit, defaultVal = "") {
2424
- if (value === null || value === "" || value === void 0) {
2425
- value = defaultVal;
2426
- }
2427
- if (unit === null) {
2428
- return String(value);
2429
- }
2430
- let [v, u] = String(value).includes(SEPARATOR) ? split(String(value)) : [value, unit];
2431
- if (!u) {
2432
- u = unit;
2433
- }
2434
- return [v, u].join(SEPARATOR);
2435
- }
2436
- function unumWithUnit(numWithUnit, toUnit, fromUnit) {
2437
- return withUnit(unum(numWithUnit, toUnit, fromUnit), toUnit);
2438
- }
2439
- function convertSamePrecision(numWithUnit, toUnit, digits) {
2440
- const validNumWithUnit = String(numWithUnit);
2441
- const m = split(validNumWithUnit);
2442
- const convertedNumber = !m[1] || m[1] == toUnit ? Number(m[0]) : to(m[0], String(m[1]), toUnit);
2443
- let prettyNumber = "0";
2444
- let targetDigits = digits;
2445
- if (convertedNumber !== 0) {
2446
- if (!targetDigits) {
2447
- if (m[1] === toUnit) {
2448
- return validNumWithUnit;
2449
- }
2450
- const regx = String(m[0]).match(/^[-+.,0]*(\d*)[.,]?(\d*)/);
2451
- if (regx) {
2452
- targetDigits = Math.max(3, regx[1].length + regx[2].length);
2453
- } else {
2454
- targetDigits = 3;
2455
- }
2456
- }
2457
- const lim = Math.pow(10, --targetDigits);
2458
- const absNum = Math.abs(convertedNumber);
2459
- if (absNum >= 1e5 * lim || absNum * 1e4 * (1 + lim) < lim) {
2460
- prettyNumber = convertedNumber.toExponential(targetDigits);
2461
- } else if (absNum >= lim) {
2462
- prettyNumber = convertedNumber.toFixed();
2463
- } else {
2464
- const digs = Math.floor(Math.log10(absNum));
2465
- prettyNumber = convertedNumber.toFixed(targetDigits - digs);
2466
- let j = prettyNumber.length;
2467
- if (prettyNumber[--j] == "0") {
2468
- while (prettyNumber[--j] == "0") ;
2469
- prettyNumber = prettyNumber.slice(0, j + (prettyNumber[j] == "." ? 0 : 1));
2470
- }
2471
- }
2472
- }
2473
- return withUnit(prettyNumber, toUnit);
2474
- }
2475
- function altUnitsList(value, quantity) {
2476
- let v = value;
2477
- if (!getUnit(value)) {
2478
- v = withUnit(value, unitFromQuantity(quantity) ?? "");
2479
- }
2480
- const altUnits = ALT_UNITS[quantity] ?? [];
2481
- return altUnits.map((unit) => [...split(convertSamePrecision(v, unit)), label(unit)]);
2482
- }
2483
- function validateAndClean(previousValue, nextText) {
2484
- const unit = split(previousValue)[1];
2485
- const stripAllExceptNumeric = /[^0-9.,-Ee]/g;
2486
- const stripE = /^([^(e|E)]*[eE])|[eE]/g;
2487
- const stripInvalidLeading = /^[E|e]*|[E|e]*$/g;
2488
- const replaceComma = /,/g;
2489
- const stripDot = /^([^.]*\.)|\./g;
2490
- const stripDotFollowedByE = /\.(?=e)/g;
2491
- const stripMinus = /-|[eE]-/g;
2492
- const cleanedValue = nextText.replace(stripAllExceptNumeric, "").replace(stripE, "$1").replace(stripInvalidLeading, "").replace(replaceComma, ".").replace(stripDot, "$1").replace(stripDotFollowedByE, "").replace(stripMinus, (match, offset) => offset === 0 || match.toLowerCase() === "e-" ? match : "");
2493
- return !Number.isFinite(+cleanedValue) ? previousValue : `${cleanedValue}${unit ? "|" : ""}${unit}`;
2494
- }
2495
- function withPrettyUnitLabel(valueWithUnits) {
2496
- const [val, unit] = split(valueWithUnits);
2497
- const prettyUnit = LABELS[unit] ?? "";
2498
- return `${val} ${prettyUnit}`;
2499
- }
2500
- function validateNumber(value) {
2501
- let val = value;
2502
- if (typeof value === "string" && isValueWithUnit(value)) {
2503
- val = getValue(value);
2504
- }
2505
- val = checkAndCleanDecimalComma(val);
2506
- if (isNumeric(val)) {
2507
- const valid2 = numberSchemaValidator(toNum(val));
2508
- return { valid: valid2, errors: transformErrors(numberSchemaValidator.errors) };
2509
- }
2510
- const valid = numberSchemaValidator(val);
2511
- return { valid, errors: transformErrors(numberSchemaValidator.errors) };
2512
- }
2513
-
2514
- export { ALT_UNITS, DEPRECATED_UNITS, INTERMEDIATE_CONVERSIONS, KNOWN_CONVERSIONS, KNOWN_UNITS, LABELS, QUANTITIES_DESCRIPTION, UNITS_DESCRIPTION, UNIT_ALIASES, UNIT_FROM_KEY, allNumbers, altUnitsList, asFraction, charCount, checkAndCleanDecimalComma, cleanNum, cleanNumStr, convertAndGetValue, convertAndGetValueStrict, convertSamePrecision, convertTable, displayNumber, displayNumberToFixed, formatNumber, fraction, getAltUnitsListByQuantity, getNumberOfDigitsToShow, getQuantities, getUnit, getUnitsForQuantity, getValue, isCloseTo, isCloseToOrGreaterThan, isCloseToOrLessThan, isDeepCloseTo, isEmptyValueWithUnit, isFraction, isNonNumerical, isNumeric, isScientificStringNum, isValidNum, isValueWithUnit, label, numFraction, round, roundByMagnitude, roundByMagnitudeToFixed, roundByRange, roundNumberWithLabel, roundToDecimalPrecision, roundToFixed, roundToPrecision, showAltUnitsList, split, stripLeadingZeros, to, toBase, toNum, toString, unitFromKey, unitFromQuantity, unum, unumWithUnit, validateAndClean, validateNumber, withPrettyUnitLabel, withUnit };
1
+ export { a3 as ALT_UNITS, a7 as DEPRECATED_UNITS, a9 as INTERMEDIATE_CONVERSIONS, a6 as KNOWN_CONVERSIONS, aa as KNOWN_UNITS, a4 as LABELS, ab as QUANTITIES_DESCRIPTION, ac as UNITS_DESCRIPTION, a8 as UNIT_ALIASES, a5 as UNIT_FROM_KEY, O as allNumbers, i as altUnitsList, W as asFraction, S as charCount, c as checkAndCleanDecimalComma, Z as cleanNum, Y as cleanNumStr, q as convertAndGetValue, x as convertAndGetValueStrict, p as convertSamePrecision, j as convertTable, Q as displayNumber, R as displayNumberToFixed, P as formatNumber, U as fraction, g as getAltUnitsListByQuantity, T as getNumberOfDigitsToShow, b as getQuantities, o as getUnit, a as getUnitsForQuantity, n as getValue, H as isCloseTo, K as isCloseToOrGreaterThan, J as isCloseToOrLessThan, I as isDeepCloseTo, N as isEmptyValueWithUnit, V as isFraction, M as isNonNumerical, L as isNumeric, a1 as isScientificStringNum, a0 as isValidNum, m as isValueWithUnit, l as label, X as numFraction, A as round, E as roundByMagnitude, F as roundByMagnitudeToFixed, G as roundByRange, r as roundNumberWithLabel, D as roundToDecimalPrecision, B as roundToFixed, C as roundToPrecision, s as showAltUnitsList, e as split, a2 as stripLeadingZeros, t as to, h as toBase, _ as toNum, $ as toString, u as unitFromKey, d as unitFromQuantity, f as unum, k as unumWithUnit, v as validateAndClean, z as validateNumber, y as withPrettyUnitLabel, w as withUnit } from './units-eowpZ327.js';
2
+ import 'fraction.js';