@oliasoft-open-source/units 5.4.2 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -2,24 +2,25 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_units = require("./units2.cjs");
3
3
  //#region src/rounding/cosmetic-rounding.ts
4
4
  const COSMETIC_ROUNDING_DEFAULT_PRECISION = 14;
5
- const safeToString = (value) => {
6
- return String(require_units.toString(value));
7
- };
8
5
  /**
9
6
  * Applies display-only rounding to remove floating-point conversion noise.
10
7
  *
11
8
  * The value is rounded to 14 significant digits, while strings written in
12
9
  * scientific notation are preserved as entered.
13
10
  *
14
- * @param value - numeric value in string representation
15
- * @returns the cosmetically rounded string
11
+ * - accepts number types, stringified numbers, and unit strings
12
+ * - returns the same type as the input
13
+ *
14
+ * @param value - numeric value to cosmetically round
15
+ * @returns the cosmetically rounded value
16
16
  *
17
17
  * @example
18
- * roundNumberCosmetic('9750.000000000004') -> '9750'
18
+ * roundCosmetic('9750.000000000004') -> '9750'
19
+ * roundCosmetic('9750.000000000004|m') -> '9750|m'
19
20
  */
20
- const roundNumberCosmetic = (value) => {
21
+ const roundCosmetic = (value) => {
21
22
  if (require_units.isScientificStringNum(value)) return value;
22
- return safeToString(require_units.roundToPrecision(require_units.toNum(value), COSMETIC_ROUNDING_DEFAULT_PRECISION));
23
+ return require_units.roundToPrecision(value, COSMETIC_ROUNDING_DEFAULT_PRECISION);
23
24
  };
24
25
  //#endregion
25
26
  //#region src/index.ts
@@ -73,7 +74,7 @@ exports.round = require_units.round;
73
74
  exports.roundByMagnitude = require_units.roundByMagnitude;
74
75
  exports.roundByMagnitudeToFixed = require_units.roundByMagnitudeToFixed;
75
76
  exports.roundByRange = require_units.roundByRange;
76
- exports.roundNumberCosmetic = roundNumberCosmetic;
77
+ exports.roundCosmetic = roundCosmetic;
77
78
  exports.roundNumberWithLabel = require_units.roundNumberWithLabel;
78
79
  exports.roundToDecimalPrecision = require_units.roundToDecimalPrecision;
79
80
  exports.roundToFixed = require_units.roundToFixed;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["toString","isScientificStringNum","roundToPrecision","toNum"],"sources":["../src/rounding/cosmetic-rounding.ts","../src/index.ts"],"sourcesContent":["import { isScientificStringNum, toNum, toString } from '../numbers/numbers.ts';\nimport { roundToPrecision } from './rounding.ts';\n\nconst COSMETIC_ROUNDING_DEFAULT_PRECISION = 14;\n\nconst safeToString = (value: string | number): string => {\n return String(toString(value));\n};\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 * @param value - numeric value in string representation\n * @returns the cosmetically rounded string\n *\n * @example\n * roundNumberCosmetic('9750.000000000004') -> '9750'\n */\nexport const roundNumberCosmetic = (value: string): string => {\n if (isScientificStringNum(value)) {\n return value;\n }\n\n return safeToString(\n roundToPrecision(toNum(value), COSMETIC_ROUNDING_DEFAULT_PRECISION),\n );\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';\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 './constants.ts';\n\nimport {\n isNumeric,\n isNonNumerical,\n isEmptyValueWithUnit,\n allNumbers,\n formatNumber,\n charCount,\n getNumberOfDigitsToShow,\n fraction,\n isFraction,\n asFraction,\n numFraction,\n cleanNumStr,\n cleanNum,\n stripLeadingZeros,\n} from './utils.ts';\n\nimport {\n toNum,\n toString,\n isValidNum,\n isScientificStringNum,\n} from './numbers/numbers.ts';\n\nimport {\n displayNumber,\n displayNumberToFixed,\n} from './numbers/display-number.ts';\n\nimport {\n round,\n roundToFixed,\n roundToPrecision,\n roundToDecimalPrecision,\n roundByMagnitude,\n roundByMagnitudeToFixed,\n roundByRange,\n} from './rounding/rounding.ts';\n\nimport { roundNumberCosmetic } from './rounding/cosmetic-rounding.ts';\n\nimport {\n isCloseTo,\n isDeepCloseTo,\n isCloseToOrLessThan,\n isCloseToOrGreaterThan,\n} from './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 roundNumberCosmetic,\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":";;;AAGA,MAAM,sCAAsC;AAE5C,MAAM,gBAAgB,UAAmC;AACvD,QAAO,OAAOA,cAAAA,SAAS,MAAM,CAAC;;;;;;;;;;;;;;AAehC,MAAa,uBAAuB,UAA0B;AAC5D,KAAIC,cAAAA,sBAAsB,MAAM,CAC9B,QAAO;AAGT,QAAO,aACLC,cAAAA,iBAAiBC,cAAAA,MAAM,MAAM,EAAE,oCAAoC,CACpE"}
1
+ {"version":3,"file":"index.cjs","names":["isScientificStringNum","roundToPrecision"],"sources":["../src/rounding/cosmetic-rounding.ts","../src/index.ts"],"sourcesContent":["import { isScientificStringNum } from '../numbers/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>(\n value: Value,\n): 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';\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 './constants.ts';\n\nimport {\n isNumeric,\n isNonNumerical,\n isEmptyValueWithUnit,\n allNumbers,\n formatNumber,\n charCount,\n getNumberOfDigitsToShow,\n fraction,\n isFraction,\n asFraction,\n numFraction,\n cleanNumStr,\n cleanNum,\n stripLeadingZeros,\n} from './utils.ts';\n\nimport {\n toNum,\n toString,\n isValidNum,\n isScientificStringNum,\n} from './numbers/numbers.ts';\n\nimport {\n displayNumber,\n displayNumberToFixed,\n} from './numbers/display-number.ts';\n\nimport {\n round,\n roundToFixed,\n roundToPrecision,\n roundToDecimalPrecision,\n roundByMagnitude,\n roundByMagnitudeToFixed,\n roundByRange,\n} from './rounding/rounding.ts';\n\nimport { roundCosmetic } from './rounding/cosmetic-rounding.ts';\n\nimport {\n isCloseTo,\n isDeepCloseTo,\n isCloseToOrLessThan,\n isCloseToOrGreaterThan,\n} from './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":";;;AAGA,MAAM,sCAAsC;;;;;;;;;;;;;;;;;AAkB5C,MAAa,iBACX,UACU;AACV,KAAIA,cAAAA,sBAAsB,MAAM,CAC9B,QAAO;AAGT,QAAOC,cAAAA,iBAAiB,OAAO,oCAAoC"}
package/dist/index.d.cts CHANGED
@@ -357,7 +357,7 @@ declare const roundByRange: <Value extends number | string | null | undefined>(v
357
357
  declare const roundToFixed: <Value extends number | string | null | undefined>(value: Value, n?: number) => Value;
358
358
  //#endregion
359
359
  //#region src/rounding/cosmetic-rounding.d.ts
360
- declare const roundNumberCosmetic: (value: string) => string;
360
+ declare const roundCosmetic: <Value extends number | string>(value: Value) => Value;
361
361
  //#endregion
362
362
  //#region src/comparison/comparison.d.ts
363
363
  type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
@@ -372,5 +372,5 @@ declare const isCloseToOrGreaterThan: (firstValue: number | string | null, secon
372
372
  declare const isCloseToOrLessThan: (firstValue: number | string | null, secondValue: number | string | null, options?: toleranceType) => boolean;
373
373
  declare const isDeepCloseTo: (a: any, b: any, options?: toleranceType) => boolean;
374
374
  //#endregion
375
- 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, roundNumberCosmetic, roundNumberWithLabel, roundToDecimalPrecision, roundToFixed, roundToPrecision, showAltUnitsList, split, stripLeadingZeros, to, toBase, toNum, toString, unitFromKey, unitFromQuantity, unum, unumWithUnit, validateAndClean, validateNumber, withPrettyUnitLabel, withUnit };
375
+ 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 };
376
376
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/constants.ts","../src/utils.ts","../src/numbers/display-number.ts","../src/rounding/rounding.ts","../src/rounding/cosmetic-rounding.ts","../src/comparison/comparison.ts"],"mappings":";;;;cAQa,MAAA,EAAQ,MAAA;AAAA,cAgOR,SAAA,EAAW,MAAA;AAAA,cAiMX,aAAA,EAAe,MAAA;AAAA,cA8Gf,iBAAA,EAAmB,MAAA,UAAgB,GAAA;AAAA,cA4gBnC,gBAAA,EAAkB,MAAA;AAAA,cAclB,YAAA,EAAc,MAAA;AAAA,cAYd,wBAAA,EAA0B,MAAA;AAAA,cA0K1B,WAAA;AAAA,cAaA,sBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8FA,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCtzCG,oBAAA,CAAqB,GAAA;AAAA,cAkBxB,UAAA,GAAc,KAAA;AAAA,iBAeX,SAAA,CAAU,CAAA;AAAA,iBA6BV,UAAA,CAAW,GAAA;AAAA,cAWd,YAAA,GACX,MAAA;AAAA,iBAUc,SAAA,CAAU,GAAA,mBAAsB,GAAA;AAAA,iBAyBhC,uBAAA,CACd,GAAA,mBACA,YAAA;AAAA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,CAAA,GAAI,CAAA;AAAA,KAEL,aAAA,GAAgB,GAAA;EACjB,YAAA;AAAA;EACA,YAAA;AAAA;AAAA,cAuCS,SAAA,GACX,UAAA,0BACA,WAAA,0BACA,OAAA,GAAS,aAAA;AAAA,cAuEE,sBAAA,GACX,UAAA,0BACA,WAAA,0BACA,OAAA,GAAS,aAAA;AAAA,cAoBE,mBAAA,GACX,UAAA,0BACA,WAAA,0BACA,OAAA,GAAS,aAAA;AAAA,cAmBE,aAAA,GACX,CAAA,OACA,CAAA,OACA,OAAA,GAAS,aAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/constants.ts","../src/utils.ts","../src/numbers/display-number.ts","../src/rounding/rounding.ts","../src/rounding/cosmetic-rounding.ts","../src/comparison/comparison.ts"],"mappings":";;;;cAQa,MAAA,EAAQ,MAAA;AAAA,cAgOR,SAAA,EAAW,MAAA;AAAA,cAiMX,aAAA,EAAe,MAAA;AAAA,cA8Gf,iBAAA,EAAmB,MAAA,UAAgB,GAAA;AAAA,cA4gBnC,gBAAA,EAAkB,MAAA;AAAA,cAclB,YAAA,EAAc,MAAA;AAAA,cAYd,wBAAA,EAA0B,MAAA;AAAA,cA0K1B,WAAA;AAAA,cAaA,sBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8FA,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCtzCG,oBAAA,CAAqB,GAAA;AAAA,cAkBxB,UAAA,GAAc,KAAA;AAAA,iBAeX,SA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AwB,OAAA,OAAc,CAAA,QAAS,CAAA;AAAA,KAC/C,GAAA,SACH,CAAA,GAAI,CAAA,SAAU,MAAA,qBACT,OAAA,CAAQ,CAAA,EAAG,CAAA,IAAK,CAAA,KAAM,OAAA,CAAQ,CAAA,EAAG,CAAA,IAAK,CAAA,IACvC,CAAA,GAAI,CAAA;AAAA,KAEL,aAAA,GAAgB,GAAA;EACjB,YAAA;AAAA;EACA,YAAA;AAAA;AAAA,cAuCS,SAAA,GACX,UAAA,0BACA,WAAA,0BACA,OAAA,GAAS,aAAA;AAAA,cAuEE,sBAAA,GACX,UAAA,0BACA,WAAA,0BACA,OAAA,GAAS,aAAA;AAAA,cAoBE,mBAAA,GACX,UAAA,0BACA,WAAA,0BACA,OAAA,GAAS,aAAA;AAAA,cAmBE,aAAA,GACX,CAAA,OACA,CAAA,OACA,OAAA,GAAS,aAAA"}
package/dist/index.d.ts CHANGED
@@ -357,7 +357,7 @@ declare const roundByRange: <Value extends number | string | null | undefined>(v
357
357
  declare const roundToFixed: <Value extends number | string | null | undefined>(value: Value, n?: number) => Value;
358
358
  //#endregion
359
359
  //#region src/rounding/cosmetic-rounding.d.ts
360
- declare const roundNumberCosmetic: (value: string) => string;
360
+ declare const roundCosmetic: <Value extends number | string>(value: Value) => Value;
361
361
  //#endregion
362
362
  //#region src/comparison/comparison.d.ts
363
363
  type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
@@ -372,5 +372,5 @@ declare const isCloseToOrGreaterThan: (firstValue: number | string | null, secon
372
372
  declare const isCloseToOrLessThan: (firstValue: number | string | null, secondValue: number | string | null, options?: toleranceType) => boolean;
373
373
  declare const isDeepCloseTo: (a: any, b: any, options?: toleranceType) => boolean;
374
374
  //#endregion
375
- 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, roundNumberCosmetic, roundNumberWithLabel, roundToDecimalPrecision, roundToFixed, roundToPrecision, showAltUnitsList, split, stripLeadingZeros, to, toBase, toNum, toString, unitFromKey, unitFromQuantity, unum, unumWithUnit, validateAndClean, validateNumber, withPrettyUnitLabel, withUnit };
375
+ 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 };
376
376
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/constants.ts","../src/utils.ts","../src/numbers/display-number.ts","../src/rounding/rounding.ts","../src/rounding/cosmetic-rounding.ts","../src/comparison/comparison.ts"],"mappings":";;;;cAQa,MAAA,EAAQ,MAAA;AAAA,cAgOR,SAAA,EAAW,MAAA;AAAA,cAiMX,aAAA,EAAe,MAAA;AAAA,cA8Gf,iBAAA,EAAmB,MAAA,UAAgB,GAAA;AAAA,cA4gBnC,gBAAA,EAAkB,MAAA;AAAA,cAclB,YAAA,EAAc,MAAA;AAAA,cAYd,wBAAA,EAA0B,MAAA;AAAA,cA0K1B,WAAA;AAAA,cAaA,sBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8FA,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCtzCG,oBAAA,CAAqB,GAAA;AAAA,cAkBxB,UAAA,GAAc,KAAA;AAAA,iBAeX,SAAA,CAAU,CAAA;AAAA,iBA6BV,UAAA,CAAW,GAAA;AAAA,cAWd,YAAA,GACX,MAAA;AAAA,iBAUc,SAAA,CAAU,GAAA,mBAAsB,GAAA;AAAA,iBAyBhC,uBAAA,CACd,GAAA,mBACA,YAAA;AAAA,iBAsCc,QAAA,CAAS,GAAA,wBAA2B,QAAA,UAAkB,GAAA;AAAA,iBA8BtD,UAAA,CAAW,GAAA;AAAA,iBAsBX,WAAA,CAAY,GAAA;AAAA,iBAgDZ,WAAA,CA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aAAA;AAAA,cAuEE,sBAAA,GACX,UAAA,0BACA,WAAA,0BACA,OAAA,GAAS,aAAA;AAAA,cAoBE,mBAAA,GACX,UAAA,0BACA,WAAA,0BACA,OAAA,GAAS,aAAA;AAAA,cAmBE,aAAA,GACX,CAAA,OACA,CAAA,OACA,OAAA,GAAS,aAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/constants.ts","../src/utils.ts","../src/numbers/display-number.ts","../src/rounding/rounding.ts","../src/rounding/cosmetic-rounding.ts","../src/comparison/comparison.ts"],"mappings":";;;;cAQa,MAAA,EAAQ,MAAA;AAAA,cAgOR,SAAA,EAAW,MAAA;AAAA,cAiMX,aAAA,EAAe,MAAA;AAAA,cA8Gf,iBAAA,EAAmB,MAAA,UAAgB,GAAA;AAAA,cA4gBnC,gBAAA,EAAkB,MAAA;AAAA,cAclB,YAAA,EAAc,MAAA;AAAA,cAYd,wBAAA,EAA0B,MAAA;AAAA,cA0K1B,WAAA;AAAA,cAaA,sBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8FA,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCtzCG,oBAAA,CAAqB,GAAA;AAAA,cAkBxB,UAAA,GAAc,KAAA;AAAA,iBAeX,SAAA,CAAU,CAAA;AAAA,iBA6BV,UAAA,CAAW,GAAA;AAAA,cAWd,YAAA,GACX,MAAA;AAAA,iBAUc,SAAA,CAAU,GAAA,mBAAsB,GAAA;AAAA,iBAyBhC,uBAAA,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AAA,CAAQ,CAAA,EAAG,CAAA,IAAK,CAAA,IACvC,CAAA,GAAI,CAAA;AAAA,KAEL,aAAA,GAAgB,GAAA;EACjB,YAAA;AAAA;EACA,YAAA;AAAA;AAAA,cAuCS,SAAA,GACX,UAAA,0BACA,WAAA,0BACA,OAAA,GAAS,aAAA;AAAA,cAuEE,sBAAA,GACX,UAAA,0BACA,WAAA,0BACA,OAAA,GAAS,aAAA;AAAA,cAoBE,mBAAA,GACX,UAAA,0BACA,WAAA,0BACA,OAAA,GAAS,aAAA;AAAA,cAmBE,aAAA,GACX,CAAA,OACA,CAAA,OACA,OAAA,GAAS,aAAA"}
package/dist/index.js CHANGED
@@ -1,29 +1,30 @@
1
1
  import { $ as displayNumber, A as DEPRECATED_UNITS, B as asFraction, C as unum, D as withPrettyUnitLabel, E as validateNumber, F as QUANTITIES_DESCRIPTION, G as fraction, H as cleanNum, I as UNITS_DESCRIPTION, J as isFraction, K as getNumberOfDigitsToShow, L as UNIT_ALIASES, M as KNOWN_CONVERSIONS, N as KNOWN_UNITS, O as withUnit, P as LABELS, Q as stripLeadingZeros, R as UNIT_FROM_KEY, S as unitFromQuantity, T as validateAndClean, U as cleanNumStr, V as charCount, W as formatNumber, X as isNumeric, Y as isNonNumerical, Z as numFraction, _ as showAltUnitsList, a as convertAndGetValue, at as roundToDecimalPrecision, b as toBase, c as convertTable, ct as isCloseTo, d as getUnit, dt as isDeepCloseTo, et as displayNumberToFixed, f as getUnitsForQuantity, ft as isScientificStringNum, g as roundNumberWithLabel, h as label, ht as toString, i as checkAndCleanDecimalComma, it as roundByRange, j as INTERMEDIATE_CONVERSIONS, k as ALT_UNITS, l as getAltUnitsListByQuantity, lt as isCloseToOrGreaterThan, m as isValueWithUnit, mt as toNum, nt as roundByMagnitude, o as convertAndGetValueStrict, ot as roundToFixed, p as getValue, pt as isValidNum, q as isEmptyValueWithUnit, r as altUnitsList, rt as roundByMagnitudeToFixed, s as convertSamePrecision, st as roundToPrecision, tt as round, u as getQuantities, ut as isCloseToOrLessThan, v as split, w as unumWithUnit, x as unitFromKey, y as to, z as allNumbers } from "./units2.js";
2
2
  //#region src/rounding/cosmetic-rounding.ts
3
3
  const COSMETIC_ROUNDING_DEFAULT_PRECISION = 14;
4
- const safeToString = (value) => {
5
- return String(toString(value));
6
- };
7
4
  /**
8
5
  * Applies display-only rounding to remove floating-point conversion noise.
9
6
  *
10
7
  * The value is rounded to 14 significant digits, while strings written in
11
8
  * scientific notation are preserved as entered.
12
9
  *
13
- * @param value - numeric value in string representation
14
- * @returns the cosmetically rounded string
10
+ * - accepts number types, stringified numbers, and unit strings
11
+ * - returns the same type as the input
12
+ *
13
+ * @param value - numeric value to cosmetically round
14
+ * @returns the cosmetically rounded value
15
15
  *
16
16
  * @example
17
- * roundNumberCosmetic('9750.000000000004') -> '9750'
17
+ * roundCosmetic('9750.000000000004') -> '9750'
18
+ * roundCosmetic('9750.000000000004|m') -> '9750|m'
18
19
  */
19
- const roundNumberCosmetic = (value) => {
20
+ const roundCosmetic = (value) => {
20
21
  if (isScientificStringNum(value)) return value;
21
- return safeToString(roundToPrecision(toNum(value), COSMETIC_ROUNDING_DEFAULT_PRECISION));
22
+ return roundToPrecision(value, COSMETIC_ROUNDING_DEFAULT_PRECISION);
22
23
  };
23
24
  //#endregion
24
25
  //#region src/index.ts
25
26
  /* istanbul ignore file */
26
27
  //#endregion
27
- 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, roundNumberCosmetic, roundNumberWithLabel, roundToDecimalPrecision, roundToFixed, roundToPrecision, showAltUnitsList, split, stripLeadingZeros, to, toBase, toNum, toString, unitFromKey, unitFromQuantity, unum, unumWithUnit, validateAndClean, validateNumber, withPrettyUnitLabel, withUnit };
28
+ 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 };
28
29
 
29
30
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/rounding/cosmetic-rounding.ts","../src/index.ts"],"sourcesContent":["import { isScientificStringNum, toNum, toString } from '../numbers/numbers.ts';\nimport { roundToPrecision } from './rounding.ts';\n\nconst COSMETIC_ROUNDING_DEFAULT_PRECISION = 14;\n\nconst safeToString = (value: string | number): string => {\n return String(toString(value));\n};\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 * @param value - numeric value in string representation\n * @returns the cosmetically rounded string\n *\n * @example\n * roundNumberCosmetic('9750.000000000004') -> '9750'\n */\nexport const roundNumberCosmetic = (value: string): string => {\n if (isScientificStringNum(value)) {\n return value;\n }\n\n return safeToString(\n roundToPrecision(toNum(value), COSMETIC_ROUNDING_DEFAULT_PRECISION),\n );\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';\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 './constants.ts';\n\nimport {\n isNumeric,\n isNonNumerical,\n isEmptyValueWithUnit,\n allNumbers,\n formatNumber,\n charCount,\n getNumberOfDigitsToShow,\n fraction,\n isFraction,\n asFraction,\n numFraction,\n cleanNumStr,\n cleanNum,\n stripLeadingZeros,\n} from './utils.ts';\n\nimport {\n toNum,\n toString,\n isValidNum,\n isScientificStringNum,\n} from './numbers/numbers.ts';\n\nimport {\n displayNumber,\n displayNumberToFixed,\n} from './numbers/display-number.ts';\n\nimport {\n round,\n roundToFixed,\n roundToPrecision,\n roundToDecimalPrecision,\n roundByMagnitude,\n roundByMagnitudeToFixed,\n roundByRange,\n} from './rounding/rounding.ts';\n\nimport { roundNumberCosmetic } from './rounding/cosmetic-rounding.ts';\n\nimport {\n isCloseTo,\n isDeepCloseTo,\n isCloseToOrLessThan,\n isCloseToOrGreaterThan,\n} from './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 roundNumberCosmetic,\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":";;AAGA,MAAM,sCAAsC;AAE5C,MAAM,gBAAgB,UAAmC;AACvD,QAAO,OAAO,SAAS,MAAM,CAAC;;;;;;;;;;;;;;AAehC,MAAa,uBAAuB,UAA0B;AAC5D,KAAI,sBAAsB,MAAM,CAC9B,QAAO;AAGT,QAAO,aACL,iBAAiB,MAAM,MAAM,EAAE,oCAAoC,CACpE"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/rounding/cosmetic-rounding.ts","../src/index.ts"],"sourcesContent":["import { isScientificStringNum } from '../numbers/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>(\n value: Value,\n): 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';\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 './constants.ts';\n\nimport {\n isNumeric,\n isNonNumerical,\n isEmptyValueWithUnit,\n allNumbers,\n formatNumber,\n charCount,\n getNumberOfDigitsToShow,\n fraction,\n isFraction,\n asFraction,\n numFraction,\n cleanNumStr,\n cleanNum,\n stripLeadingZeros,\n} from './utils.ts';\n\nimport {\n toNum,\n toString,\n isValidNum,\n isScientificStringNum,\n} from './numbers/numbers.ts';\n\nimport {\n displayNumber,\n displayNumberToFixed,\n} from './numbers/display-number.ts';\n\nimport {\n round,\n roundToFixed,\n roundToPrecision,\n roundToDecimalPrecision,\n roundByMagnitude,\n roundByMagnitudeToFixed,\n roundByRange,\n} from './rounding/rounding.ts';\n\nimport { roundCosmetic } from './rounding/cosmetic-rounding.ts';\n\nimport {\n isCloseTo,\n isDeepCloseTo,\n isCloseToOrLessThan,\n isCloseToOrGreaterThan,\n} from './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":";;AAGA,MAAM,sCAAsC;;;;;;;;;;;;;;;;;AAkB5C,MAAa,iBACX,UACU;AACV,KAAI,sBAAsB,MAAM,CAC9B,QAAO;AAGT,QAAO,iBAAiB,OAAO,oCAAoC"}
@@ -2,7 +2,7 @@
2
2
  declare const isValidNum: (value: unknown) => boolean;
3
3
  declare const isScientificStringNum: (value: unknown) => boolean;
4
4
  declare const toNum: (value: unknown, fallback?: number, minimum?: number) => any;
5
- declare const toString: (value?: unknown) => unknown;
5
+ declare const toString: (value?: unknown) => any;
6
6
  //#endregion
7
7
  export { isScientificStringNum, isValidNum, toNum, toString };
8
8
  //# sourceMappingURL=numbers.d.cts.map
@@ -2,7 +2,7 @@
2
2
  declare const isValidNum: (value: unknown) => boolean;
3
3
  declare const isScientificStringNum: (value: unknown) => boolean;
4
4
  declare const toNum: (value: unknown, fallback?: number, minimum?: number) => any;
5
- declare const toString: (value?: unknown) => unknown;
5
+ declare const toString: (value?: unknown) => any;
6
6
  //#endregion
7
7
  export { isScientificStringNum, isValidNum, toNum, toString };
8
8
  //# sourceMappingURL=numbers.d.ts.map
package/dist/units2.cjs CHANGED
@@ -171,7 +171,7 @@ const parseNumber = (value, preserveTrailingZeros = false) => {
171
171
  * @returns number or string output value
172
172
  */
173
173
  const safeStringifyNumber = (value, isScientific) => {
174
- return isScientific ? String(value) : String(toString(value));
174
+ return isScientific ? String(value) : toString(value);
175
175
  };
176
176
  /**
177
177
  * Internal function to unParse a value, unit, and type back to an output value
@@ -2974,7 +2974,7 @@ function convertAndGetValueStrict(value, toUnit, fromUnit) {
2974
2974
  if (typeof value === "string" && isValueWithUnit(value) && getValue(value) === "") return "";
2975
2975
  const isString = typeof value === "string";
2976
2976
  const result = convertAndGetValue(value, toUnit, fromUnit);
2977
- return isString ? String(toString(result)) : result;
2977
+ return isString ? toString(result) : result;
2978
2978
  }
2979
2979
  /**
2980
2980
  * Convert value to the base unit given by the quantity