@oliasoft-open-source/units 4.4.3 → 4.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +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-OcXa9PZa.cjs → units-B3a2-Mk6.cjs} +26 -1
- package/dist/{units-BOzU7M3c.js → units-CNKurcic.js} +26 -1
- package/dist/units.cjs +1 -1
- package/dist/units.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
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-CNKurcic.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-CNKurcic.js';
|
|
2
2
|
import 'fraction.js';
|
|
@@ -710,6 +710,29 @@ function get_k_from_conf_int(a) {
|
|
|
710
710
|
function get_conf_int_from_k(k) {
|
|
711
711
|
return erf(k / sqrt(2));
|
|
712
712
|
}
|
|
713
|
+
const normalizeExponent = (input) => {
|
|
714
|
+
return input.replace(
|
|
715
|
+
/^([+-]?(?:\d+\.?\d*|\.\d+))[ ]*[eE][ ]*([+-]?[ ]*\d+)/,
|
|
716
|
+
(_m, mantissa, exp2) => {
|
|
717
|
+
let m = mantissa.endsWith(".") ? mantissa.slice(0, -1) : mantissa;
|
|
718
|
+
if (m.startsWith(".")) m = "0" + m;
|
|
719
|
+
const e = exp2.replace(/[ ]+/g, "");
|
|
720
|
+
return `${m}e${e}`;
|
|
721
|
+
}
|
|
722
|
+
);
|
|
723
|
+
};
|
|
724
|
+
function normalizeScientific(val) {
|
|
725
|
+
if (typeof val !== "string") return val;
|
|
726
|
+
let s = val.replace(/\u00A0|\u2007|\u202F/g, " ").trim();
|
|
727
|
+
if (isValueWithUnit(s)) {
|
|
728
|
+
const [val2, unit] = split(s);
|
|
729
|
+
const fixedLeft = normalizeExponent(val2.trim());
|
|
730
|
+
return `${fixedLeft}|${unit.trim()}`;
|
|
731
|
+
}
|
|
732
|
+
const m = s.match(/^([+-]?(?:\d+(?:\.\d*)?|\.\d+)\s*[eE]\s*[+-]?\s*\d+)\s+(.+)$/);
|
|
733
|
+
if (m) return `${normalizeExponent(m[1])}|${m[2].trim()}`;
|
|
734
|
+
return normalizeExponent(s);
|
|
735
|
+
}
|
|
713
736
|
|
|
714
737
|
const LABELS = Object.freeze({
|
|
715
738
|
in: "in",
|
|
@@ -2267,6 +2290,7 @@ function checkAndCleanDecimalComma(val) {
|
|
|
2267
2290
|
}
|
|
2268
2291
|
function to(value, fromUnit, toUnit) {
|
|
2269
2292
|
value = checkAndCleanDecimalComma(value);
|
|
2293
|
+
value = normalizeScientific(value);
|
|
2270
2294
|
if (toUnit === "undefined") {
|
|
2271
2295
|
console.warn('Inconsistent "to unit" - debug call to "Units.to()"');
|
|
2272
2296
|
}
|
|
@@ -2358,7 +2382,8 @@ function unum(numWithUnit, toUnit, fromUnit) {
|
|
|
2358
2382
|
if (typeof numWithUnit === "string" && numWithUnit.startsWith("NaN") || typeof numWithUnit === "number" && isNaN(numWithUnit)) {
|
|
2359
2383
|
return NaN;
|
|
2360
2384
|
}
|
|
2361
|
-
const
|
|
2385
|
+
const normInput = normalizeScientific(numWithUnit);
|
|
2386
|
+
const cleanStr = cleanNumStr(normInput).replaceAll("+", "");
|
|
2362
2387
|
const m = split(cleanStr);
|
|
2363
2388
|
if (!m) {
|
|
2364
2389
|
if (toUnit && fromUnit) return unum(numWithUnit + fromUnit, toUnit);
|
|
@@ -708,6 +708,29 @@ function get_k_from_conf_int(a) {
|
|
|
708
708
|
function get_conf_int_from_k(k) {
|
|
709
709
|
return erf(k / sqrt(2));
|
|
710
710
|
}
|
|
711
|
+
const normalizeExponent = (input) => {
|
|
712
|
+
return input.replace(
|
|
713
|
+
/^([+-]?(?:\d+\.?\d*|\.\d+))[ ]*[eE][ ]*([+-]?[ ]*\d+)/,
|
|
714
|
+
(_m, mantissa, exp2) => {
|
|
715
|
+
let m = mantissa.endsWith(".") ? mantissa.slice(0, -1) : mantissa;
|
|
716
|
+
if (m.startsWith(".")) m = "0" + m;
|
|
717
|
+
const e = exp2.replace(/[ ]+/g, "");
|
|
718
|
+
return `${m}e${e}`;
|
|
719
|
+
}
|
|
720
|
+
);
|
|
721
|
+
};
|
|
722
|
+
function normalizeScientific(val) {
|
|
723
|
+
if (typeof val !== "string") return val;
|
|
724
|
+
let s = val.replace(/\u00A0|\u2007|\u202F/g, " ").trim();
|
|
725
|
+
if (isValueWithUnit(s)) {
|
|
726
|
+
const [val2, unit] = split(s);
|
|
727
|
+
const fixedLeft = normalizeExponent(val2.trim());
|
|
728
|
+
return `${fixedLeft}|${unit.trim()}`;
|
|
729
|
+
}
|
|
730
|
+
const m = s.match(/^([+-]?(?:\d+(?:\.\d*)?|\.\d+)\s*[eE]\s*[+-]?\s*\d+)\s+(.+)$/);
|
|
731
|
+
if (m) return `${normalizeExponent(m[1])}|${m[2].trim()}`;
|
|
732
|
+
return normalizeExponent(s);
|
|
733
|
+
}
|
|
711
734
|
|
|
712
735
|
const LABELS = Object.freeze({
|
|
713
736
|
in: "in",
|
|
@@ -2265,6 +2288,7 @@ function checkAndCleanDecimalComma(val) {
|
|
|
2265
2288
|
}
|
|
2266
2289
|
function to(value, fromUnit, toUnit) {
|
|
2267
2290
|
value = checkAndCleanDecimalComma(value);
|
|
2291
|
+
value = normalizeScientific(value);
|
|
2268
2292
|
if (toUnit === "undefined") {
|
|
2269
2293
|
console.warn('Inconsistent "to unit" - debug call to "Units.to()"');
|
|
2270
2294
|
}
|
|
@@ -2356,7 +2380,8 @@ function unum(numWithUnit, toUnit, fromUnit) {
|
|
|
2356
2380
|
if (typeof numWithUnit === "string" && numWithUnit.startsWith("NaN") || typeof numWithUnit === "number" && isNaN(numWithUnit)) {
|
|
2357
2381
|
return NaN;
|
|
2358
2382
|
}
|
|
2359
|
-
const
|
|
2383
|
+
const normInput = normalizeScientific(numWithUnit);
|
|
2384
|
+
const cleanStr = cleanNumStr(normInput).replaceAll("+", "");
|
|
2360
2385
|
const m = split(cleanStr);
|
|
2361
2386
|
if (!m) {
|
|
2362
2387
|
if (toUnit && fromUnit) return unum(numWithUnit + fromUnit, toUnit);
|
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-CNKurcic.js';
|
|
2
2
|
import 'fraction.js';
|