@oliasoft-open-source/units 4.5.2-beta-1 → 4.5.3-beta-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/numbers/numbers.cjs +1 -1
- package/dist/numbers/numbers.js +1 -1
- package/dist/{units-CJ3ckQN8.cjs → units-B3mFL4mq.cjs} +115 -60
- package/dist/{units-CrmXBjNL.js → units-COuQAjLd.js} +115 -60
- package/dist/units.cjs +1 -1
- package/dist/units.js +1 -1
- package/package.json +13 -15
package/dist/index.cjs
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -355,7 +355,7 @@ declare const roundToFixed: <Value extends number | string | null | undefined>(v
|
|
|
355
355
|
type Without<T, U> = {
|
|
356
356
|
[P in Exclude<keyof T, keyof U>]?: never;
|
|
357
357
|
};
|
|
358
|
-
type XOR<T, U> =
|
|
358
|
+
type XOR<T, U> = T | U extends Record<string, unknown> ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
|
|
359
359
|
type toleranceType = XOR<{
|
|
360
360
|
relativeDiff: number | string;
|
|
361
361
|
}, {
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { a3 as ALT_UNITS, a7 as DEPRECATED_UNITS, a9 as INTERMEDIATE_CONVERSIONS, a6 as KNOWN_CONVERSIONS, aa as KNOWN_UNITS, a4 as LABELS, ab as QUANTITIES_DESCRIPTION, ac as UNITS_DESCRIPTION, a8 as UNIT_ALIASES, a5 as UNIT_FROM_KEY, O as allNumbers, i as altUnitsList, W as asFraction, S as charCount, c as checkAndCleanDecimalComma, Z as cleanNum, Y as cleanNumStr, q as convertAndGetValue, x as convertAndGetValueStrict, p as convertSamePrecision, j as convertTable, Q as displayNumber, R as displayNumberToFixed, P as formatNumber, U as fraction, g as getAltUnitsListByQuantity, T as getNumberOfDigitsToShow, b as getQuantities, o as getUnit, a as getUnitsForQuantity, n as getValue, H as isCloseTo, K as isCloseToOrGreaterThan, J as isCloseToOrLessThan, I as isDeepCloseTo, N as isEmptyValueWithUnit, V as isFraction, M as isNonNumerical, L as isNumeric, a1 as isScientificStringNum, a0 as isValidNum, m as isValueWithUnit, l as label, X as numFraction, A as round, E as roundByMagnitude, F as roundByMagnitudeToFixed, G as roundByRange, r as roundNumberWithLabel, D as roundToDecimalPrecision, B as roundToFixed, C as roundToPrecision, s as showAltUnitsList, e as split, a2 as stripLeadingZeros, t as to, h as toBase, _ as toNum, $ as toString, u as unitFromKey, d as unitFromQuantity, f as unum, k as unumWithUnit, v as validateAndClean, z as validateNumber, y as withPrettyUnitLabel, w as withUnit } from './units-
|
|
1
|
+
export { a3 as ALT_UNITS, a7 as DEPRECATED_UNITS, a9 as INTERMEDIATE_CONVERSIONS, a6 as KNOWN_CONVERSIONS, aa as KNOWN_UNITS, a4 as LABELS, ab as QUANTITIES_DESCRIPTION, ac as UNITS_DESCRIPTION, a8 as UNIT_ALIASES, a5 as UNIT_FROM_KEY, O as allNumbers, i as altUnitsList, W as asFraction, S as charCount, c as checkAndCleanDecimalComma, Z as cleanNum, Y as cleanNumStr, q as convertAndGetValue, x as convertAndGetValueStrict, p as convertSamePrecision, j as convertTable, Q as displayNumber, R as displayNumberToFixed, P as formatNumber, U as fraction, g as getAltUnitsListByQuantity, T as getNumberOfDigitsToShow, b as getQuantities, o as getUnit, a as getUnitsForQuantity, n as getValue, H as isCloseTo, K as isCloseToOrGreaterThan, J as isCloseToOrLessThan, I as isDeepCloseTo, N as isEmptyValueWithUnit, V as isFraction, M as isNonNumerical, L as isNumeric, a1 as isScientificStringNum, a0 as isValidNum, m as isValueWithUnit, l as label, X as numFraction, A as round, E as roundByMagnitude, F as roundByMagnitudeToFixed, G as roundByRange, r as roundNumberWithLabel, D as roundToDecimalPrecision, B as roundToFixed, C as roundToPrecision, s as showAltUnitsList, e as split, a2 as stripLeadingZeros, t as to, h as toBase, _ as toNum, $ as toString, u as unitFromKey, d as unitFromQuantity, f as unum, k as unumWithUnit, v as validateAndClean, z as validateNumber, y as withPrettyUnitLabel, w as withUnit } from './units-COuQAjLd.js';
|
|
2
2
|
import 'fraction.js';
|
package/dist/numbers/numbers.cjs
CHANGED
package/dist/numbers/numbers.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { a1 as isScientificStringNum, a0 as isValidNum, _ as toNum, $ as toString } from '../units-
|
|
1
|
+
export { a1 as isScientificStringNum, a0 as isValidNum, _ as toNum, $ as toString } from '../units-COuQAjLd.js';
|
|
2
2
|
import 'fraction.js';
|
|
@@ -157,14 +157,18 @@ const isCloseTo = (firstValue, secondValue, options = { relativeDiff: DEFAULT_MA
|
|
|
157
157
|
const hasUnitFirstValue = isValueWithUnit(firstValue);
|
|
158
158
|
const hasUnitSecondValue = isValueWithUnit(secondValue);
|
|
159
159
|
if (hasUnitFirstValue && !hasUnitSecondValue || !hasUnitFirstValue && hasUnitSecondValue) {
|
|
160
|
-
throw new Error(
|
|
160
|
+
throw new Error(
|
|
161
|
+
`Parameters must either both have units or both not have units. Received "${firstValue}" and "${secondValue}"`
|
|
162
|
+
);
|
|
161
163
|
}
|
|
162
164
|
if (toleranceNumber === null) {
|
|
163
165
|
console.warn("Tolerance number is not defined!");
|
|
164
166
|
return firstValue === secondValue;
|
|
165
167
|
}
|
|
166
168
|
if (toleranceNumber <= 0 || toleranceNumber < Number.EPSILON) {
|
|
167
|
-
throw Error(
|
|
169
|
+
throw Error(
|
|
170
|
+
"Unpredictable results - toleranceNumber should be bigger than zero or less then EPSILON"
|
|
171
|
+
);
|
|
168
172
|
}
|
|
169
173
|
const { firstNumber, secondNumber } = convertNumbers(firstValue, secondValue);
|
|
170
174
|
if ((firstNumber === Infinity || firstNumber === "Infinity") && (secondNumber === Infinity || secondNumber === "Infinity") || (firstNumber === -Infinity || firstNumber === "-Infinity") && (secondNumber === -Infinity || secondNumber === "-Infinity")) {
|
|
@@ -176,7 +180,9 @@ const isCloseTo = (firstValue, secondValue, options = { relativeDiff: DEFAULT_MA
|
|
|
176
180
|
const diff2 = Math.abs(firstNumber - secondNumber);
|
|
177
181
|
return isCloseTo(diff2, toleranceNumber, { relativeDiff: "1%" }) || diff2 < toleranceNumber;
|
|
178
182
|
} else {
|
|
179
|
-
return 2 * Math.abs(
|
|
183
|
+
return 2 * Math.abs(
|
|
184
|
+
(firstNumber - secondNumber) / (firstNumber + secondNumber)
|
|
185
|
+
) < toleranceNumber;
|
|
180
186
|
}
|
|
181
187
|
}
|
|
182
188
|
return false;
|
|
@@ -305,7 +311,11 @@ const roundToDecimalPrecision = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
|
|
|
305
311
|
};
|
|
306
312
|
const roundNumberByMagnitude = (value, n = DEFAULT_SIGNIFICANT_DIGITS, toFixed = false) => {
|
|
307
313
|
const noDecimalsAbove = 10 ** n;
|
|
308
|
-
const result = noDecimalsAbove && value > noDecimalsAbove ? roundNumber(value, 0) : toFixed ? roundNumberToFixedPrecision(value, n) :
|
|
314
|
+
const result = noDecimalsAbove && value > noDecimalsAbove ? roundNumber(value, 0) : toFixed ? roundNumberToFixedPrecision(value, n) : (
|
|
315
|
+
//for comparison, old implementation from toPretty (functionally equivalent to new implementation, see tests)
|
|
316
|
+
//return Number(value.toExponential(n - 1).toString());
|
|
317
|
+
roundNumberToPrecision(value, n)
|
|
318
|
+
);
|
|
309
319
|
return toFixed ? String(result) : result;
|
|
310
320
|
};
|
|
311
321
|
const roundByMagnitude = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
|
|
@@ -404,11 +414,11 @@ const appendTrailingZeros = (value, numberOfZeros) => {
|
|
|
404
414
|
return numberOfZeros > 0 && value !== "0" ? !value.includes(".") ? `${value}.${zeros}` : `${value}${zeros}` : value;
|
|
405
415
|
};
|
|
406
416
|
const formatDecimal = (value, thousandSeparator, preserveTrailingZeros = false) => {
|
|
407
|
-
const convertedValue = convertNumberToLocale(
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
) : convertedValue;
|
|
417
|
+
const convertedValue = convertNumberToLocale(
|
|
418
|
+
toNum(value),
|
|
419
|
+
"en-US"
|
|
420
|
+
).replaceAll(",", thousandSeparator);
|
|
421
|
+
return preserveTrailingZeros ? appendTrailingZeros(convertedValue, countTrailingZeros(value, true)) : convertedValue;
|
|
412
422
|
};
|
|
413
423
|
const formatDecimalDisplayNumber = (value, options) => {
|
|
414
424
|
const { nonBreakingSpace } = options ?? {};
|
|
@@ -425,10 +435,7 @@ const formatDecimalDisplayNumber = (value, options) => {
|
|
|
425
435
|
return formatDecimal(value, space, options?.preserveTrailingZeros);
|
|
426
436
|
};
|
|
427
437
|
const formatScientificDisplayNumber = (value, options) => {
|
|
428
|
-
const {
|
|
429
|
-
roundScientificCoefficient,
|
|
430
|
-
eNotation
|
|
431
|
-
} = options ?? {};
|
|
438
|
+
const { roundScientificCoefficient, eNotation } = options ?? {};
|
|
432
439
|
if (Number.isNaN(value)) {
|
|
433
440
|
return "Invalid";
|
|
434
441
|
}
|
|
@@ -667,8 +674,8 @@ function cleanNumStr(str) {
|
|
|
667
674
|
}
|
|
668
675
|
const stripLeadingZeros = (value) => {
|
|
669
676
|
const isMinus = value?.[0] === "-";
|
|
670
|
-
const matchMinus = /^-/
|
|
671
|
-
const matchLeadingZeros = /^(?:0+(?=[1-9])|0+(?=0))/
|
|
677
|
+
const matchMinus = /^-/gm;
|
|
678
|
+
const matchLeadingZeros = /^(?:0+(?=[1-9])|0+(?=0))/gm;
|
|
672
679
|
const cleanedValue = value.replace(matchMinus, "").replace(matchLeadingZeros, "");
|
|
673
680
|
return isMinus ? `-${cleanedValue}` : cleanedValue;
|
|
674
681
|
};
|
|
@@ -698,7 +705,9 @@ function newton(f, df, x0, tol = 1e-8, max_iter = 30) {
|
|
|
698
705
|
}
|
|
699
706
|
function erf(z) {
|
|
700
707
|
const t = 1 / (1 + 0.5 * abs(z));
|
|
701
|
-
const ans = 1 - t * exp(
|
|
708
|
+
const ans = 1 - t * exp(
|
|
709
|
+
-(z ** 2) - 1.26551223 + t * (1.00002368 + t * (0.37409196 + t * (0.09678418 + t * (-0.18628806 + t * (0.27886807 + t * (-1.13520398 + t * (1.48851587 + t * (-0.82215223 + t * 0.17087277))))))))
|
|
710
|
+
);
|
|
702
711
|
return z >= 0 ? ans : -ans;
|
|
703
712
|
}
|
|
704
713
|
function get_k_from_conf_int(a) {
|
|
@@ -729,7 +738,9 @@ function normalizeScientific(val) {
|
|
|
729
738
|
const fixedLeft = normalizeExponent(val2.trim());
|
|
730
739
|
return `${fixedLeft}|${unit.trim()}`;
|
|
731
740
|
}
|
|
732
|
-
const m = s.match(
|
|
741
|
+
const m = s.match(
|
|
742
|
+
/^([+-]?(?:\d+(?:\.\d*)?|\.\d+)\s*[eE]\s*[+-]?\s*\d+)\s+(.+)$/
|
|
743
|
+
);
|
|
733
744
|
if (m) return `${normalizeExponent(m[1])}|${m[2].trim()}`;
|
|
734
745
|
return normalizeExponent(s);
|
|
735
746
|
}
|
|
@@ -882,9 +893,9 @@ const LABELS = Object.freeze({
|
|
|
882
893
|
mph: "mph",
|
|
883
894
|
"km/h": "km/h",
|
|
884
895
|
"m/s2": "m/s\xB2",
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
896
|
+
Gs: "Gs",
|
|
897
|
+
nT: "nT",
|
|
898
|
+
g: "g",
|
|
888
899
|
"ft/s2": "ft/s\xB2",
|
|
889
900
|
"Pa*s": "Pa\u22C5s",
|
|
890
901
|
P: "P",
|
|
@@ -952,7 +963,15 @@ const LABELS = Object.freeze({
|
|
|
952
963
|
});
|
|
953
964
|
const ALT_UNITS = Object.freeze({
|
|
954
965
|
acceleration: ["ft/s2", "m/s2"],
|
|
955
|
-
angleGradient: [
|
|
966
|
+
angleGradient: [
|
|
967
|
+
"deg/30m",
|
|
968
|
+
"rad/m",
|
|
969
|
+
"deg/m",
|
|
970
|
+
"deg/ft",
|
|
971
|
+
"rad/ft",
|
|
972
|
+
"deg/100ft",
|
|
973
|
+
"deg/10m"
|
|
974
|
+
],
|
|
956
975
|
angles: ["deg", "rad"],
|
|
957
976
|
areaOther: ["in2", "ft2", "mm2", "cm2", "m2", "mile2", "km2"],
|
|
958
977
|
areaTubular: ["in2", "cm2", "ft2", "m2"],
|
|
@@ -1025,23 +1044,36 @@ const ALT_UNITS = Object.freeze({
|
|
|
1025
1044
|
permeability: ["mD", "m2"],
|
|
1026
1045
|
power: ["hp", "W", "hhp", "MW", "kW", "BTU/h"],
|
|
1027
1046
|
pressure: ["bar", "psi", "Pa", "kPa", "MPa", "ksi", "GPa", "lbf/100ft2"],
|
|
1028
|
-
pressureGradient: [
|
|
1047
|
+
pressureGradient: [
|
|
1048
|
+
"bar/100m",
|
|
1049
|
+
"Pa/m",
|
|
1050
|
+
"bar/m",
|
|
1051
|
+
"psi/100ft",
|
|
1052
|
+
"psi/ft",
|
|
1053
|
+
"kPa/m"
|
|
1054
|
+
],
|
|
1029
1055
|
pressurechange: ["bar", "psi", "Pa", "MPa", "kPa"],
|
|
1030
1056
|
gasliftFlowRate: ["STB/d", "Sm3/d", "SCF/d"],
|
|
1031
1057
|
productionFlowRate: ["MMSCFD", "STB/d", "Sm3/d", "MSm3/d", "SCF/d"],
|
|
1032
1058
|
productionFlowRateOil: ["MMSCFD", "STB/d", "Sm3/d", "MSm3/d", "SCF/d"],
|
|
1033
1059
|
productionFlowRateGas: ["MMSCFD", "STB/d", "Sm3/d", "MSm3/d", "SCF/d"],
|
|
1034
|
-
injectionFlowRate: [
|
|
1060
|
+
injectionFlowRate: [
|
|
1061
|
+
"lpm",
|
|
1062
|
+
"lps",
|
|
1063
|
+
"bpm",
|
|
1064
|
+
"gpm",
|
|
1065
|
+
"MMSCFD",
|
|
1066
|
+
"STB/d",
|
|
1067
|
+
"Sm3/d",
|
|
1068
|
+
"MSm3/d",
|
|
1069
|
+
"SCF/d"
|
|
1070
|
+
],
|
|
1035
1071
|
pumpRate: ["lpm", "lps", "bpm", "m3/s", "ft3/s", "gpm"],
|
|
1036
1072
|
rotationalSpeed: ["rpm", "Hz"],
|
|
1037
1073
|
roughness: ["m", "microM", "in"],
|
|
1038
1074
|
rpm: ["rpm", "Hz"],
|
|
1039
1075
|
sdstats: ["CI", "Sigma"],
|
|
1040
|
-
specificHeatCapacity: [
|
|
1041
|
-
"J/(kg*degC)",
|
|
1042
|
-
"J/(kg*degK)",
|
|
1043
|
-
"BTU/(lbm*degF)"
|
|
1044
|
-
],
|
|
1076
|
+
specificHeatCapacity: ["J/(kg*degC)", "J/(kg*degK)", "BTU/(lbm*degF)"],
|
|
1045
1077
|
speed: ["km/h", "ft/min", "mph", "ft/h", "ft/s", "m/min", "m/s", "m/h"],
|
|
1046
1078
|
inverseStandSpeed: ["d/stand", "h/stand", "min/stand", "s/stand"],
|
|
1047
1079
|
rop: ["ft/h", "ft/min", "ft/s", "km/h", "m/h", "m/min", "m/s", "mph"],
|
|
@@ -1049,10 +1081,7 @@ const ALT_UNITS = Object.freeze({
|
|
|
1049
1081
|
temperature: ["C", "F", "K"],
|
|
1050
1082
|
pressurePerTemperature: ["Pa/C", "Bar/C", "psi/F", "psi/C"],
|
|
1051
1083
|
tempgrad: ["C/100m", "F/100ft", "K/100m", "C/m", "F/ft", "K/m"],
|
|
1052
|
-
thermalConductivity: [
|
|
1053
|
-
"BTU/(h*ft*degF)",
|
|
1054
|
-
"W/(mK)"
|
|
1055
|
-
],
|
|
1084
|
+
thermalConductivity: ["BTU/(h*ft*degF)", "W/(mK)"],
|
|
1056
1085
|
thermalExpansionCoefficient: ["E-06/degC", "E-06/degF", "1/K"],
|
|
1057
1086
|
torque: ["Nm", "ftlbf", "kNm"],
|
|
1058
1087
|
torqueGradient: ["N", "lbf", "tonnes"],
|
|
@@ -1072,15 +1101,7 @@ const ALT_UNITS = Object.freeze({
|
|
|
1072
1101
|
"MSm3",
|
|
1073
1102
|
"SCF"
|
|
1074
1103
|
],
|
|
1075
|
-
kickToleranceVolume: [
|
|
1076
|
-
"m3",
|
|
1077
|
-
"bbl",
|
|
1078
|
-
"USGal",
|
|
1079
|
-
"ft3",
|
|
1080
|
-
"STB",
|
|
1081
|
-
"Sm3",
|
|
1082
|
-
"SCF"
|
|
1083
|
-
],
|
|
1104
|
+
kickToleranceVolume: ["m3", "bbl", "USGal", "ft3", "STB", "Sm3", "SCF"],
|
|
1084
1105
|
weight: ["tonnes", "kg", "lbf", "mt", "kip", "N"],
|
|
1085
1106
|
weightGradient: ["ppf", "kg/m"],
|
|
1086
1107
|
wgrad: ["sg", "ppg"],
|
|
@@ -1092,7 +1113,20 @@ const ALT_UNITS = Object.freeze({
|
|
|
1092
1113
|
shearStress: ["Pa", "lbf/100ft2"],
|
|
1093
1114
|
sensorAccelerometer: ["g", "m/s2"],
|
|
1094
1115
|
sensorMagnetometer: ["nT", "Gs"],
|
|
1095
|
-
location: [
|
|
1116
|
+
location: [
|
|
1117
|
+
"lk",
|
|
1118
|
+
"ftCla",
|
|
1119
|
+
"lkCla",
|
|
1120
|
+
"ftSe",
|
|
1121
|
+
"ydSe",
|
|
1122
|
+
"chSe",
|
|
1123
|
+
"chSe(T)",
|
|
1124
|
+
"ftGC",
|
|
1125
|
+
"ydInd",
|
|
1126
|
+
"ft",
|
|
1127
|
+
"m",
|
|
1128
|
+
"usft"
|
|
1129
|
+
],
|
|
1096
1130
|
mixingRequirements: ["m3/t", "L/100kg"],
|
|
1097
1131
|
entalphy: ["J/kg", "kJ/kg", "BTU/lbm"]
|
|
1098
1132
|
});
|
|
@@ -1184,8 +1218,17 @@ const C = Object.freeze({
|
|
|
1184
1218
|
day_to_second: 60 * 60 * 24,
|
|
1185
1219
|
m3_per_m_to_ft3_per_ft: 10.763910416709722,
|
|
1186
1220
|
// https://www.wolframalpha.com/input?i=cubic+meter+per+meter++to+feet+cubic+per+foot&assumption=%7B%22F%22%2C+%22UnitsConversion2%22%2C+%22fromValue%22%7D+-%3E%220.100000000000000000%22
|
|
1187
|
-
in3_per_ft_to_m3_per_m: 537633333333e-16
|
|
1221
|
+
in3_per_ft_to_m3_per_m: 537633333333e-16,
|
|
1188
1222
|
// 1 / m3_per_m_to_ft3_per_ft / ft3_to_in3 = 0.000053763333333333334 https://www.wolframalpha.com/input?i=cubic+meter+per+meter++to+feet+cubic+per+foot&assumption=%7B%22F%22%2C+%22UnitsConversion2%22%2C+%22fromValue%22%7D+-%3E%220.100000000000000000%22
|
|
1223
|
+
/* OW-24122 Flow rate conversion MSm³/d
|
|
1224
|
+
`Mega Standard Cubic Metre per day` (`MSm3/d`) <-> `meters cubed per second` (`m3/s`)
|
|
1225
|
+
1 `MSm3/d`
|
|
1226
|
+
= `1 * 625/54` `m3/s` (https://www.wolframalpha.com/input?i=Mega+Standard+Cubic+Metre+per+day)
|
|
1227
|
+
= `1 / (86400 * 1e-6)` `m3/s` (OW-24122)
|
|
1228
|
+
= `11.5740740741`
|
|
1229
|
+
We can represent this as `625 / 54` or `1_000_000 / 86400`
|
|
1230
|
+
*/
|
|
1231
|
+
MSm3d_to_m3s: 625 / 54
|
|
1189
1232
|
});
|
|
1190
1233
|
const KNOWN_CONVERSIONS = Object.freeze({
|
|
1191
1234
|
// LENGTH
|
|
@@ -1323,8 +1366,8 @@ const KNOWN_CONVERSIONS = Object.freeze({
|
|
|
1323
1366
|
"kg|tonnes": (val) => val / 1e3,
|
|
1324
1367
|
"kg|mt": (val) => val / 1e3,
|
|
1325
1368
|
/*
|
|
1326
|
-
|
|
1327
|
-
|
|
1369
|
+
1 kip = 1000 lbf - https://en.wikipedia.org/wiki/Kip_(unit)
|
|
1370
|
+
*/
|
|
1328
1371
|
"kg|kip": (val) => val * C.kg_to_lbf * 1e-3,
|
|
1329
1372
|
"kgf|kg": (val) => val,
|
|
1330
1373
|
"lbf|kg": (val) => val * C.lbf_to_kg,
|
|
@@ -1392,7 +1435,7 @@ const KNOWN_CONVERSIONS = Object.freeze({
|
|
|
1392
1435
|
"m3/s|MMSCFD": (val) => val / 0.32774128,
|
|
1393
1436
|
"m3/s|STB/d": (val) => val * 1346875e8 / 247854343,
|
|
1394
1437
|
"m3/s|Sm3/d": (val) => val * C.day_to_second,
|
|
1395
|
-
"m3/s|MSm3/d": (val) => val /
|
|
1438
|
+
"m3/s|MSm3/d": (val) => val / C.MSm3d_to_m3s,
|
|
1396
1439
|
"m3/s|SCF/d": (val) => val * 3.0511872047366146e6,
|
|
1397
1440
|
"ft3/s|m3/s": (val) => val * C.ft3_to_m3,
|
|
1398
1441
|
"lpm|m3/s": (val) => val / 6e4,
|
|
@@ -1412,9 +1455,9 @@ const KNOWN_CONVERSIONS = Object.freeze({
|
|
|
1412
1455
|
"Mm3/d|m3/d": (val) => val * 1e6,
|
|
1413
1456
|
"m3/d|Mm3/d": (val) => val * 1e-6,
|
|
1414
1457
|
/*
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1458
|
+
exact formula is 247854343 / 134687500000000 = 0.0000018402178598607888 - https://www.wolframalpha.com/input?i=STB%2Fd
|
|
1459
|
+
STB has a lot of intermediate conversions, so to avoid delta during conversions trip we have to store 2 more digits
|
|
1460
|
+
*/
|
|
1418
1461
|
"STB/d|m3/s": (val) => val * 184021785986e-17,
|
|
1419
1462
|
"Sm3/d|m3/d": (val) => val,
|
|
1420
1463
|
// At a pressure of 101.325 kPa (760 Torr) and DIN 1343: a temperature of 273.15 K (0°C/32°F) | NOTE: Thomas suggested that we leep those conversions 1to1,
|
|
@@ -1423,7 +1466,7 @@ const KNOWN_CONVERSIONS = Object.freeze({
|
|
|
1423
1466
|
"Sm3/d|m3/s": (val) => val / C.day_to_second,
|
|
1424
1467
|
"MSm3/d|Sm3/d": (val) => val * 1e6,
|
|
1425
1468
|
"Sm3/d|MSm3/d": (val) => val * 1e-6,
|
|
1426
|
-
"MSm3/d|m3/s": (val) => val *
|
|
1469
|
+
"MSm3/d|m3/s": (val) => val * C.MSm3d_to_m3s,
|
|
1427
1470
|
"SCF/d|m3/s": (val) => val * 32774128e-14,
|
|
1428
1471
|
// TURBULENT SKIN
|
|
1429
1472
|
"1/m3/d|1/MMSCFD": (val) => val * 28316.85,
|
|
@@ -1880,9 +1923,13 @@ const INTERMEDIATE_CONVERSIONS = Object.freeze({
|
|
|
1880
1923
|
//Entalphy
|
|
1881
1924
|
"BTU/lbm": "J/kg"
|
|
1882
1925
|
});
|
|
1883
|
-
const KNOWN_UNITS = Object.freeze(
|
|
1926
|
+
const KNOWN_UNITS = Object.freeze(
|
|
1927
|
+
Array.from(new Set(Object.values(ALT_UNITS).flat()))
|
|
1928
|
+
);
|
|
1884
1929
|
const SPECIAL_NUMBERS = [NaN, -Infinity, Infinity];
|
|
1885
|
-
const SPECIAL_NUMBERS_STRING = SPECIAL_NUMBERS.map(
|
|
1930
|
+
const SPECIAL_NUMBERS_STRING = SPECIAL_NUMBERS.map(
|
|
1931
|
+
(number) => number.toString()
|
|
1932
|
+
);
|
|
1886
1933
|
const QUANTITIES_DESCRIPTION = {
|
|
1887
1934
|
density: "Density",
|
|
1888
1935
|
length: "Length",
|
|
@@ -2406,7 +2453,9 @@ function unum(numWithUnit, toUnit, fromUnit) {
|
|
|
2406
2453
|
if (m[0] == null) m[0] = "0";
|
|
2407
2454
|
if (m[1]) fromUnit = m[1];
|
|
2408
2455
|
if (!fromUnit && toUnit !== fromUnit) {
|
|
2409
|
-
throw new Error(
|
|
2456
|
+
throw new Error(
|
|
2457
|
+
`unum: unable to figure out unit: ${numWithUnit} fromUnit ${fromUnit}`
|
|
2458
|
+
);
|
|
2410
2459
|
}
|
|
2411
2460
|
if (toUnit === fromUnit) {
|
|
2412
2461
|
const v = m[0] ? toNum(m[0]) : 0;
|
|
@@ -2475,10 +2524,7 @@ function convertTable(toUnitRow, table, defaultUnitRow, removeFinalUnitsRow = fa
|
|
|
2475
2524
|
return newTable;
|
|
2476
2525
|
}
|
|
2477
2526
|
function roundNumberWithLabel(value, n = 2) {
|
|
2478
|
-
return displayNumber(
|
|
2479
|
-
round(value, n),
|
|
2480
|
-
{ withUnit: true }
|
|
2481
|
-
);
|
|
2527
|
+
return displayNumber(round(value, n), { withUnit: true });
|
|
2482
2528
|
}
|
|
2483
2529
|
function withUnit(value, unit, defaultVal = "") {
|
|
2484
2530
|
if (value === null || value === "" || value === void 0) {
|
|
@@ -2526,7 +2572,10 @@ function convertSamePrecision(numWithUnit, toUnit, digits) {
|
|
|
2526
2572
|
let j = prettyNumber.length;
|
|
2527
2573
|
if (prettyNumber[--j] == "0") {
|
|
2528
2574
|
while (prettyNumber[--j] == "0") ;
|
|
2529
|
-
prettyNumber = prettyNumber.slice(
|
|
2575
|
+
prettyNumber = prettyNumber.slice(
|
|
2576
|
+
0,
|
|
2577
|
+
j + (prettyNumber[j] == "." ? 0 : 1)
|
|
2578
|
+
);
|
|
2530
2579
|
}
|
|
2531
2580
|
}
|
|
2532
2581
|
}
|
|
@@ -2538,7 +2587,10 @@ function altUnitsList(value, quantity) {
|
|
|
2538
2587
|
v = withUnit(value, unitFromQuantity(quantity) ?? "");
|
|
2539
2588
|
}
|
|
2540
2589
|
const altUnits = ALT_UNITS[quantity] ?? [];
|
|
2541
|
-
return altUnits.map((unit) => [
|
|
2590
|
+
return altUnits.map((unit) => [
|
|
2591
|
+
...split(convertSamePrecision(v, unit)),
|
|
2592
|
+
label(unit)
|
|
2593
|
+
]);
|
|
2542
2594
|
}
|
|
2543
2595
|
function validateAndClean(previousValue, nextText) {
|
|
2544
2596
|
const unit = split(previousValue)[1];
|
|
@@ -2549,7 +2601,10 @@ function validateAndClean(previousValue, nextText) {
|
|
|
2549
2601
|
const stripDot = /^([^.]*\.)|\./g;
|
|
2550
2602
|
const stripDotFollowedByE = /\.(?=e)/g;
|
|
2551
2603
|
const stripMinus = /-|[eE]-/g;
|
|
2552
|
-
const cleanedValue = nextText.replace(stripAllExceptNumeric, "").replace(stripE, "$1").replace(stripInvalidLeading, "").replace(replaceComma, ".").replace(stripDot, "$1").replace(stripDotFollowedByE, "").replace(
|
|
2604
|
+
const cleanedValue = nextText.replace(stripAllExceptNumeric, "").replace(stripE, "$1").replace(stripInvalidLeading, "").replace(replaceComma, ".").replace(stripDot, "$1").replace(stripDotFollowedByE, "").replace(
|
|
2605
|
+
stripMinus,
|
|
2606
|
+
(match, offset) => offset === 0 || match.toLowerCase() === "e-" ? match : ""
|
|
2607
|
+
);
|
|
2553
2608
|
return !Number.isFinite(+cleanedValue) ? previousValue : `${cleanedValue}${unit ? "|" : ""}${unit}`;
|
|
2554
2609
|
}
|
|
2555
2610
|
function withPrettyUnitLabel(valueWithUnits) {
|
|
@@ -155,14 +155,18 @@ const isCloseTo = (firstValue, secondValue, options = { relativeDiff: DEFAULT_MA
|
|
|
155
155
|
const hasUnitFirstValue = isValueWithUnit(firstValue);
|
|
156
156
|
const hasUnitSecondValue = isValueWithUnit(secondValue);
|
|
157
157
|
if (hasUnitFirstValue && !hasUnitSecondValue || !hasUnitFirstValue && hasUnitSecondValue) {
|
|
158
|
-
throw new Error(
|
|
158
|
+
throw new Error(
|
|
159
|
+
`Parameters must either both have units or both not have units. Received "${firstValue}" and "${secondValue}"`
|
|
160
|
+
);
|
|
159
161
|
}
|
|
160
162
|
if (toleranceNumber === null) {
|
|
161
163
|
console.warn("Tolerance number is not defined!");
|
|
162
164
|
return firstValue === secondValue;
|
|
163
165
|
}
|
|
164
166
|
if (toleranceNumber <= 0 || toleranceNumber < Number.EPSILON) {
|
|
165
|
-
throw Error(
|
|
167
|
+
throw Error(
|
|
168
|
+
"Unpredictable results - toleranceNumber should be bigger than zero or less then EPSILON"
|
|
169
|
+
);
|
|
166
170
|
}
|
|
167
171
|
const { firstNumber, secondNumber } = convertNumbers(firstValue, secondValue);
|
|
168
172
|
if ((firstNumber === Infinity || firstNumber === "Infinity") && (secondNumber === Infinity || secondNumber === "Infinity") || (firstNumber === -Infinity || firstNumber === "-Infinity") && (secondNumber === -Infinity || secondNumber === "-Infinity")) {
|
|
@@ -174,7 +178,9 @@ const isCloseTo = (firstValue, secondValue, options = { relativeDiff: DEFAULT_MA
|
|
|
174
178
|
const diff2 = Math.abs(firstNumber - secondNumber);
|
|
175
179
|
return isCloseTo(diff2, toleranceNumber, { relativeDiff: "1%" }) || diff2 < toleranceNumber;
|
|
176
180
|
} else {
|
|
177
|
-
return 2 * Math.abs(
|
|
181
|
+
return 2 * Math.abs(
|
|
182
|
+
(firstNumber - secondNumber) / (firstNumber + secondNumber)
|
|
183
|
+
) < toleranceNumber;
|
|
178
184
|
}
|
|
179
185
|
}
|
|
180
186
|
return false;
|
|
@@ -303,7 +309,11 @@ const roundToDecimalPrecision = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
|
|
|
303
309
|
};
|
|
304
310
|
const roundNumberByMagnitude = (value, n = DEFAULT_SIGNIFICANT_DIGITS, toFixed = false) => {
|
|
305
311
|
const noDecimalsAbove = 10 ** n;
|
|
306
|
-
const result = noDecimalsAbove && value > noDecimalsAbove ? roundNumber(value, 0) : toFixed ? roundNumberToFixedPrecision(value, n) :
|
|
312
|
+
const result = noDecimalsAbove && value > noDecimalsAbove ? roundNumber(value, 0) : toFixed ? roundNumberToFixedPrecision(value, n) : (
|
|
313
|
+
//for comparison, old implementation from toPretty (functionally equivalent to new implementation, see tests)
|
|
314
|
+
//return Number(value.toExponential(n - 1).toString());
|
|
315
|
+
roundNumberToPrecision(value, n)
|
|
316
|
+
);
|
|
307
317
|
return toFixed ? String(result) : result;
|
|
308
318
|
};
|
|
309
319
|
const roundByMagnitude = (value, n = DEFAULT_SIGNIFICANT_DIGITS) => {
|
|
@@ -402,11 +412,11 @@ const appendTrailingZeros = (value, numberOfZeros) => {
|
|
|
402
412
|
return numberOfZeros > 0 && value !== "0" ? !value.includes(".") ? `${value}.${zeros}` : `${value}${zeros}` : value;
|
|
403
413
|
};
|
|
404
414
|
const formatDecimal = (value, thousandSeparator, preserveTrailingZeros = false) => {
|
|
405
|
-
const convertedValue = convertNumberToLocale(
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
) : convertedValue;
|
|
415
|
+
const convertedValue = convertNumberToLocale(
|
|
416
|
+
toNum(value),
|
|
417
|
+
"en-US"
|
|
418
|
+
).replaceAll(",", thousandSeparator);
|
|
419
|
+
return preserveTrailingZeros ? appendTrailingZeros(convertedValue, countTrailingZeros(value, true)) : convertedValue;
|
|
410
420
|
};
|
|
411
421
|
const formatDecimalDisplayNumber = (value, options) => {
|
|
412
422
|
const { nonBreakingSpace } = options ?? {};
|
|
@@ -423,10 +433,7 @@ const formatDecimalDisplayNumber = (value, options) => {
|
|
|
423
433
|
return formatDecimal(value, space, options?.preserveTrailingZeros);
|
|
424
434
|
};
|
|
425
435
|
const formatScientificDisplayNumber = (value, options) => {
|
|
426
|
-
const {
|
|
427
|
-
roundScientificCoefficient,
|
|
428
|
-
eNotation
|
|
429
|
-
} = options ?? {};
|
|
436
|
+
const { roundScientificCoefficient, eNotation } = options ?? {};
|
|
430
437
|
if (Number.isNaN(value)) {
|
|
431
438
|
return "Invalid";
|
|
432
439
|
}
|
|
@@ -665,8 +672,8 @@ function cleanNumStr(str) {
|
|
|
665
672
|
}
|
|
666
673
|
const stripLeadingZeros = (value) => {
|
|
667
674
|
const isMinus = value?.[0] === "-";
|
|
668
|
-
const matchMinus = /^-/
|
|
669
|
-
const matchLeadingZeros = /^(?:0+(?=[1-9])|0+(?=0))/
|
|
675
|
+
const matchMinus = /^-/gm;
|
|
676
|
+
const matchLeadingZeros = /^(?:0+(?=[1-9])|0+(?=0))/gm;
|
|
670
677
|
const cleanedValue = value.replace(matchMinus, "").replace(matchLeadingZeros, "");
|
|
671
678
|
return isMinus ? `-${cleanedValue}` : cleanedValue;
|
|
672
679
|
};
|
|
@@ -696,7 +703,9 @@ function newton(f, df, x0, tol = 1e-8, max_iter = 30) {
|
|
|
696
703
|
}
|
|
697
704
|
function erf(z) {
|
|
698
705
|
const t = 1 / (1 + 0.5 * abs(z));
|
|
699
|
-
const ans = 1 - t * exp(
|
|
706
|
+
const ans = 1 - t * exp(
|
|
707
|
+
-(z ** 2) - 1.26551223 + t * (1.00002368 + t * (0.37409196 + t * (0.09678418 + t * (-0.18628806 + t * (0.27886807 + t * (-1.13520398 + t * (1.48851587 + t * (-0.82215223 + t * 0.17087277))))))))
|
|
708
|
+
);
|
|
700
709
|
return z >= 0 ? ans : -ans;
|
|
701
710
|
}
|
|
702
711
|
function get_k_from_conf_int(a) {
|
|
@@ -727,7 +736,9 @@ function normalizeScientific(val) {
|
|
|
727
736
|
const fixedLeft = normalizeExponent(val2.trim());
|
|
728
737
|
return `${fixedLeft}|${unit.trim()}`;
|
|
729
738
|
}
|
|
730
|
-
const m = s.match(
|
|
739
|
+
const m = s.match(
|
|
740
|
+
/^([+-]?(?:\d+(?:\.\d*)?|\.\d+)\s*[eE]\s*[+-]?\s*\d+)\s+(.+)$/
|
|
741
|
+
);
|
|
731
742
|
if (m) return `${normalizeExponent(m[1])}|${m[2].trim()}`;
|
|
732
743
|
return normalizeExponent(s);
|
|
733
744
|
}
|
|
@@ -880,9 +891,9 @@ const LABELS = Object.freeze({
|
|
|
880
891
|
mph: "mph",
|
|
881
892
|
"km/h": "km/h",
|
|
882
893
|
"m/s2": "m/s\xB2",
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
894
|
+
Gs: "Gs",
|
|
895
|
+
nT: "nT",
|
|
896
|
+
g: "g",
|
|
886
897
|
"ft/s2": "ft/s\xB2",
|
|
887
898
|
"Pa*s": "Pa\u22C5s",
|
|
888
899
|
P: "P",
|
|
@@ -950,7 +961,15 @@ const LABELS = Object.freeze({
|
|
|
950
961
|
});
|
|
951
962
|
const ALT_UNITS = Object.freeze({
|
|
952
963
|
acceleration: ["ft/s2", "m/s2"],
|
|
953
|
-
angleGradient: [
|
|
964
|
+
angleGradient: [
|
|
965
|
+
"deg/30m",
|
|
966
|
+
"rad/m",
|
|
967
|
+
"deg/m",
|
|
968
|
+
"deg/ft",
|
|
969
|
+
"rad/ft",
|
|
970
|
+
"deg/100ft",
|
|
971
|
+
"deg/10m"
|
|
972
|
+
],
|
|
954
973
|
angles: ["deg", "rad"],
|
|
955
974
|
areaOther: ["in2", "ft2", "mm2", "cm2", "m2", "mile2", "km2"],
|
|
956
975
|
areaTubular: ["in2", "cm2", "ft2", "m2"],
|
|
@@ -1023,23 +1042,36 @@ const ALT_UNITS = Object.freeze({
|
|
|
1023
1042
|
permeability: ["mD", "m2"],
|
|
1024
1043
|
power: ["hp", "W", "hhp", "MW", "kW", "BTU/h"],
|
|
1025
1044
|
pressure: ["bar", "psi", "Pa", "kPa", "MPa", "ksi", "GPa", "lbf/100ft2"],
|
|
1026
|
-
pressureGradient: [
|
|
1045
|
+
pressureGradient: [
|
|
1046
|
+
"bar/100m",
|
|
1047
|
+
"Pa/m",
|
|
1048
|
+
"bar/m",
|
|
1049
|
+
"psi/100ft",
|
|
1050
|
+
"psi/ft",
|
|
1051
|
+
"kPa/m"
|
|
1052
|
+
],
|
|
1027
1053
|
pressurechange: ["bar", "psi", "Pa", "MPa", "kPa"],
|
|
1028
1054
|
gasliftFlowRate: ["STB/d", "Sm3/d", "SCF/d"],
|
|
1029
1055
|
productionFlowRate: ["MMSCFD", "STB/d", "Sm3/d", "MSm3/d", "SCF/d"],
|
|
1030
1056
|
productionFlowRateOil: ["MMSCFD", "STB/d", "Sm3/d", "MSm3/d", "SCF/d"],
|
|
1031
1057
|
productionFlowRateGas: ["MMSCFD", "STB/d", "Sm3/d", "MSm3/d", "SCF/d"],
|
|
1032
|
-
injectionFlowRate: [
|
|
1058
|
+
injectionFlowRate: [
|
|
1059
|
+
"lpm",
|
|
1060
|
+
"lps",
|
|
1061
|
+
"bpm",
|
|
1062
|
+
"gpm",
|
|
1063
|
+
"MMSCFD",
|
|
1064
|
+
"STB/d",
|
|
1065
|
+
"Sm3/d",
|
|
1066
|
+
"MSm3/d",
|
|
1067
|
+
"SCF/d"
|
|
1068
|
+
],
|
|
1033
1069
|
pumpRate: ["lpm", "lps", "bpm", "m3/s", "ft3/s", "gpm"],
|
|
1034
1070
|
rotationalSpeed: ["rpm", "Hz"],
|
|
1035
1071
|
roughness: ["m", "microM", "in"],
|
|
1036
1072
|
rpm: ["rpm", "Hz"],
|
|
1037
1073
|
sdstats: ["CI", "Sigma"],
|
|
1038
|
-
specificHeatCapacity: [
|
|
1039
|
-
"J/(kg*degC)",
|
|
1040
|
-
"J/(kg*degK)",
|
|
1041
|
-
"BTU/(lbm*degF)"
|
|
1042
|
-
],
|
|
1074
|
+
specificHeatCapacity: ["J/(kg*degC)", "J/(kg*degK)", "BTU/(lbm*degF)"],
|
|
1043
1075
|
speed: ["km/h", "ft/min", "mph", "ft/h", "ft/s", "m/min", "m/s", "m/h"],
|
|
1044
1076
|
inverseStandSpeed: ["d/stand", "h/stand", "min/stand", "s/stand"],
|
|
1045
1077
|
rop: ["ft/h", "ft/min", "ft/s", "km/h", "m/h", "m/min", "m/s", "mph"],
|
|
@@ -1047,10 +1079,7 @@ const ALT_UNITS = Object.freeze({
|
|
|
1047
1079
|
temperature: ["C", "F", "K"],
|
|
1048
1080
|
pressurePerTemperature: ["Pa/C", "Bar/C", "psi/F", "psi/C"],
|
|
1049
1081
|
tempgrad: ["C/100m", "F/100ft", "K/100m", "C/m", "F/ft", "K/m"],
|
|
1050
|
-
thermalConductivity: [
|
|
1051
|
-
"BTU/(h*ft*degF)",
|
|
1052
|
-
"W/(mK)"
|
|
1053
|
-
],
|
|
1082
|
+
thermalConductivity: ["BTU/(h*ft*degF)", "W/(mK)"],
|
|
1054
1083
|
thermalExpansionCoefficient: ["E-06/degC", "E-06/degF", "1/K"],
|
|
1055
1084
|
torque: ["Nm", "ftlbf", "kNm"],
|
|
1056
1085
|
torqueGradient: ["N", "lbf", "tonnes"],
|
|
@@ -1070,15 +1099,7 @@ const ALT_UNITS = Object.freeze({
|
|
|
1070
1099
|
"MSm3",
|
|
1071
1100
|
"SCF"
|
|
1072
1101
|
],
|
|
1073
|
-
kickToleranceVolume: [
|
|
1074
|
-
"m3",
|
|
1075
|
-
"bbl",
|
|
1076
|
-
"USGal",
|
|
1077
|
-
"ft3",
|
|
1078
|
-
"STB",
|
|
1079
|
-
"Sm3",
|
|
1080
|
-
"SCF"
|
|
1081
|
-
],
|
|
1102
|
+
kickToleranceVolume: ["m3", "bbl", "USGal", "ft3", "STB", "Sm3", "SCF"],
|
|
1082
1103
|
weight: ["tonnes", "kg", "lbf", "mt", "kip", "N"],
|
|
1083
1104
|
weightGradient: ["ppf", "kg/m"],
|
|
1084
1105
|
wgrad: ["sg", "ppg"],
|
|
@@ -1090,7 +1111,20 @@ const ALT_UNITS = Object.freeze({
|
|
|
1090
1111
|
shearStress: ["Pa", "lbf/100ft2"],
|
|
1091
1112
|
sensorAccelerometer: ["g", "m/s2"],
|
|
1092
1113
|
sensorMagnetometer: ["nT", "Gs"],
|
|
1093
|
-
location: [
|
|
1114
|
+
location: [
|
|
1115
|
+
"lk",
|
|
1116
|
+
"ftCla",
|
|
1117
|
+
"lkCla",
|
|
1118
|
+
"ftSe",
|
|
1119
|
+
"ydSe",
|
|
1120
|
+
"chSe",
|
|
1121
|
+
"chSe(T)",
|
|
1122
|
+
"ftGC",
|
|
1123
|
+
"ydInd",
|
|
1124
|
+
"ft",
|
|
1125
|
+
"m",
|
|
1126
|
+
"usft"
|
|
1127
|
+
],
|
|
1094
1128
|
mixingRequirements: ["m3/t", "L/100kg"],
|
|
1095
1129
|
entalphy: ["J/kg", "kJ/kg", "BTU/lbm"]
|
|
1096
1130
|
});
|
|
@@ -1182,8 +1216,17 @@ const C = Object.freeze({
|
|
|
1182
1216
|
day_to_second: 60 * 60 * 24,
|
|
1183
1217
|
m3_per_m_to_ft3_per_ft: 10.763910416709722,
|
|
1184
1218
|
// https://www.wolframalpha.com/input?i=cubic+meter+per+meter++to+feet+cubic+per+foot&assumption=%7B%22F%22%2C+%22UnitsConversion2%22%2C+%22fromValue%22%7D+-%3E%220.100000000000000000%22
|
|
1185
|
-
in3_per_ft_to_m3_per_m: 537633333333e-16
|
|
1219
|
+
in3_per_ft_to_m3_per_m: 537633333333e-16,
|
|
1186
1220
|
// 1 / m3_per_m_to_ft3_per_ft / ft3_to_in3 = 0.000053763333333333334 https://www.wolframalpha.com/input?i=cubic+meter+per+meter++to+feet+cubic+per+foot&assumption=%7B%22F%22%2C+%22UnitsConversion2%22%2C+%22fromValue%22%7D+-%3E%220.100000000000000000%22
|
|
1221
|
+
/* OW-24122 Flow rate conversion MSm³/d
|
|
1222
|
+
`Mega Standard Cubic Metre per day` (`MSm3/d`) <-> `meters cubed per second` (`m3/s`)
|
|
1223
|
+
1 `MSm3/d`
|
|
1224
|
+
= `1 * 625/54` `m3/s` (https://www.wolframalpha.com/input?i=Mega+Standard+Cubic+Metre+per+day)
|
|
1225
|
+
= `1 / (86400 * 1e-6)` `m3/s` (OW-24122)
|
|
1226
|
+
= `11.5740740741`
|
|
1227
|
+
We can represent this as `625 / 54` or `1_000_000 / 86400`
|
|
1228
|
+
*/
|
|
1229
|
+
MSm3d_to_m3s: 625 / 54
|
|
1187
1230
|
});
|
|
1188
1231
|
const KNOWN_CONVERSIONS = Object.freeze({
|
|
1189
1232
|
// LENGTH
|
|
@@ -1321,8 +1364,8 @@ const KNOWN_CONVERSIONS = Object.freeze({
|
|
|
1321
1364
|
"kg|tonnes": (val) => val / 1e3,
|
|
1322
1365
|
"kg|mt": (val) => val / 1e3,
|
|
1323
1366
|
/*
|
|
1324
|
-
|
|
1325
|
-
|
|
1367
|
+
1 kip = 1000 lbf - https://en.wikipedia.org/wiki/Kip_(unit)
|
|
1368
|
+
*/
|
|
1326
1369
|
"kg|kip": (val) => val * C.kg_to_lbf * 1e-3,
|
|
1327
1370
|
"kgf|kg": (val) => val,
|
|
1328
1371
|
"lbf|kg": (val) => val * C.lbf_to_kg,
|
|
@@ -1390,7 +1433,7 @@ const KNOWN_CONVERSIONS = Object.freeze({
|
|
|
1390
1433
|
"m3/s|MMSCFD": (val) => val / 0.32774128,
|
|
1391
1434
|
"m3/s|STB/d": (val) => val * 1346875e8 / 247854343,
|
|
1392
1435
|
"m3/s|Sm3/d": (val) => val * C.day_to_second,
|
|
1393
|
-
"m3/s|MSm3/d": (val) => val /
|
|
1436
|
+
"m3/s|MSm3/d": (val) => val / C.MSm3d_to_m3s,
|
|
1394
1437
|
"m3/s|SCF/d": (val) => val * 3.0511872047366146e6,
|
|
1395
1438
|
"ft3/s|m3/s": (val) => val * C.ft3_to_m3,
|
|
1396
1439
|
"lpm|m3/s": (val) => val / 6e4,
|
|
@@ -1410,9 +1453,9 @@ const KNOWN_CONVERSIONS = Object.freeze({
|
|
|
1410
1453
|
"Mm3/d|m3/d": (val) => val * 1e6,
|
|
1411
1454
|
"m3/d|Mm3/d": (val) => val * 1e-6,
|
|
1412
1455
|
/*
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1456
|
+
exact formula is 247854343 / 134687500000000 = 0.0000018402178598607888 - https://www.wolframalpha.com/input?i=STB%2Fd
|
|
1457
|
+
STB has a lot of intermediate conversions, so to avoid delta during conversions trip we have to store 2 more digits
|
|
1458
|
+
*/
|
|
1416
1459
|
"STB/d|m3/s": (val) => val * 184021785986e-17,
|
|
1417
1460
|
"Sm3/d|m3/d": (val) => val,
|
|
1418
1461
|
// At a pressure of 101.325 kPa (760 Torr) and DIN 1343: a temperature of 273.15 K (0°C/32°F) | NOTE: Thomas suggested that we leep those conversions 1to1,
|
|
@@ -1421,7 +1464,7 @@ const KNOWN_CONVERSIONS = Object.freeze({
|
|
|
1421
1464
|
"Sm3/d|m3/s": (val) => val / C.day_to_second,
|
|
1422
1465
|
"MSm3/d|Sm3/d": (val) => val * 1e6,
|
|
1423
1466
|
"Sm3/d|MSm3/d": (val) => val * 1e-6,
|
|
1424
|
-
"MSm3/d|m3/s": (val) => val *
|
|
1467
|
+
"MSm3/d|m3/s": (val) => val * C.MSm3d_to_m3s,
|
|
1425
1468
|
"SCF/d|m3/s": (val) => val * 32774128e-14,
|
|
1426
1469
|
// TURBULENT SKIN
|
|
1427
1470
|
"1/m3/d|1/MMSCFD": (val) => val * 28316.85,
|
|
@@ -1878,9 +1921,13 @@ const INTERMEDIATE_CONVERSIONS = Object.freeze({
|
|
|
1878
1921
|
//Entalphy
|
|
1879
1922
|
"BTU/lbm": "J/kg"
|
|
1880
1923
|
});
|
|
1881
|
-
const KNOWN_UNITS = Object.freeze(
|
|
1924
|
+
const KNOWN_UNITS = Object.freeze(
|
|
1925
|
+
Array.from(new Set(Object.values(ALT_UNITS).flat()))
|
|
1926
|
+
);
|
|
1882
1927
|
const SPECIAL_NUMBERS = [NaN, -Infinity, Infinity];
|
|
1883
|
-
const SPECIAL_NUMBERS_STRING = SPECIAL_NUMBERS.map(
|
|
1928
|
+
const SPECIAL_NUMBERS_STRING = SPECIAL_NUMBERS.map(
|
|
1929
|
+
(number) => number.toString()
|
|
1930
|
+
);
|
|
1884
1931
|
const QUANTITIES_DESCRIPTION = {
|
|
1885
1932
|
density: "Density",
|
|
1886
1933
|
length: "Length",
|
|
@@ -2404,7 +2451,9 @@ function unum(numWithUnit, toUnit, fromUnit) {
|
|
|
2404
2451
|
if (m[0] == null) m[0] = "0";
|
|
2405
2452
|
if (m[1]) fromUnit = m[1];
|
|
2406
2453
|
if (!fromUnit && toUnit !== fromUnit) {
|
|
2407
|
-
throw new Error(
|
|
2454
|
+
throw new Error(
|
|
2455
|
+
`unum: unable to figure out unit: ${numWithUnit} fromUnit ${fromUnit}`
|
|
2456
|
+
);
|
|
2408
2457
|
}
|
|
2409
2458
|
if (toUnit === fromUnit) {
|
|
2410
2459
|
const v = m[0] ? toNum(m[0]) : 0;
|
|
@@ -2473,10 +2522,7 @@ function convertTable(toUnitRow, table, defaultUnitRow, removeFinalUnitsRow = fa
|
|
|
2473
2522
|
return newTable;
|
|
2474
2523
|
}
|
|
2475
2524
|
function roundNumberWithLabel(value, n = 2) {
|
|
2476
|
-
return displayNumber(
|
|
2477
|
-
round(value, n),
|
|
2478
|
-
{ withUnit: true }
|
|
2479
|
-
);
|
|
2525
|
+
return displayNumber(round(value, n), { withUnit: true });
|
|
2480
2526
|
}
|
|
2481
2527
|
function withUnit(value, unit, defaultVal = "") {
|
|
2482
2528
|
if (value === null || value === "" || value === void 0) {
|
|
@@ -2524,7 +2570,10 @@ function convertSamePrecision(numWithUnit, toUnit, digits) {
|
|
|
2524
2570
|
let j = prettyNumber.length;
|
|
2525
2571
|
if (prettyNumber[--j] == "0") {
|
|
2526
2572
|
while (prettyNumber[--j] == "0") ;
|
|
2527
|
-
prettyNumber = prettyNumber.slice(
|
|
2573
|
+
prettyNumber = prettyNumber.slice(
|
|
2574
|
+
0,
|
|
2575
|
+
j + (prettyNumber[j] == "." ? 0 : 1)
|
|
2576
|
+
);
|
|
2528
2577
|
}
|
|
2529
2578
|
}
|
|
2530
2579
|
}
|
|
@@ -2536,7 +2585,10 @@ function altUnitsList(value, quantity) {
|
|
|
2536
2585
|
v = withUnit(value, unitFromQuantity(quantity) ?? "");
|
|
2537
2586
|
}
|
|
2538
2587
|
const altUnits = ALT_UNITS[quantity] ?? [];
|
|
2539
|
-
return altUnits.map((unit) => [
|
|
2588
|
+
return altUnits.map((unit) => [
|
|
2589
|
+
...split(convertSamePrecision(v, unit)),
|
|
2590
|
+
label(unit)
|
|
2591
|
+
]);
|
|
2540
2592
|
}
|
|
2541
2593
|
function validateAndClean(previousValue, nextText) {
|
|
2542
2594
|
const unit = split(previousValue)[1];
|
|
@@ -2547,7 +2599,10 @@ function validateAndClean(previousValue, nextText) {
|
|
|
2547
2599
|
const stripDot = /^([^.]*\.)|\./g;
|
|
2548
2600
|
const stripDotFollowedByE = /\.(?=e)/g;
|
|
2549
2601
|
const stripMinus = /-|[eE]-/g;
|
|
2550
|
-
const cleanedValue = nextText.replace(stripAllExceptNumeric, "").replace(stripE, "$1").replace(stripInvalidLeading, "").replace(replaceComma, ".").replace(stripDot, "$1").replace(stripDotFollowedByE, "").replace(
|
|
2602
|
+
const cleanedValue = nextText.replace(stripAllExceptNumeric, "").replace(stripE, "$1").replace(stripInvalidLeading, "").replace(replaceComma, ".").replace(stripDot, "$1").replace(stripDotFollowedByE, "").replace(
|
|
2603
|
+
stripMinus,
|
|
2604
|
+
(match, offset) => offset === 0 || match.toLowerCase() === "e-" ? match : ""
|
|
2605
|
+
);
|
|
2551
2606
|
return !Number.isFinite(+cleanedValue) ? previousValue : `${cleanedValue}${unit ? "|" : ""}${unit}`;
|
|
2552
2607
|
}
|
|
2553
2608
|
function withPrettyUnitLabel(valueWithUnits) {
|
package/dist/units.cjs
CHANGED
package/dist/units.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { ae as EXP_NOTATION_RE, ad as SEPARATOR, i as altUnitsList, c as checkAndCleanDecimalComma, q as convertAndGetValue, x as convertAndGetValueStrict, p as convertSamePrecision, j as convertTable, g as getAltUnitsListByQuantity, b as getQuantities, o as getUnit, a as getUnitsForQuantity, n as getValue, m as isValueWithUnit, l as label, r as roundNumberWithLabel, s as showAltUnitsList, e as split, t as to, h as toBase, u as unitFromKey, d as unitFromQuantity, f as unum, k as unumWithUnit, v as validateAndClean, z as validateNumber, y as withPrettyUnitLabel, w as withUnit } from './units-
|
|
1
|
+
export { ae as EXP_NOTATION_RE, ad as SEPARATOR, i as altUnitsList, c as checkAndCleanDecimalComma, q as convertAndGetValue, x as convertAndGetValueStrict, p as convertSamePrecision, j as convertTable, g as getAltUnitsListByQuantity, b as getQuantities, o as getUnit, a as getUnitsForQuantity, n as getValue, m as isValueWithUnit, l as label, r as roundNumberWithLabel, s as showAltUnitsList, e as split, t as to, h as toBase, u as unitFromKey, d as unitFromQuantity, f as unum, k as unumWithUnit, v as validateAndClean, z as validateNumber, y as withPrettyUnitLabel, w as withUnit } from './units-COuQAjLd.js';
|
|
2
2
|
import 'fraction.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oliasoft-open-source/units",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.3-beta-1",
|
|
4
4
|
"description": "Package for units management",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,9 +35,12 @@
|
|
|
35
35
|
"scripts": {
|
|
36
36
|
"compile-validators:build": "esbuild dist/validate/ajv-validators.js --bundle --allow-overwrite --platform=node --format=cjs --outfile=dist/validate/ajv-validators.js",
|
|
37
37
|
"build": "pkgroll --clean-dist --tsconfig=tsconfig.build.json && cp README.md dist/",
|
|
38
|
-
"lint": "
|
|
38
|
+
"lint:check": "oxlint .",
|
|
39
|
+
"lint:fix": "oxlint --fix .",
|
|
40
|
+
"formatting:check": "prettier --check '*/**/*.{ts,js,json}'",
|
|
41
|
+
"formatting:fix": "prettier --write '*/**/*.{ts,js,json}'",
|
|
39
42
|
"start": "yarn link && yarn compile-validators && tsx watch src/index.ts",
|
|
40
|
-
"test": "yarn compile-validators && jest --coverageThreshold \"{}\"",
|
|
43
|
+
"test": "yarn formatting:check && yarn lint:check && yarn compile-validators && jest --coverageThreshold \"{}\"",
|
|
41
44
|
"test:watch": "jest --watchAll",
|
|
42
45
|
"watch": "tsc -w -p tsconfig.dev.json",
|
|
43
46
|
"validate-release-notes": "tsx scripts/validate-release-notes.ts",
|
|
@@ -46,33 +49,28 @@
|
|
|
46
49
|
"prepare": "husky"
|
|
47
50
|
},
|
|
48
51
|
"lint-staged": {
|
|
49
|
-
"
|
|
52
|
+
"*/**/*.{ts,js,json}": [
|
|
53
|
+
"oxlint --fix",
|
|
54
|
+
"prettier --write"
|
|
55
|
+
]
|
|
50
56
|
},
|
|
51
57
|
"dependencies": {
|
|
52
58
|
"fraction.js": "^5.2.1"
|
|
53
59
|
},
|
|
54
60
|
"devDependencies": {
|
|
55
|
-
"@
|
|
56
|
-
"@commitlint/config-conventional": "^19.7.1",
|
|
57
|
-
"@oliasoft-open-source/eslint-config-oliasoft": "^1.2.4",
|
|
61
|
+
"@prettier/plugin-oxc": "^0.1.3",
|
|
58
62
|
"@types/jest": "^29.5.14",
|
|
59
63
|
"@types/node": "^22.13.4",
|
|
60
|
-
"@typescript-eslint/eslint-plugin": "^8.24.1",
|
|
61
|
-
"@typescript-eslint/parser": "^8.24.1",
|
|
62
64
|
"ajv": "^8.17.1",
|
|
63
65
|
"ajv-errors": "^3.0.0",
|
|
64
66
|
"ajv-keywords": "^5.1.0",
|
|
65
67
|
"esbuild": "^0.25.0",
|
|
66
|
-
"eslint": "^9.20.1",
|
|
67
|
-
"eslint-config-prettier": "^10.0.1",
|
|
68
|
-
"eslint-import-resolver-typescript": "^3.8.2",
|
|
69
|
-
"eslint-plugin-import": "^2.31.0",
|
|
70
|
-
"eslint-plugin-prettier": "^5.2.3",
|
|
71
68
|
"husky": "^9.1.7",
|
|
72
69
|
"jest": "^29.7.0",
|
|
73
70
|
"lint-staged": "^15.4.3",
|
|
71
|
+
"oxlint": "^1.39.0",
|
|
74
72
|
"pkgroll": "^2.10.0",
|
|
75
|
-
"prettier": "^3.
|
|
73
|
+
"prettier": "^3.7.4",
|
|
76
74
|
"ts-jest": "^29.2.5",
|
|
77
75
|
"tsx": "^4.19.3",
|
|
78
76
|
"typescript": "^5.7.3"
|