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