@oliasoft-open-source/units 5.6.0-beta-1 → 5.6.0-beta-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -49,11 +49,13 @@ const roundCosmetic = (value) => {
|
|
|
49
49
|
//#endregion
|
|
50
50
|
exports.ALT_UNITS = require_conversion.ALT_UNITS;
|
|
51
51
|
exports.DEPRECATED_UNITS = require_conversion.DEPRECATED_UNITS;
|
|
52
|
+
exports.EXP_NOTATION_RE = require_conversion.EXP_NOTATION_RE;
|
|
52
53
|
exports.INTERMEDIATE_CONVERSIONS = require_conversion.INTERMEDIATE_CONVERSIONS;
|
|
53
54
|
exports.KNOWN_CONVERSIONS = require_conversion.KNOWN_CONVERSIONS;
|
|
54
55
|
exports.KNOWN_UNITS = require_conversion.KNOWN_UNITS;
|
|
55
56
|
exports.LABELS = require_conversion.LABELS;
|
|
56
57
|
exports.QUANTITIES_DESCRIPTION = require_conversion.QUANTITIES_DESCRIPTION;
|
|
58
|
+
exports.SEPARATOR = require_conversion.SEPARATOR;
|
|
57
59
|
exports.UNITS_DESCRIPTION = require_conversion.UNITS_DESCRIPTION;
|
|
58
60
|
exports.UNIT_ALIASES = require_conversion.UNIT_ALIASES;
|
|
59
61
|
exports.UNIT_FROM_KEY = require_conversion.UNIT_FROM_KEY;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["isScientificStringNum","roundToPrecision"],"sources":["../src/numbers/rounding/number-digits.ts","../src/numbers/rounding/cosmetic-rounding.ts","../src/index.ts"],"sourcesContent":["/**\n * Calculates a useful decimal precision for small values used by legacy rounding.\n *\n * @deprecated Use `roundByMagnitude` or another current rounding function instead.\n */\nexport function getNumberOfDigitsToShow(value: number | string, maxNumberOfDigits = 20): number {\n const defaultDigits = Math.min(4, maxNumberOfDigits);\n let digits = defaultDigits;\n if (typeof value !== 'number') {\n return defaultDigits;\n }\n\n const valueString = String(value);\n const exponentialNumber = /-?[0-9.,]*[Ee]-?[0-9]+/;\n if (exponentialNumber.test(valueString)) {\n while (Math.abs(value) * 10 ** digits < 1 && digits < maxNumberOfDigits) {\n digits += 1;\n }\n return Math.min(digits + (defaultDigits - 1), maxNumberOfDigits);\n }\n\n if (value > 1 || value < -1) {\n return defaultDigits;\n }\n\n for (let index = 2; index < valueString.length; index += 1) {\n if (valueString[index] !== '0') {\n return Math.min(maxNumberOfDigits, digits + index - 2);\n }\n }\n return digits;\n}\n","import { isScientificStringNum } from '../numbers.ts';\nimport { roundToPrecision } from './rounding.ts';\n\nconst COSMETIC_ROUNDING_DEFAULT_PRECISION = 14;\n\n/**\n * Applies display-only rounding to remove floating-point conversion noise.\n *\n * The value is rounded to 14 significant digits, while strings written in\n * scientific notation are preserved as entered.\n *\n * - accepts number types, stringified numbers, and unit strings\n * - returns the same type as the input\n *\n * @param value - numeric value to cosmetically round\n * @returns the cosmetically rounded value\n *\n * @example\n * roundCosmetic('9750.000000000004') -> '9750'\n * roundCosmetic('9750.000000000004|m') -> '9750|m'\n */\nexport const roundCosmetic = <Value extends number | string>(value: Value): Value => {\n if (isScientificStringNum(value)) {\n return value;\n }\n\n return roundToPrecision(value, COSMETIC_ROUNDING_DEFAULT_PRECISION);\n};\n","/* istanbul ignore file */\nimport {\n label,\n showAltUnitsList,\n getAltUnitsListByQuantity,\n checkAndCleanDecimalComma,\n unitFromKey,\n to,\n split,\n unum,\n toBase,\n altUnitsList,\n convertTable,\n roundNumberWithLabel,\n withUnit,\n unumWithUnit,\n validateAndClean,\n isValueWithUnit,\n getValue,\n getUnit,\n convertSamePrecision,\n convertAndGetValue,\n convertAndGetValueStrict,\n getUnitsForQuantity,\n getQuantities,\n unitFromQuantity,\n withPrettyUnitLabel,\n validateNumber,\n} from './units.ts';\nimport { isEmptyValueWithUnit } from './units/unit-string.ts';\n\nimport {\n ALT_UNITS,\n LABELS,\n UNIT_FROM_KEY,\n KNOWN_CONVERSIONS,\n DEPRECATED_UNITS,\n UNIT_ALIASES,\n INTERMEDIATE_CONVERSIONS,\n KNOWN_UNITS,\n QUANTITIES_DESCRIPTION,\n UNITS_DESCRIPTION,\n} from './units/constants.ts';\n\nimport { asFraction, fraction, isFraction, numFraction } from './numbers/fractions/fractions.ts';\nimport { charCount, cleanNum, cleanNumStr, stripLeadingZeros } from './numbers/parsing/number-input.ts';\nimport { allNumbers, isNonNumerical, isNumeric } from './numbers/predicates.ts';\nimport { getNumberOfDigitsToShow } from './numbers/rounding/number-digits.ts';\n\nimport { toNum, toString, isValidNum, isScientificStringNum } from './numbers/numbers.ts';\n\nimport { displayNumber, displayNumberToFixed, formatNumber } from './numbers/format/display-number.ts';\n\nimport {\n round,\n roundToFixed,\n roundToPrecision,\n roundToDecimalPrecision,\n roundByMagnitude,\n roundByMagnitudeToFixed,\n roundByRange,\n} from './numbers/rounding/rounding.ts';\n\nimport { roundCosmetic } from './numbers/rounding/cosmetic-rounding.ts';\n\nimport {\n isCloseTo,\n isCloseToOrGreaterThan,\n isCloseToOrLessThan,\n isDeepCloseTo,\n} from './numbers/comparison/comparison.ts';\n\nexport {\n // Units\n label,\n showAltUnitsList,\n getAltUnitsListByQuantity,\n getUnitsForQuantity,\n getQuantities,\n checkAndCleanDecimalComma,\n unitFromKey,\n unitFromQuantity,\n to,\n split,\n unum,\n toBase,\n altUnitsList,\n convertTable,\n roundNumberWithLabel,\n withUnit,\n unumWithUnit,\n validateAndClean,\n isValueWithUnit,\n getValue,\n getUnit,\n convertSamePrecision,\n convertAndGetValue,\n convertAndGetValueStrict,\n withPrettyUnitLabel,\n validateNumber,\n //Rounding\n round,\n roundToFixed,\n roundToPrecision,\n roundToDecimalPrecision,\n roundByMagnitude,\n roundByMagnitudeToFixed,\n roundByRange,\n roundCosmetic,\n //Comparison\n isCloseTo,\n isDeepCloseTo,\n isCloseToOrLessThan,\n isCloseToOrGreaterThan,\n // Utils\n isNumeric,\n isNonNumerical,\n isEmptyValueWithUnit,\n allNumbers,\n formatNumber,\n displayNumber,\n displayNumberToFixed,\n charCount,\n getNumberOfDigitsToShow,\n fraction,\n isFraction,\n asFraction,\n numFraction,\n cleanNumStr,\n cleanNum,\n toNum,\n toString,\n isValidNum,\n isScientificStringNum,\n stripLeadingZeros,\n // Constants\n ALT_UNITS,\n LABELS,\n UNIT_FROM_KEY,\n KNOWN_CONVERSIONS,\n DEPRECATED_UNITS,\n UNIT_ALIASES,\n INTERMEDIATE_CONVERSIONS,\n KNOWN_UNITS,\n QUANTITIES_DESCRIPTION,\n UNITS_DESCRIPTION,\n};\n"],"mappings":";;;;;;;;;AAKA,SAAgB,wBAAwB,OAAwB,oBAAoB,IAAY;CAC9F,MAAM,gBAAgB,KAAK,IAAI,GAAG,kBAAkB;CACpD,IAAI,SAAS;AACb,KAAI,OAAO,UAAU,SACnB,QAAO;CAGT,MAAM,cAAc,OAAO,MAAM;AAEjC,KAD0B,yBACJ,KAAK,YAAY,EAAE;AACvC,SAAO,KAAK,IAAI,MAAM,GAAG,MAAM,SAAS,KAAK,SAAS,kBACpD,WAAU;AAEZ,SAAO,KAAK,IAAI,UAAU,gBAAgB,IAAI,kBAAkB;;AAGlE,KAAI,QAAQ,KAAK,QAAQ,GACvB,QAAO;AAGT,MAAK,IAAI,QAAQ,GAAG,QAAQ,YAAY,QAAQ,SAAS,EACvD,KAAI,YAAY,WAAW,IACzB,QAAO,KAAK,IAAI,mBAAmB,SAAS,QAAQ,EAAE;AAG1D,QAAO;;;;AC3BT,MAAM,sCAAsC;;;;;;;;;;;;;;;;;AAkB5C,MAAa,iBAAgD,UAAwB;AACnF,KAAIA,mBAAAA,sBAAsB,MAAM,CAC9B,QAAO;AAGT,QAAOC,mBAAAA,iBAAiB,OAAO,oCAAoC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["isScientificStringNum","roundToPrecision"],"sources":["../src/numbers/rounding/number-digits.ts","../src/numbers/rounding/cosmetic-rounding.ts","../src/index.ts"],"sourcesContent":["/**\n * Calculates a useful decimal precision for small values used by legacy rounding.\n *\n * @deprecated Use `roundByMagnitude` or another current rounding function instead.\n */\nexport function getNumberOfDigitsToShow(value: number | string, maxNumberOfDigits = 20): number {\n const defaultDigits = Math.min(4, maxNumberOfDigits);\n let digits = defaultDigits;\n if (typeof value !== 'number') {\n return defaultDigits;\n }\n\n const valueString = String(value);\n const exponentialNumber = /-?[0-9.,]*[Ee]-?[0-9]+/;\n if (exponentialNumber.test(valueString)) {\n while (Math.abs(value) * 10 ** digits < 1 && digits < maxNumberOfDigits) {\n digits += 1;\n }\n return Math.min(digits + (defaultDigits - 1), maxNumberOfDigits);\n }\n\n if (value > 1 || value < -1) {\n return defaultDigits;\n }\n\n for (let index = 2; index < valueString.length; index += 1) {\n if (valueString[index] !== '0') {\n return Math.min(maxNumberOfDigits, digits + index - 2);\n }\n }\n return digits;\n}\n","import { isScientificStringNum } from '../numbers.ts';\nimport { roundToPrecision } from './rounding.ts';\n\nconst COSMETIC_ROUNDING_DEFAULT_PRECISION = 14;\n\n/**\n * Applies display-only rounding to remove floating-point conversion noise.\n *\n * The value is rounded to 14 significant digits, while strings written in\n * scientific notation are preserved as entered.\n *\n * - accepts number types, stringified numbers, and unit strings\n * - returns the same type as the input\n *\n * @param value - numeric value to cosmetically round\n * @returns the cosmetically rounded value\n *\n * @example\n * roundCosmetic('9750.000000000004') -> '9750'\n * roundCosmetic('9750.000000000004|m') -> '9750|m'\n */\nexport const roundCosmetic = <Value extends number | string>(value: Value): Value => {\n if (isScientificStringNum(value)) {\n return value;\n }\n\n return roundToPrecision(value, COSMETIC_ROUNDING_DEFAULT_PRECISION);\n};\n","/* istanbul ignore file */\nimport {\n label,\n showAltUnitsList,\n getAltUnitsListByQuantity,\n checkAndCleanDecimalComma,\n unitFromKey,\n to,\n split,\n unum,\n toBase,\n altUnitsList,\n convertTable,\n roundNumberWithLabel,\n withUnit,\n unumWithUnit,\n validateAndClean,\n isValueWithUnit,\n getValue,\n getUnit,\n convertSamePrecision,\n convertAndGetValue,\n convertAndGetValueStrict,\n getUnitsForQuantity,\n getQuantities,\n unitFromQuantity,\n withPrettyUnitLabel,\n validateNumber,\n} from './units.ts';\nimport { isEmptyValueWithUnit } from './units/unit-string.ts';\n\nimport {\n ALT_UNITS,\n LABELS,\n UNIT_FROM_KEY,\n KNOWN_CONVERSIONS,\n DEPRECATED_UNITS,\n UNIT_ALIASES,\n INTERMEDIATE_CONVERSIONS,\n KNOWN_UNITS,\n QUANTITIES_DESCRIPTION,\n UNITS_DESCRIPTION,\n} from './units/constants.ts';\n\nimport { asFraction, fraction, isFraction, numFraction } from './numbers/fractions/fractions.ts';\nimport { charCount, cleanNum, cleanNumStr, stripLeadingZeros } from './numbers/parsing/number-input.ts';\nimport { allNumbers, isNonNumerical, isNumeric } from './numbers/predicates.ts';\nimport { getNumberOfDigitsToShow } from './numbers/rounding/number-digits.ts';\n\nimport { toNum, toString, isValidNum, isScientificStringNum } from './numbers/numbers.ts';\n\nimport { displayNumber, displayNumberToFixed, formatNumber } from './numbers/format/display-number.ts';\n\nimport {\n round,\n roundToFixed,\n roundToPrecision,\n roundToDecimalPrecision,\n roundByMagnitude,\n roundByMagnitudeToFixed,\n roundByRange,\n} from './numbers/rounding/rounding.ts';\n\nimport { roundCosmetic } from './numbers/rounding/cosmetic-rounding.ts';\n\nimport {\n isCloseTo,\n isCloseToOrGreaterThan,\n isCloseToOrLessThan,\n isDeepCloseTo,\n} from './numbers/comparison/comparison.ts';\n\nexport {\n // Units\n label,\n showAltUnitsList,\n getAltUnitsListByQuantity,\n getUnitsForQuantity,\n getQuantities,\n checkAndCleanDecimalComma,\n unitFromKey,\n unitFromQuantity,\n to,\n split,\n unum,\n toBase,\n altUnitsList,\n convertTable,\n roundNumberWithLabel,\n withUnit,\n unumWithUnit,\n validateAndClean,\n isValueWithUnit,\n getValue,\n getUnit,\n convertSamePrecision,\n convertAndGetValue,\n convertAndGetValueStrict,\n withPrettyUnitLabel,\n validateNumber,\n //Rounding\n round,\n roundToFixed,\n roundToPrecision,\n roundToDecimalPrecision,\n roundByMagnitude,\n roundByMagnitudeToFixed,\n roundByRange,\n roundCosmetic,\n //Comparison\n isCloseTo,\n isDeepCloseTo,\n isCloseToOrLessThan,\n isCloseToOrGreaterThan,\n // Utils\n isNumeric,\n isNonNumerical,\n isEmptyValueWithUnit,\n allNumbers,\n formatNumber,\n displayNumber,\n displayNumberToFixed,\n charCount,\n getNumberOfDigitsToShow,\n fraction,\n isFraction,\n asFraction,\n numFraction,\n cleanNumStr,\n cleanNum,\n toNum,\n toString,\n isValidNum,\n isScientificStringNum,\n stripLeadingZeros,\n // Constants\n ALT_UNITS,\n LABELS,\n UNIT_FROM_KEY,\n KNOWN_CONVERSIONS,\n DEPRECATED_UNITS,\n UNIT_ALIASES,\n INTERMEDIATE_CONVERSIONS,\n KNOWN_UNITS,\n QUANTITIES_DESCRIPTION,\n UNITS_DESCRIPTION,\n};\n\nexport { EXP_NOTATION_RE } from './numbers/scientific-notation/scientific-notation.ts';\nexport { SEPARATOR } from './units/unit-string.ts';\nexport type { AltUnitWithLabel, LocaleFormat, ValidateReturn } from './units/types.ts';\n"],"mappings":";;;;;;;;;AAKA,SAAgB,wBAAwB,OAAwB,oBAAoB,IAAY;CAC9F,MAAM,gBAAgB,KAAK,IAAI,GAAG,kBAAkB;CACpD,IAAI,SAAS;AACb,KAAI,OAAO,UAAU,SACnB,QAAO;CAGT,MAAM,cAAc,OAAO,MAAM;AAEjC,KAD0B,yBACJ,KAAK,YAAY,EAAE;AACvC,SAAO,KAAK,IAAI,MAAM,GAAG,MAAM,SAAS,KAAK,SAAS,kBACpD,WAAU;AAEZ,SAAO,KAAK,IAAI,UAAU,gBAAgB,IAAI,kBAAkB;;AAGlE,KAAI,QAAQ,KAAK,QAAQ,GACvB,QAAO;AAGT,MAAK,IAAI,QAAQ,GAAG,QAAQ,YAAY,QAAQ,SAAS,EACvD,KAAI,YAAY,WAAW,IACzB,QAAO,KAAK,IAAI,mBAAmB,SAAS,QAAQ,EAAE;AAG1D,QAAO;;;;AC3BT,MAAM,sCAAsC;;;;;;;;;;;;;;;;;AAkB5C,MAAa,iBAAgD,UAAwB;AACnF,KAAIA,mBAAAA,sBAAsB,MAAM,CAC9B,QAAO;AAGT,QAAOC,mBAAAA,iBAAiB,OAAO,oCAAoC"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as LocaleFormat, r as ValidateReturn, t as AltUnitWithLabel } from "./chunks/types.cjs";
|
|
2
|
+
import { C as getAltUnitsListByQuantity, D as showAltUnitsList, E as label, O as unitFromKey, S as withUnit, T as getUnitsForQuantity, _ as getValue, a as altUnitsList, b as split, c as convertAndGetValue, d as to, f as toBase, g as getUnit, h as SEPARATOR, i as validateNumber, k as unitFromQuantity, l as convertAndGetValueStrict, m as unumWithUnit, n as checkAndCleanDecimalComma, o as roundNumberWithLabel, p as unum, r as validateAndClean, s as convertTable, t as EXP_NOTATION_RE, u as convertSamePrecision, v as isEmptyValueWithUnit, w as getQuantities, x as withPrettyUnitLabel, y as isValueWithUnit } from "./chunks/units.cjs";
|
|
2
3
|
import { isScientificStringNum, isValidNum, toNum, toString } from "./numbers/numbers.cjs";
|
|
3
4
|
|
|
4
5
|
//#region src/units/constants.d.ts
|
|
@@ -377,5 +378,5 @@ declare const isCloseToOrGreaterThan: (firstValue: number | string | null, secon
|
|
|
377
378
|
declare const isCloseToOrLessThan: (firstValue: number | string | null, secondValue: number | string | null, options?: toleranceType) => boolean;
|
|
378
379
|
declare const isDeepCloseTo: (a: any, b: any, options?: toleranceType) => boolean;
|
|
379
380
|
//#endregion
|
|
380
|
-
export { ALT_UNITS, DEPRECATED_UNITS, INTERMEDIATE_CONVERSIONS, KNOWN_CONVERSIONS, KNOWN_UNITS, LABELS, QUANTITIES_DESCRIPTION, UNITS_DESCRIPTION, UNIT_ALIASES, UNIT_FROM_KEY, allNumbers, altUnitsList, asFraction, charCount, checkAndCleanDecimalComma, cleanNum, cleanNumStr, convertAndGetValue, convertAndGetValueStrict, convertSamePrecision, convertTable, displayNumber, displayNumberToFixed, formatNumber, fraction, getAltUnitsListByQuantity, getNumberOfDigitsToShow, getQuantities, getUnit, getUnitsForQuantity, getValue, isCloseTo, isCloseToOrGreaterThan, isCloseToOrLessThan, isDeepCloseTo, isEmptyValueWithUnit, isFraction, isNonNumerical, isNumeric, isScientificStringNum, isValidNum, isValueWithUnit, label, numFraction, round, roundByMagnitude, roundByMagnitudeToFixed, roundByRange, roundCosmetic, roundNumberWithLabel, roundToDecimalPrecision, roundToFixed, roundToPrecision, showAltUnitsList, split, stripLeadingZeros, to, toBase, toNum, toString, unitFromKey, unitFromQuantity, unum, unumWithUnit, validateAndClean, validateNumber, withPrettyUnitLabel, withUnit };
|
|
381
|
+
export { ALT_UNITS, type AltUnitWithLabel, DEPRECATED_UNITS, EXP_NOTATION_RE, INTERMEDIATE_CONVERSIONS, KNOWN_CONVERSIONS, KNOWN_UNITS, LABELS, type LocaleFormat, QUANTITIES_DESCRIPTION, SEPARATOR, UNITS_DESCRIPTION, UNIT_ALIASES, UNIT_FROM_KEY, type ValidateReturn, allNumbers, altUnitsList, asFraction, charCount, checkAndCleanDecimalComma, cleanNum, cleanNumStr, convertAndGetValue, convertAndGetValueStrict, convertSamePrecision, convertTable, displayNumber, displayNumberToFixed, formatNumber, fraction, getAltUnitsListByQuantity, getNumberOfDigitsToShow, getQuantities, getUnit, getUnitsForQuantity, getValue, isCloseTo, isCloseToOrGreaterThan, isCloseToOrLessThan, isDeepCloseTo, isEmptyValueWithUnit, isFraction, isNonNumerical, isNumeric, isScientificStringNum, isValidNum, isValueWithUnit, label, numFraction, round, roundByMagnitude, roundByMagnitudeToFixed, roundByRange, roundCosmetic, roundNumberWithLabel, roundToDecimalPrecision, roundToFixed, roundToPrecision, showAltUnitsList, split, stripLeadingZeros, to, toBase, toNum, toString, unitFromKey, unitFromQuantity, unum, unumWithUnit, validateAndClean, validateNumber, withPrettyUnitLabel, withUnit };
|
|
381
382
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/units/constants.ts","../src/numbers/fractions/fractions.ts","../src/numbers/parsing/number-input.ts","../src/numbers/predicates.ts","../src/numbers/rounding/number-digits.ts","../src/numbers/format/display-number.ts","../src/numbers/rounding/rounding.ts","../src/numbers/rounding/cosmetic-rounding.ts","../src/numbers/comparison/comparison.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/units/constants.ts","../src/numbers/fractions/fractions.ts","../src/numbers/parsing/number-input.ts","../src/numbers/predicates.ts","../src/numbers/rounding/number-digits.ts","../src/numbers/format/display-number.ts","../src/numbers/rounding/rounding.ts","../src/numbers/rounding/cosmetic-rounding.ts","../src/numbers/comparison/comparison.ts"],"mappings":";;;;;cAQa,MAAA,EAAQ,MAAA;AAAA,cAgOR,SAAA,EAAW,MAAA;AAAA,cAgIX,aAAA,EAAe,MAAA;AAAA,cA8Gf,iBAAA,EAAmB,MAAA,UAAgB,GAAA;AAAA,cA0fnC,gBAAA,EAAkB,MAAA;AAAA,cAclB,YAAA,EAAc,MAAA;AAAA,cAYd,wBAAA,EAA0B,MAAA;AAAA,cA0K1B,WAAA;AAAA,cASA,sBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8FA,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAA,cACC,KAAA;AAAA,cAuDU,YAAA,qDACX,KAAA,EAAO,KAAA,EACP,GAAA,UACA,GAAA,UACA,CAAA,cACC,KAAA;AAAA,cAgCU,YAAA,qDACX,KAAA,EAAO,KAAA,EACP,CAAA,cACC,KAAA;;;cCtVU,aAAA,kCAAgD,KAAA,EAAO,KAAA,KAAQ,KAAA;;;KCbvE,OAAA,iBAAwB,OAAA,OAAc,CAAA,QAAS,CAAA;AAAA,KAC/C,GAAA,SAAY,CAAA,GAAI,CAAA,SAAU,MAAA,qBAA2B,OAAA,CAAQ,CAAA,EAAG,CAAA,IAAK,CAAA,KAAM,OAAA,CAAQ,CAAA,EAAG,CAAA,IAAK,CAAA,IAAK,CAAA,GAAI,CAAA;AAAA,KAEpG,aAAA,GAAgB,GAAA;EAAM,YAAA;AAAA;EAAmC,YAAA;AAAA;AAAA,cAoCjD,SAAA,GACX,UAAA,0BACA,WAAA,0BACA,OAAA,GAAS,aAAA;AAAA,cA2DE,sBAAA,GACX,UAAA,0BACA,WAAA,0BACA,OAAA,GAAS,aAAA;AAAA,cAiBE,mBAAA,GACX,UAAA,0BACA,WAAA,0BACA,OAAA,GAAS,aAAA;AAAA,cAgBE,aAAA,GACX,CAAA,OACA,CAAA,OACA,OAAA,GAAS,aAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as LocaleFormat, r as ValidateReturn, t as AltUnitWithLabel } from "./chunks/types.js";
|
|
2
|
+
import { C as getAltUnitsListByQuantity, D as showAltUnitsList, E as label, O as unitFromKey, S as withUnit, T as getUnitsForQuantity, _ as getValue, a as altUnitsList, b as split, c as convertAndGetValue, d as to, f as toBase, g as getUnit, h as SEPARATOR, i as validateNumber, k as unitFromQuantity, l as convertAndGetValueStrict, m as unumWithUnit, n as checkAndCleanDecimalComma, o as roundNumberWithLabel, p as unum, r as validateAndClean, s as convertTable, t as EXP_NOTATION_RE, u as convertSamePrecision, v as isEmptyValueWithUnit, w as getQuantities, x as withPrettyUnitLabel, y as isValueWithUnit } from "./chunks/units.js";
|
|
2
3
|
import { isScientificStringNum, isValidNum, toNum, toString } from "./numbers/numbers.js";
|
|
3
4
|
|
|
4
5
|
//#region src/units/constants.d.ts
|
|
@@ -377,5 +378,5 @@ declare const isCloseToOrGreaterThan: (firstValue: number | string | null, secon
|
|
|
377
378
|
declare const isCloseToOrLessThan: (firstValue: number | string | null, secondValue: number | string | null, options?: toleranceType) => boolean;
|
|
378
379
|
declare const isDeepCloseTo: (a: any, b: any, options?: toleranceType) => boolean;
|
|
379
380
|
//#endregion
|
|
380
|
-
export { ALT_UNITS, DEPRECATED_UNITS, INTERMEDIATE_CONVERSIONS, KNOWN_CONVERSIONS, KNOWN_UNITS, LABELS, QUANTITIES_DESCRIPTION, UNITS_DESCRIPTION, UNIT_ALIASES, UNIT_FROM_KEY, allNumbers, altUnitsList, asFraction, charCount, checkAndCleanDecimalComma, cleanNum, cleanNumStr, convertAndGetValue, convertAndGetValueStrict, convertSamePrecision, convertTable, displayNumber, displayNumberToFixed, formatNumber, fraction, getAltUnitsListByQuantity, getNumberOfDigitsToShow, getQuantities, getUnit, getUnitsForQuantity, getValue, isCloseTo, isCloseToOrGreaterThan, isCloseToOrLessThan, isDeepCloseTo, isEmptyValueWithUnit, isFraction, isNonNumerical, isNumeric, isScientificStringNum, isValidNum, isValueWithUnit, label, numFraction, round, roundByMagnitude, roundByMagnitudeToFixed, roundByRange, roundCosmetic, roundNumberWithLabel, roundToDecimalPrecision, roundToFixed, roundToPrecision, showAltUnitsList, split, stripLeadingZeros, to, toBase, toNum, toString, unitFromKey, unitFromQuantity, unum, unumWithUnit, validateAndClean, validateNumber, withPrettyUnitLabel, withUnit };
|
|
381
|
+
export { ALT_UNITS, type AltUnitWithLabel, DEPRECATED_UNITS, EXP_NOTATION_RE, INTERMEDIATE_CONVERSIONS, KNOWN_CONVERSIONS, KNOWN_UNITS, LABELS, type LocaleFormat, QUANTITIES_DESCRIPTION, SEPARATOR, UNITS_DESCRIPTION, UNIT_ALIASES, UNIT_FROM_KEY, type ValidateReturn, allNumbers, altUnitsList, asFraction, charCount, checkAndCleanDecimalComma, cleanNum, cleanNumStr, convertAndGetValue, convertAndGetValueStrict, convertSamePrecision, convertTable, displayNumber, displayNumberToFixed, formatNumber, fraction, getAltUnitsListByQuantity, getNumberOfDigitsToShow, getQuantities, getUnit, getUnitsForQuantity, getValue, isCloseTo, isCloseToOrGreaterThan, isCloseToOrLessThan, isDeepCloseTo, isEmptyValueWithUnit, isFraction, isNonNumerical, isNumeric, isScientificStringNum, isValidNum, isValueWithUnit, label, numFraction, round, roundByMagnitude, roundByMagnitudeToFixed, roundByRange, roundCosmetic, roundNumberWithLabel, roundToDecimalPrecision, roundToFixed, roundToPrecision, showAltUnitsList, split, stripLeadingZeros, to, toBase, toNum, toString, unitFromKey, unitFromQuantity, unum, unumWithUnit, validateAndClean, validateNumber, withPrettyUnitLabel, withUnit };
|
|
381
382
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/units/constants.ts","../src/numbers/fractions/fractions.ts","../src/numbers/parsing/number-input.ts","../src/numbers/predicates.ts","../src/numbers/rounding/number-digits.ts","../src/numbers/format/display-number.ts","../src/numbers/rounding/rounding.ts","../src/numbers/rounding/cosmetic-rounding.ts","../src/numbers/comparison/comparison.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/units/constants.ts","../src/numbers/fractions/fractions.ts","../src/numbers/parsing/number-input.ts","../src/numbers/predicates.ts","../src/numbers/rounding/number-digits.ts","../src/numbers/format/display-number.ts","../src/numbers/rounding/rounding.ts","../src/numbers/rounding/cosmetic-rounding.ts","../src/numbers/comparison/comparison.ts"],"mappings":";;;;;cAQa,MAAA,EAAQ,MAAA;AAAA,cAgOR,SAAA,EAAW,MAAA;A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|
|
1
|
-
import { $ as showAltUnitsList, A as isNonNumerical, B as isEmptyValueWithUnit, C as roundToFixed, D as isCloseToOrLessThan, E as isCloseToOrGreaterThan, F as isFraction, G as charCount, H as split, I as numFraction, J as stripLeadingZeros, K as cleanNum, N as asFraction, O as isDeepCloseTo, P as fraction, Q as label, R as getUnit, S as roundToDecimalPrecision, T as isCloseTo, U as withPrettyUnitLabel, V as isValueWithUnit, W as withUnit, X as getQuantities, Y as getAltUnitsListByQuantity, Z as getUnitsForQuantity, _ as formatNumber, a as toBase, at as KNOWN_CONVERSIONS, b as roundByMagnitudeToFixed, c as checkAndCleanDecimalComma, ct as QUANTITIES_DESCRIPTION, d as isScientificStringNum, dt as UNIT_FROM_KEY, et as unitFromKey, f as isValidNum, g as displayNumberToFixed, h as displayNumber, i as to, it as INTERMEDIATE_CONVERSIONS, j as isNumeric, k as allNumbers, l as validateAndClean, lt as UNITS_DESCRIPTION, m as toString, n as convertAndGetValueStrict, nt as ALT_UNITS, o as unum, ot as KNOWN_UNITS, p as toNum, q as cleanNumStr, r as convertSamePrecision, rt as DEPRECATED_UNITS, s as unumWithUnit, st as LABELS, t as convertAndGetValue, tt as unitFromQuantity, u as validateNumber, ut as UNIT_ALIASES, v as round, w as roundToPrecision, x as roundByRange, y as roundByMagnitude, z as getValue } from "./chunks/conversion.js";
|
|
1
|
+
import { $ as showAltUnitsList, A as isNonNumerical, B as isEmptyValueWithUnit, C as roundToFixed, D as isCloseToOrLessThan, E as isCloseToOrGreaterThan, F as isFraction, G as charCount, H as split, I as numFraction, J as stripLeadingZeros, K as cleanNum, L as SEPARATOR, M as EXP_NOTATION_RE, N as asFraction, O as isDeepCloseTo, P as fraction, Q as label, R as getUnit, S as roundToDecimalPrecision, T as isCloseTo, U as withPrettyUnitLabel, V as isValueWithUnit, W as withUnit, X as getQuantities, Y as getAltUnitsListByQuantity, Z as getUnitsForQuantity, _ as formatNumber, a as toBase, at as KNOWN_CONVERSIONS, b as roundByMagnitudeToFixed, c as checkAndCleanDecimalComma, ct as QUANTITIES_DESCRIPTION, d as isScientificStringNum, dt as UNIT_FROM_KEY, et as unitFromKey, f as isValidNum, g as displayNumberToFixed, h as displayNumber, i as to, it as INTERMEDIATE_CONVERSIONS, j as isNumeric, k as allNumbers, l as validateAndClean, lt as UNITS_DESCRIPTION, m as toString, n as convertAndGetValueStrict, nt as ALT_UNITS, o as unum, ot as KNOWN_UNITS, p as toNum, q as cleanNumStr, r as convertSamePrecision, rt as DEPRECATED_UNITS, s as unumWithUnit, st as LABELS, t as convertAndGetValue, tt as unitFromQuantity, u as validateNumber, ut as UNIT_ALIASES, v as round, w as roundToPrecision, x as roundByRange, y as roundByMagnitude, z as getValue } from "./chunks/conversion.js";
|
|
2
2
|
import { n as roundNumberWithLabel, r as convertTable, t as altUnitsList } from "./chunks/units.js";
|
|
3
3
|
//#region src/numbers/rounding/number-digits.ts
|
|
4
4
|
/**
|
|
@@ -46,6 +46,6 @@ const roundCosmetic = (value) => {
|
|
|
46
46
|
//#region src/index.ts
|
|
47
47
|
/* istanbul ignore file */
|
|
48
48
|
//#endregion
|
|
49
|
-
export { ALT_UNITS, DEPRECATED_UNITS, INTERMEDIATE_CONVERSIONS, KNOWN_CONVERSIONS, KNOWN_UNITS, LABELS, QUANTITIES_DESCRIPTION, UNITS_DESCRIPTION, UNIT_ALIASES, UNIT_FROM_KEY, allNumbers, altUnitsList, asFraction, charCount, checkAndCleanDecimalComma, cleanNum, cleanNumStr, convertAndGetValue, convertAndGetValueStrict, convertSamePrecision, convertTable, displayNumber, displayNumberToFixed, formatNumber, fraction, getAltUnitsListByQuantity, getNumberOfDigitsToShow, getQuantities, getUnit, getUnitsForQuantity, getValue, isCloseTo, isCloseToOrGreaterThan, isCloseToOrLessThan, isDeepCloseTo, isEmptyValueWithUnit, isFraction, isNonNumerical, isNumeric, isScientificStringNum, isValidNum, isValueWithUnit, label, numFraction, round, roundByMagnitude, roundByMagnitudeToFixed, roundByRange, roundCosmetic, roundNumberWithLabel, roundToDecimalPrecision, roundToFixed, roundToPrecision, showAltUnitsList, split, stripLeadingZeros, to, toBase, toNum, toString, unitFromKey, unitFromQuantity, unum, unumWithUnit, validateAndClean, validateNumber, withPrettyUnitLabel, withUnit };
|
|
49
|
+
export { ALT_UNITS, DEPRECATED_UNITS, EXP_NOTATION_RE, INTERMEDIATE_CONVERSIONS, KNOWN_CONVERSIONS, KNOWN_UNITS, LABELS, QUANTITIES_DESCRIPTION, SEPARATOR, UNITS_DESCRIPTION, UNIT_ALIASES, UNIT_FROM_KEY, allNumbers, altUnitsList, asFraction, charCount, checkAndCleanDecimalComma, cleanNum, cleanNumStr, convertAndGetValue, convertAndGetValueStrict, convertSamePrecision, convertTable, displayNumber, displayNumberToFixed, formatNumber, fraction, getAltUnitsListByQuantity, getNumberOfDigitsToShow, getQuantities, getUnit, getUnitsForQuantity, getValue, isCloseTo, isCloseToOrGreaterThan, isCloseToOrLessThan, isDeepCloseTo, isEmptyValueWithUnit, isFraction, isNonNumerical, isNumeric, isScientificStringNum, isValidNum, isValueWithUnit, label, numFraction, round, roundByMagnitude, roundByMagnitudeToFixed, roundByRange, roundCosmetic, roundNumberWithLabel, roundToDecimalPrecision, roundToFixed, roundToPrecision, showAltUnitsList, split, stripLeadingZeros, to, toBase, toNum, toString, unitFromKey, unitFromQuantity, unum, unumWithUnit, validateAndClean, validateNumber, withPrettyUnitLabel, withUnit };
|
|
50
50
|
|
|
51
51
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/numbers/rounding/number-digits.ts","../src/numbers/rounding/cosmetic-rounding.ts","../src/index.ts"],"sourcesContent":["/**\n * Calculates a useful decimal precision for small values used by legacy rounding.\n *\n * @deprecated Use `roundByMagnitude` or another current rounding function instead.\n */\nexport function getNumberOfDigitsToShow(value: number | string, maxNumberOfDigits = 20): number {\n const defaultDigits = Math.min(4, maxNumberOfDigits);\n let digits = defaultDigits;\n if (typeof value !== 'number') {\n return defaultDigits;\n }\n\n const valueString = String(value);\n const exponentialNumber = /-?[0-9.,]*[Ee]-?[0-9]+/;\n if (exponentialNumber.test(valueString)) {\n while (Math.abs(value) * 10 ** digits < 1 && digits < maxNumberOfDigits) {\n digits += 1;\n }\n return Math.min(digits + (defaultDigits - 1), maxNumberOfDigits);\n }\n\n if (value > 1 || value < -1) {\n return defaultDigits;\n }\n\n for (let index = 2; index < valueString.length; index += 1) {\n if (valueString[index] !== '0') {\n return Math.min(maxNumberOfDigits, digits + index - 2);\n }\n }\n return digits;\n}\n","import { isScientificStringNum } from '../numbers.ts';\nimport { roundToPrecision } from './rounding.ts';\n\nconst COSMETIC_ROUNDING_DEFAULT_PRECISION = 14;\n\n/**\n * Applies display-only rounding to remove floating-point conversion noise.\n *\n * The value is rounded to 14 significant digits, while strings written in\n * scientific notation are preserved as entered.\n *\n * - accepts number types, stringified numbers, and unit strings\n * - returns the same type as the input\n *\n * @param value - numeric value to cosmetically round\n * @returns the cosmetically rounded value\n *\n * @example\n * roundCosmetic('9750.000000000004') -> '9750'\n * roundCosmetic('9750.000000000004|m') -> '9750|m'\n */\nexport const roundCosmetic = <Value extends number | string>(value: Value): Value => {\n if (isScientificStringNum(value)) {\n return value;\n }\n\n return roundToPrecision(value, COSMETIC_ROUNDING_DEFAULT_PRECISION);\n};\n","/* istanbul ignore file */\nimport {\n label,\n showAltUnitsList,\n getAltUnitsListByQuantity,\n checkAndCleanDecimalComma,\n unitFromKey,\n to,\n split,\n unum,\n toBase,\n altUnitsList,\n convertTable,\n roundNumberWithLabel,\n withUnit,\n unumWithUnit,\n validateAndClean,\n isValueWithUnit,\n getValue,\n getUnit,\n convertSamePrecision,\n convertAndGetValue,\n convertAndGetValueStrict,\n getUnitsForQuantity,\n getQuantities,\n unitFromQuantity,\n withPrettyUnitLabel,\n validateNumber,\n} from './units.ts';\nimport { isEmptyValueWithUnit } from './units/unit-string.ts';\n\nimport {\n ALT_UNITS,\n LABELS,\n UNIT_FROM_KEY,\n KNOWN_CONVERSIONS,\n DEPRECATED_UNITS,\n UNIT_ALIASES,\n INTERMEDIATE_CONVERSIONS,\n KNOWN_UNITS,\n QUANTITIES_DESCRIPTION,\n UNITS_DESCRIPTION,\n} from './units/constants.ts';\n\nimport { asFraction, fraction, isFraction, numFraction } from './numbers/fractions/fractions.ts';\nimport { charCount, cleanNum, cleanNumStr, stripLeadingZeros } from './numbers/parsing/number-input.ts';\nimport { allNumbers, isNonNumerical, isNumeric } from './numbers/predicates.ts';\nimport { getNumberOfDigitsToShow } from './numbers/rounding/number-digits.ts';\n\nimport { toNum, toString, isValidNum, isScientificStringNum } from './numbers/numbers.ts';\n\nimport { displayNumber, displayNumberToFixed, formatNumber } from './numbers/format/display-number.ts';\n\nimport {\n round,\n roundToFixed,\n roundToPrecision,\n roundToDecimalPrecision,\n roundByMagnitude,\n roundByMagnitudeToFixed,\n roundByRange,\n} from './numbers/rounding/rounding.ts';\n\nimport { roundCosmetic } from './numbers/rounding/cosmetic-rounding.ts';\n\nimport {\n isCloseTo,\n isCloseToOrGreaterThan,\n isCloseToOrLessThan,\n isDeepCloseTo,\n} from './numbers/comparison/comparison.ts';\n\nexport {\n // Units\n label,\n showAltUnitsList,\n getAltUnitsListByQuantity,\n getUnitsForQuantity,\n getQuantities,\n checkAndCleanDecimalComma,\n unitFromKey,\n unitFromQuantity,\n to,\n split,\n unum,\n toBase,\n altUnitsList,\n convertTable,\n roundNumberWithLabel,\n withUnit,\n unumWithUnit,\n validateAndClean,\n isValueWithUnit,\n getValue,\n getUnit,\n convertSamePrecision,\n convertAndGetValue,\n convertAndGetValueStrict,\n withPrettyUnitLabel,\n validateNumber,\n //Rounding\n round,\n roundToFixed,\n roundToPrecision,\n roundToDecimalPrecision,\n roundByMagnitude,\n roundByMagnitudeToFixed,\n roundByRange,\n roundCosmetic,\n //Comparison\n isCloseTo,\n isDeepCloseTo,\n isCloseToOrLessThan,\n isCloseToOrGreaterThan,\n // Utils\n isNumeric,\n isNonNumerical,\n isEmptyValueWithUnit,\n allNumbers,\n formatNumber,\n displayNumber,\n displayNumberToFixed,\n charCount,\n getNumberOfDigitsToShow,\n fraction,\n isFraction,\n asFraction,\n numFraction,\n cleanNumStr,\n cleanNum,\n toNum,\n toString,\n isValidNum,\n isScientificStringNum,\n stripLeadingZeros,\n // Constants\n ALT_UNITS,\n LABELS,\n UNIT_FROM_KEY,\n KNOWN_CONVERSIONS,\n DEPRECATED_UNITS,\n UNIT_ALIASES,\n INTERMEDIATE_CONVERSIONS,\n KNOWN_UNITS,\n QUANTITIES_DESCRIPTION,\n UNITS_DESCRIPTION,\n};\n"],"mappings":";;;;;;;;AAKA,SAAgB,wBAAwB,OAAwB,oBAAoB,IAAY;CAC9F,MAAM,gBAAgB,KAAK,IAAI,GAAG,kBAAkB;CACpD,IAAI,SAAS;AACb,KAAI,OAAO,UAAU,SACnB,QAAO;CAGT,MAAM,cAAc,OAAO,MAAM;AAEjC,KAD0B,yBACJ,KAAK,YAAY,EAAE;AACvC,SAAO,KAAK,IAAI,MAAM,GAAG,MAAM,SAAS,KAAK,SAAS,kBACpD,WAAU;AAEZ,SAAO,KAAK,IAAI,UAAU,gBAAgB,IAAI,kBAAkB;;AAGlE,KAAI,QAAQ,KAAK,QAAQ,GACvB,QAAO;AAGT,MAAK,IAAI,QAAQ,GAAG,QAAQ,YAAY,QAAQ,SAAS,EACvD,KAAI,YAAY,WAAW,IACzB,QAAO,KAAK,IAAI,mBAAmB,SAAS,QAAQ,EAAE;AAG1D,QAAO;;;;AC3BT,MAAM,sCAAsC;;;;;;;;;;;;;;;;;AAkB5C,MAAa,iBAAgD,UAAwB;AACnF,KAAI,sBAAsB,MAAM,CAC9B,QAAO;AAGT,QAAO,iBAAiB,OAAO,oCAAoC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/numbers/rounding/number-digits.ts","../src/numbers/rounding/cosmetic-rounding.ts","../src/index.ts"],"sourcesContent":["/**\n * Calculates a useful decimal precision for small values used by legacy rounding.\n *\n * @deprecated Use `roundByMagnitude` or another current rounding function instead.\n */\nexport function getNumberOfDigitsToShow(value: number | string, maxNumberOfDigits = 20): number {\n const defaultDigits = Math.min(4, maxNumberOfDigits);\n let digits = defaultDigits;\n if (typeof value !== 'number') {\n return defaultDigits;\n }\n\n const valueString = String(value);\n const exponentialNumber = /-?[0-9.,]*[Ee]-?[0-9]+/;\n if (exponentialNumber.test(valueString)) {\n while (Math.abs(value) * 10 ** digits < 1 && digits < maxNumberOfDigits) {\n digits += 1;\n }\n return Math.min(digits + (defaultDigits - 1), maxNumberOfDigits);\n }\n\n if (value > 1 || value < -1) {\n return defaultDigits;\n }\n\n for (let index = 2; index < valueString.length; index += 1) {\n if (valueString[index] !== '0') {\n return Math.min(maxNumberOfDigits, digits + index - 2);\n }\n }\n return digits;\n}\n","import { isScientificStringNum } from '../numbers.ts';\nimport { roundToPrecision } from './rounding.ts';\n\nconst COSMETIC_ROUNDING_DEFAULT_PRECISION = 14;\n\n/**\n * Applies display-only rounding to remove floating-point conversion noise.\n *\n * The value is rounded to 14 significant digits, while strings written in\n * scientific notation are preserved as entered.\n *\n * - accepts number types, stringified numbers, and unit strings\n * - returns the same type as the input\n *\n * @param value - numeric value to cosmetically round\n * @returns the cosmetically rounded value\n *\n * @example\n * roundCosmetic('9750.000000000004') -> '9750'\n * roundCosmetic('9750.000000000004|m') -> '9750|m'\n */\nexport const roundCosmetic = <Value extends number | string>(value: Value): Value => {\n if (isScientificStringNum(value)) {\n return value;\n }\n\n return roundToPrecision(value, COSMETIC_ROUNDING_DEFAULT_PRECISION);\n};\n","/* istanbul ignore file */\nimport {\n label,\n showAltUnitsList,\n getAltUnitsListByQuantity,\n checkAndCleanDecimalComma,\n unitFromKey,\n to,\n split,\n unum,\n toBase,\n altUnitsList,\n convertTable,\n roundNumberWithLabel,\n withUnit,\n unumWithUnit,\n validateAndClean,\n isValueWithUnit,\n getValue,\n getUnit,\n convertSamePrecision,\n convertAndGetValue,\n convertAndGetValueStrict,\n getUnitsForQuantity,\n getQuantities,\n unitFromQuantity,\n withPrettyUnitLabel,\n validateNumber,\n} from './units.ts';\nimport { isEmptyValueWithUnit } from './units/unit-string.ts';\n\nimport {\n ALT_UNITS,\n LABELS,\n UNIT_FROM_KEY,\n KNOWN_CONVERSIONS,\n DEPRECATED_UNITS,\n UNIT_ALIASES,\n INTERMEDIATE_CONVERSIONS,\n KNOWN_UNITS,\n QUANTITIES_DESCRIPTION,\n UNITS_DESCRIPTION,\n} from './units/constants.ts';\n\nimport { asFraction, fraction, isFraction, numFraction } from './numbers/fractions/fractions.ts';\nimport { charCount, cleanNum, cleanNumStr, stripLeadingZeros } from './numbers/parsing/number-input.ts';\nimport { allNumbers, isNonNumerical, isNumeric } from './numbers/predicates.ts';\nimport { getNumberOfDigitsToShow } from './numbers/rounding/number-digits.ts';\n\nimport { toNum, toString, isValidNum, isScientificStringNum } from './numbers/numbers.ts';\n\nimport { displayNumber, displayNumberToFixed, formatNumber } from './numbers/format/display-number.ts';\n\nimport {\n round,\n roundToFixed,\n roundToPrecision,\n roundToDecimalPrecision,\n roundByMagnitude,\n roundByMagnitudeToFixed,\n roundByRange,\n} from './numbers/rounding/rounding.ts';\n\nimport { roundCosmetic } from './numbers/rounding/cosmetic-rounding.ts';\n\nimport {\n isCloseTo,\n isCloseToOrGreaterThan,\n isCloseToOrLessThan,\n isDeepCloseTo,\n} from './numbers/comparison/comparison.ts';\n\nexport {\n // Units\n label,\n showAltUnitsList,\n getAltUnitsListByQuantity,\n getUnitsForQuantity,\n getQuantities,\n checkAndCleanDecimalComma,\n unitFromKey,\n unitFromQuantity,\n to,\n split,\n unum,\n toBase,\n altUnitsList,\n convertTable,\n roundNumberWithLabel,\n withUnit,\n unumWithUnit,\n validateAndClean,\n isValueWithUnit,\n getValue,\n getUnit,\n convertSamePrecision,\n convertAndGetValue,\n convertAndGetValueStrict,\n withPrettyUnitLabel,\n validateNumber,\n //Rounding\n round,\n roundToFixed,\n roundToPrecision,\n roundToDecimalPrecision,\n roundByMagnitude,\n roundByMagnitudeToFixed,\n roundByRange,\n roundCosmetic,\n //Comparison\n isCloseTo,\n isDeepCloseTo,\n isCloseToOrLessThan,\n isCloseToOrGreaterThan,\n // Utils\n isNumeric,\n isNonNumerical,\n isEmptyValueWithUnit,\n allNumbers,\n formatNumber,\n displayNumber,\n displayNumberToFixed,\n charCount,\n getNumberOfDigitsToShow,\n fraction,\n isFraction,\n asFraction,\n numFraction,\n cleanNumStr,\n cleanNum,\n toNum,\n toString,\n isValidNum,\n isScientificStringNum,\n stripLeadingZeros,\n // Constants\n ALT_UNITS,\n LABELS,\n UNIT_FROM_KEY,\n KNOWN_CONVERSIONS,\n DEPRECATED_UNITS,\n UNIT_ALIASES,\n INTERMEDIATE_CONVERSIONS,\n KNOWN_UNITS,\n QUANTITIES_DESCRIPTION,\n UNITS_DESCRIPTION,\n};\n\nexport { EXP_NOTATION_RE } from './numbers/scientific-notation/scientific-notation.ts';\nexport { SEPARATOR } from './units/unit-string.ts';\nexport type { AltUnitWithLabel, LocaleFormat, ValidateReturn } from './units/types.ts';\n"],"mappings":";;;;;;;;AAKA,SAAgB,wBAAwB,OAAwB,oBAAoB,IAAY;CAC9F,MAAM,gBAAgB,KAAK,IAAI,GAAG,kBAAkB;CACpD,IAAI,SAAS;AACb,KAAI,OAAO,UAAU,SACnB,QAAO;CAGT,MAAM,cAAc,OAAO,MAAM;AAEjC,KAD0B,yBACJ,KAAK,YAAY,EAAE;AACvC,SAAO,KAAK,IAAI,MAAM,GAAG,MAAM,SAAS,KAAK,SAAS,kBACpD,WAAU;AAEZ,SAAO,KAAK,IAAI,UAAU,gBAAgB,IAAI,kBAAkB;;AAGlE,KAAI,QAAQ,KAAK,QAAQ,GACvB,QAAO;AAGT,MAAK,IAAI,QAAQ,GAAG,QAAQ,YAAY,QAAQ,SAAS,EACvD,KAAI,YAAY,WAAW,IACzB,QAAO,KAAK,IAAI,mBAAmB,SAAS,QAAQ,EAAE;AAG1D,QAAO;;;;AC3BT,MAAM,sCAAsC;;;;;;;;;;;;;;;;;AAkB5C,MAAa,iBAAgD,UAAwB;AACnF,KAAI,sBAAsB,MAAM,CAC9B,QAAO;AAGT,QAAO,iBAAiB,OAAO,oCAAoC"}
|