@oliasoft-open-source/units 4.7.0 → 5.0.0

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