@oliasoft-open-source/units 5.5.2-beta-2 → 5.6.0-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.
Files changed (41) hide show
  1. package/dist/{units2.cjs → chunks/conversion.cjs} +1711 -1998
  2. package/dist/chunks/conversion.cjs.map +1 -0
  3. package/dist/{units2.js → chunks/conversion.js} +1710 -1973
  4. package/dist/chunks/conversion.js.map +1 -0
  5. package/dist/{interfaces2.d.ts → chunks/types.d.cts} +2 -2
  6. package/dist/chunks/types.d.cts.map +1 -0
  7. package/dist/{interfaces2.d.cts → chunks/types.d.ts} +2 -2
  8. package/dist/chunks/types.d.ts.map +1 -0
  9. package/dist/chunks/units.cjs +55 -0
  10. package/dist/chunks/units.cjs.map +1 -0
  11. package/dist/chunks/units.d.cts +47 -0
  12. package/dist/chunks/units.d.cts.map +1 -0
  13. package/dist/chunks/units.d.ts +47 -0
  14. package/dist/chunks/units.d.ts.map +1 -0
  15. package/dist/chunks/units.js +38 -0
  16. package/dist/chunks/units.js.map +1 -0
  17. package/dist/index.cjs +89 -68
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +23 -19
  20. package/dist/index.d.cts.map +1 -1
  21. package/dist/index.d.ts +23 -19
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +23 -2
  24. package/dist/index.js.map +1 -1
  25. package/dist/interfaces.d.cts +2 -2
  26. package/dist/interfaces.d.ts +2 -2
  27. package/dist/numbers/numbers.cjs +5 -5
  28. package/dist/numbers/numbers.d.cts.map +1 -1
  29. package/dist/numbers/numbers.d.ts.map +1 -1
  30. package/dist/numbers/numbers.js +1 -1
  31. package/dist/units.cjs +27 -26
  32. package/dist/units.d.cts +2 -34
  33. package/dist/units.d.ts +2 -34
  34. package/dist/units.js +2 -1
  35. package/package.json +6 -6
  36. package/dist/interfaces2.d.cts.map +0 -1
  37. package/dist/interfaces2.d.ts.map +0 -1
  38. package/dist/units.d.cts.map +0 -1
  39. package/dist/units.d.ts.map +0 -1
  40. package/dist/units2.cjs.map +0 -1
  41. package/dist/units2.js.map +0 -1
@@ -0,0 +1,47 @@
1
+ import { r as ValidateReturn, t as AltUnitWithLabel } from "./types.cjs";
2
+
3
+ //#region src/units/unit-catalog.d.ts
4
+ declare function showAltUnitsList(quantityKey: string): string[] | undefined;
5
+ declare function getUnitsForQuantity(quantity: string): string[] | undefined;
6
+ declare function getQuantities(): string[] | undefined;
7
+ declare function label(unitKey: string): string | undefined;
8
+ declare function unitFromKey(quantity: string): string | undefined;
9
+ declare function unitFromQuantity(quantity: string): string | undefined;
10
+ declare function getAltUnitsListByQuantity(quantity: string): AltUnitWithLabel[] | undefined;
11
+ //#endregion
12
+ //#region src/units/unit-string.d.ts
13
+ declare const SEPARATOR = "|";
14
+ declare function isEmptyValueWithUnit(value: string | number): boolean;
15
+ declare function split(valueWithUnit: string): string[];
16
+ declare function getValue(valueWithUnit: string): string;
17
+ declare function getUnit(valueWithUnit: string): string;
18
+ declare function isValueWithUnit(value: string | number): boolean;
19
+ declare function withUnit(value: string | number | null | undefined, unit: string | null, defaultValue?: string): string;
20
+ declare function withPrettyUnitLabel(valueWithUnits: string): string;
21
+ //#endregion
22
+ //#region src/units/conversion.d.ts
23
+ declare function to(value: string | number, fromUnit: string, toUnit: string): number;
24
+ declare function unum(valueWithUnit: string | number, toUnit: string, fromUnit?: string): number;
25
+ declare function convertAndGetValue(value: string | number, toUnit: string, fromUnit?: string): number;
26
+ declare function convertAndGetValueStrict(value: string | number | null, toUnit: string, fromUnit?: string): string | number | null;
27
+ declare function toBase(value: string, quantity: string): number;
28
+ declare function unumWithUnit(value: string | number, toUnit: string, fromUnit?: string): string;
29
+ declare function convertSamePrecision(valueWithUnit: string | number, toUnit: string, digits?: number): string;
30
+ //#endregion
31
+ //#region src/units/table-conversion.d.ts
32
+ declare function convertTable(toUnitRow: any, table: any, defaultUnitRow?: [], removeFinalUnitsRow?: boolean): string | number[][];
33
+ //#endregion
34
+ //#region src/units/formatting.d.ts
35
+ declare function roundNumberWithLabel(value: string, numberOfDigits?: number): string;
36
+ declare function altUnitsList(value: string, quantity: string): (string | undefined)[][];
37
+ //#endregion
38
+ //#region src/units/validation.d.ts
39
+ declare function checkAndCleanDecimalComma(value: string | number): string | number;
40
+ declare function validateAndClean(previousValue: string, nextText: string): string;
41
+ declare function validateNumber(value: string | number): ValidateReturn;
42
+ //#endregion
43
+ //#region src/numbers/scientific-notation/scientific-notation.d.ts
44
+ declare const EXP_NOTATION_RE: RegExp;
45
+ //#endregion
46
+ export { getAltUnitsListByQuantity as C, showAltUnitsList as D, label as E, unitFromKey as O, withUnit as S, getUnitsForQuantity as T, getValue as _, altUnitsList as a, split as b, convertAndGetValue as c, to as d, toBase as f, getUnit as g, SEPARATOR as h, validateNumber as i, unitFromQuantity as k, convertAndGetValueStrict as l, unumWithUnit as m, checkAndCleanDecimalComma as n, roundNumberWithLabel as o, unum as p, validateAndClean as r, convertTable as s, EXP_NOTATION_RE as t, convertSamePrecision as u, isEmptyValueWithUnit as v, getQuantities as w, withPrettyUnitLabel as x, isValueWithUnit as y };
47
+ //# sourceMappingURL=units.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units.d.cts","names":[],"sources":["../../src/units/unit-catalog.ts","../../src/units/unit-string.ts","../../src/units/conversion.ts","../../src/units/table-conversion.ts","../../src/units/formatting.ts","../../src/units/validation.ts","../../src/numbers/scientific-notation/scientific-notation.ts"],"mappings":";;;iBAIgB,gBAAA,CAAiB,WAAA;AAAA,iBAKjB,mBAAA,CAAoB,QAAA;AAAA,iBAKpB,aAAA,CAAA;AAAA,iBAKA,KAAA,CAAM,OAAA;AAAA,iBAKN,WAAA,CAAY,QAAA;AAAA,iBAKZ,gBAAA,CAAiB,QAAA;AAAA,iBAKjB,yBAAA,CAA0B,QAAA,WAAmB,gBAAA;;;cC/BhD,SAAA;AAAA,iBAKG,oBAAA,CAAqB,KAAA;AAAA,iBAKrB,KAAA,CAAM,aAAA;AAAA,iBA2BN,QAAA,CAAS,aAAA;AAAA,iBAKT,OAAA,CAAQ,aAAA;AAAA,iBAKR,eAAA,CAAgB,KAAA;AAAA,iBAShB,QAAA,CAAS,KAAA,sCAA2C,IAAA,iBAAqB,YAAA;AAAA,iBAezE,mBAAA,CAAoB,cAAA;;;iBChEpB,EAAA,CAAG,KAAA,mBAAwB,QAAA,UAAkB,MAAA;AAAA,iBA+D7C,IAAA,CAAK,aAAA,mBAAgC,MAAA,UAAgB,QAAA;AAAA,iBAoDrD,kBAAA,CAAmB,KAAA,mBAAwB,MAAA,UAAgB,QAAA;AAAA,iBAK3D,wBAAA,CACd,KAAA,0BACA,MAAA,UACA,QAAA;AAAA,iBAcc,MAAA,CAAO,KAAA,UAAe,QAAA;AAAA,iBAOtB,YAAA,CAAa,KAAA,mBAAwB,MAAA,UAAgB,QAAA;AAAA,iBAKrD,oBAAA,CAAqB,aAAA,mBAAgC,MAAA,UAAgB,MAAA;;;iBC3JrE,YAAA,CACd,SAAA,OACA,KAAA,OACA,cAAA,OACA,mBAAA;;;iBCAc,oBAAA,CAAqB,KAAA,UAAe,cAAA;AAAA,iBAKpC,YAAA,CAAa,KAAA,UAAe,QAAA;;;iBCL5B,yBAAA,CAA0B,KAAA;AAAA,iBAa1B,gBAAA,CAAiB,aAAA,UAAuB,QAAA;AAAA,iBAuBxC,cAAA,CAAe,KAAA,oBAAyB,cAAA;;;cC1C3C,eAAA,EAAe,MAAA"}
@@ -0,0 +1,47 @@
1
+ import { r as ValidateReturn, t as AltUnitWithLabel } from "./types.js";
2
+
3
+ //#region src/units/unit-catalog.d.ts
4
+ declare function showAltUnitsList(quantityKey: string): string[] | undefined;
5
+ declare function getUnitsForQuantity(quantity: string): string[] | undefined;
6
+ declare function getQuantities(): string[] | undefined;
7
+ declare function label(unitKey: string): string | undefined;
8
+ declare function unitFromKey(quantity: string): string | undefined;
9
+ declare function unitFromQuantity(quantity: string): string | undefined;
10
+ declare function getAltUnitsListByQuantity(quantity: string): AltUnitWithLabel[] | undefined;
11
+ //#endregion
12
+ //#region src/units/unit-string.d.ts
13
+ declare const SEPARATOR = "|";
14
+ declare function isEmptyValueWithUnit(value: string | number): boolean;
15
+ declare function split(valueWithUnit: string): string[];
16
+ declare function getValue(valueWithUnit: string): string;
17
+ declare function getUnit(valueWithUnit: string): string;
18
+ declare function isValueWithUnit(value: string | number): boolean;
19
+ declare function withUnit(value: string | number | null | undefined, unit: string | null, defaultValue?: string): string;
20
+ declare function withPrettyUnitLabel(valueWithUnits: string): string;
21
+ //#endregion
22
+ //#region src/units/conversion.d.ts
23
+ declare function to(value: string | number, fromUnit: string, toUnit: string): number;
24
+ declare function unum(valueWithUnit: string | number, toUnit: string, fromUnit?: string): number;
25
+ declare function convertAndGetValue(value: string | number, toUnit: string, fromUnit?: string): number;
26
+ declare function convertAndGetValueStrict(value: string | number | null, toUnit: string, fromUnit?: string): string | number | null;
27
+ declare function toBase(value: string, quantity: string): number;
28
+ declare function unumWithUnit(value: string | number, toUnit: string, fromUnit?: string): string;
29
+ declare function convertSamePrecision(valueWithUnit: string | number, toUnit: string, digits?: number): string;
30
+ //#endregion
31
+ //#region src/units/table-conversion.d.ts
32
+ declare function convertTable(toUnitRow: any, table: any, defaultUnitRow?: [], removeFinalUnitsRow?: boolean): string | number[][];
33
+ //#endregion
34
+ //#region src/units/formatting.d.ts
35
+ declare function roundNumberWithLabel(value: string, numberOfDigits?: number): string;
36
+ declare function altUnitsList(value: string, quantity: string): (string | undefined)[][];
37
+ //#endregion
38
+ //#region src/units/validation.d.ts
39
+ declare function checkAndCleanDecimalComma(value: string | number): string | number;
40
+ declare function validateAndClean(previousValue: string, nextText: string): string;
41
+ declare function validateNumber(value: string | number): ValidateReturn;
42
+ //#endregion
43
+ //#region src/numbers/scientific-notation/scientific-notation.d.ts
44
+ declare const EXP_NOTATION_RE: RegExp;
45
+ //#endregion
46
+ export { getAltUnitsListByQuantity as C, showAltUnitsList as D, label as E, unitFromKey as O, withUnit as S, getUnitsForQuantity as T, getValue as _, altUnitsList as a, split as b, convertAndGetValue as c, to as d, toBase as f, getUnit as g, SEPARATOR as h, validateNumber as i, unitFromQuantity as k, convertAndGetValueStrict as l, unumWithUnit as m, checkAndCleanDecimalComma as n, roundNumberWithLabel as o, unum as p, validateAndClean as r, convertTable as s, EXP_NOTATION_RE as t, convertSamePrecision as u, isEmptyValueWithUnit as v, getQuantities as w, withPrettyUnitLabel as x, isValueWithUnit as y };
47
+ //# sourceMappingURL=units.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units.d.ts","names":[],"sources":["../../src/units/unit-catalog.ts","../../src/units/unit-string.ts","../../src/units/conversion.ts","../../src/units/table-conversion.ts","../../src/units/formatting.ts","../../src/units/validation.ts","../../src/numbers/scientific-notation/scientific-notation.ts"],"mappings":";;;iBAIgB,gBAAA,CAAiB,WAAA;AAAA,iBAKjB,mBAAA,CAAoB,QAAA;AAAA,iBAKpB,aAAA,CAAA;AAAA,iBAKA,KAAA,CAAM,OAAA;AAAA,iBAKN,WAAA,CAAY,QAAA;AAAA,iBAKZ,gBAAA,CAAiB,QAAA;AAAA,iBAKjB,yBAAA,CAA0B,QAAA,WAAmB,gBAAA;;;cC/BhD,SAAA;AAAA,iBAKG,oBAAA,CAAqB,KAAA;AAAA,iBAKrB,KAAA,CAAM,aAAA;AAAA,iBA2BN,QAAA,CAAS,aAAA;AAAA,iBAKT,OAAA,CAAQ,aAAA;AAAA,iBAKR,eAAA,CAAgB,KAAA;AAAA,iBAShB,QAAA,CAAS,KAAA,sCAA2C,IAAA,iBAAqB,YAAA;AAAA,iBAezE,mBAAA,CAAoB,cAAA;;;iBChEpB,EAAA,CAAG,KAAA,mBAAwB,QAAA,UAAkB,MAAA;AAAA,iBA+D7C,IAAA,CAAK,aAAA,mBAAgC,MAAA,UAAgB,QAAA;AAAA,iBAoDrD,kBAAA,CAAmB,KAAA,mBAAwB,MAAA,UAAgB,QAAA;AAAA,iBAK3D,wBAAA,CACd,KAAA,0BACA,MAAA,UACA,QAAA;AAAA,iBAcc,MAAA,CAAO,KAAA,UAAe,QAAA;AAAA,iBAOtB,YAAA,CAAa,KAAA,mBAAwB,MAAA,UAAgB,QAAA;AAAA,iBAKrD,oBAAA,CAAqB,aAAA,mBAAgC,MAAA,UAAgB,MAAA;;;iBC3JrE,YAAA,CACd,SAAA,OACA,KAAA,OACA,cAAA,OACA,mBAAA;;;iBCAc,oBAAA,CAAqB,KAAA,UAAe,cAAA;AAAA,iBAKpC,YAAA,CAAa,KAAA,UAAe,QAAA;;;iBCL5B,yBAAA,CAA0B,KAAA;AAAA,iBAa1B,gBAAA,CAAiB,aAAA,UAAuB,QAAA;AAAA,iBAuBxC,cAAA,CAAe,KAAA,oBAAyB,cAAA;;;cC1C3C,eAAA,EAAe,MAAA"}
@@ -0,0 +1,38 @@
1
+ import { H as split, Q as label, R as getUnit, W as withUnit, h as displayNumber, nt as ALT_UNITS, o as unum, r as convertSamePrecision, tt as unitFromQuantity, v as round } from "./conversion.js";
2
+ //#region src/units/table-conversion.ts
3
+ /** Converts every numeric column in a table to a requested unit row. */
4
+ function convertTable(toUnitRow, table, defaultUnitRow, removeFinalUnitsRow = false) {
5
+ if (!table || !table.length || !table[0].length) return table;
6
+ if (!toUnitRow) toUnitRow = table[0];
7
+ if (!defaultUnitRow) defaultUnitRow = toUnitRow;
8
+ const firstCell = table[0][0];
9
+ const firstCellParts = firstCell && split(`${firstCell}`);
10
+ const tableHasUnits = !(firstCellParts && firstCellParts[0] && isNaN(firstCellParts[1])) && isNaN(table[0][0]);
11
+ let rowIndex = tableHasUnits ? 1 : 0;
12
+ const fromUnitRow = tableHasUnits ? table[0] : defaultUnitRow;
13
+ const convertedTable = [toUnitRow];
14
+ for (; rowIndex < table.length; rowIndex += 1) {
15
+ const convertedColumns = Array(toUnitRow.length);
16
+ const row = table[rowIndex];
17
+ for (let unitIndex = 0; unitIndex < convertedColumns.length; unitIndex += 1) convertedColumns[unitIndex] = toUnitRow[unitIndex] && row[unitIndex] ? unum(row[unitIndex], toUnitRow[unitIndex], fromUnitRow[unitIndex]) : row[unitIndex];
18
+ convertedTable.push(convertedColumns);
19
+ }
20
+ if (removeFinalUnitsRow) convertedTable.shift();
21
+ return convertedTable;
22
+ }
23
+ //#endregion
24
+ //#region src/units/formatting.ts
25
+ /** Rounds a unit string and replaces the unit key with its display label. */
26
+ function roundNumberWithLabel(value, numberOfDigits = 2) {
27
+ return displayNumber(round(value, numberOfDigits), { withUnit: true });
28
+ }
29
+ /** Returns a value converted to every unit configured for a quantity. */
30
+ function altUnitsList(value, quantity) {
31
+ let valueWithUnit = value;
32
+ if (!getUnit(value)) valueWithUnit = withUnit(value, unitFromQuantity(quantity) ?? "");
33
+ return (ALT_UNITS[quantity] ?? []).map((unit) => [...split(convertSamePrecision(valueWithUnit, unit)), label(unit)]);
34
+ }
35
+ //#endregion
36
+ export { roundNumberWithLabel as n, convertTable as r, altUnitsList as t };
37
+
38
+ //# sourceMappingURL=units.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units.js","names":[],"sources":["../../src/units/table-conversion.ts","../../src/units/formatting.ts"],"sourcesContent":["import { unum } from './conversion.ts';\nimport { split } from './unit-string.ts';\n\n/** Converts every numeric column in a table to a requested unit row. */\nexport function convertTable(\n toUnitRow: any,\n table: any,\n defaultUnitRow?: [],\n removeFinalUnitsRow = false,\n): string | number[][] {\n if (!table || !table.length || !table[0].length) {\n return table;\n }\n if (!toUnitRow) {\n toUnitRow = table[0];\n }\n if (!defaultUnitRow) {\n defaultUnitRow = toUnitRow;\n }\n\n const firstCell = table[0][0];\n const firstCellParts = firstCell && split(`${firstCell}`);\n const unitNumber = firstCellParts && firstCellParts[0] && isNaN(firstCellParts[1] as unknown as number);\n const tableHasUnits = !unitNumber && isNaN(table[0][0] as unknown as number);\n let rowIndex = tableHasUnits ? 1 : 0;\n const fromUnitRow = tableHasUnits ? table[0] : defaultUnitRow;\n const convertedTable = [toUnitRow];\n for (; rowIndex < table.length; rowIndex += 1) {\n const convertedColumns = Array(toUnitRow.length);\n const row = table[rowIndex];\n for (let unitIndex = 0; unitIndex < convertedColumns.length; unitIndex += 1) {\n convertedColumns[unitIndex] =\n toUnitRow[unitIndex] && row[unitIndex]\n ? unum(row[unitIndex], toUnitRow[unitIndex], fromUnitRow[unitIndex] as string)\n : row[unitIndex];\n }\n convertedTable.push(convertedColumns);\n }\n if (removeFinalUnitsRow) {\n convertedTable.shift();\n }\n return convertedTable;\n}\n","import { ALT_UNITS } from './constants.ts';\nimport { displayNumber } from '../numbers/format/display-number.ts';\nimport { round } from '../numbers/rounding/rounding.ts';\nimport { convertSamePrecision } from './conversion.ts';\nimport { label, unitFromQuantity } from './unit-catalog.ts';\nimport { getUnit, split, withUnit } from './unit-string.ts';\n\n/** Rounds a unit string and replaces the unit key with its display label. */\nexport function roundNumberWithLabel(value: string, numberOfDigits = 2): string {\n return displayNumber(round(value, numberOfDigits), { withUnit: true });\n}\n\n/** Returns a value converted to every unit configured for a quantity. */\nexport function altUnitsList(value: string, quantity: string): (string | undefined)[][] {\n let valueWithUnit = value;\n if (!getUnit(value)) {\n valueWithUnit = withUnit(value, unitFromQuantity(quantity) ?? '');\n }\n const alternativeUnits = ALT_UNITS[quantity] ?? [];\n return alternativeUnits.map((unit: string) => [...split(convertSamePrecision(valueWithUnit, unit)), label(unit)]);\n}\n"],"mappings":";;;AAIA,SAAgB,aACd,WACA,OACA,gBACA,sBAAsB,OACD;AACrB,KAAI,CAAC,SAAS,CAAC,MAAM,UAAU,CAAC,MAAM,GAAG,OACvC,QAAO;AAET,KAAI,CAAC,UACH,aAAY,MAAM;AAEpB,KAAI,CAAC,eACH,kBAAiB;CAGnB,MAAM,YAAY,MAAM,GAAG;CAC3B,MAAM,iBAAiB,aAAa,MAAM,GAAG,YAAY;CAEzD,MAAM,gBAAgB,EADH,kBAAkB,eAAe,MAAM,MAAM,eAAe,GAAwB,KAClE,MAAM,MAAM,GAAG,GAAwB;CAC5E,IAAI,WAAW,gBAAgB,IAAI;CACnC,MAAM,cAAc,gBAAgB,MAAM,KAAK;CAC/C,MAAM,iBAAiB,CAAC,UAAU;AAClC,QAAO,WAAW,MAAM,QAAQ,YAAY,GAAG;EAC7C,MAAM,mBAAmB,MAAM,UAAU,OAAO;EAChD,MAAM,MAAM,MAAM;AAClB,OAAK,IAAI,YAAY,GAAG,YAAY,iBAAiB,QAAQ,aAAa,EACxE,kBAAiB,aACf,UAAU,cAAc,IAAI,aACxB,KAAK,IAAI,YAAY,UAAU,YAAY,YAAY,WAAqB,GAC5E,IAAI;AAEZ,iBAAe,KAAK,iBAAiB;;AAEvC,KAAI,oBACF,gBAAe,OAAO;AAExB,QAAO;;;;;ACjCT,SAAgB,qBAAqB,OAAe,iBAAiB,GAAW;AAC9E,QAAO,cAAc,MAAM,OAAO,eAAe,EAAE,EAAE,UAAU,MAAM,CAAC;;;AAIxE,SAAgB,aAAa,OAAe,UAA4C;CACtF,IAAI,gBAAgB;AACpB,KAAI,CAAC,QAAQ,MAAM,CACjB,iBAAgB,SAAS,OAAO,iBAAiB,SAAS,IAAI,GAAG;AAGnE,SADyB,UAAU,aAAa,EAAE,EAC1B,KAAK,SAAiB,CAAC,GAAG,MAAM,qBAAqB,eAAe,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC,CAAC"}
package/dist/index.cjs CHANGED
@@ -1,6 +1,27 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_units = require("./units2.cjs");
3
- //#region src/rounding/cosmetic-rounding.ts
2
+ const require_conversion = require("./chunks/conversion.cjs");
3
+ const require_units = require("./chunks/units.cjs");
4
+ //#region src/numbers/rounding/number-digits.ts
5
+ /**
6
+ * Calculates a useful decimal precision for small values used by legacy rounding.
7
+ *
8
+ * @deprecated Use `roundByMagnitude` or another current rounding function instead.
9
+ */
10
+ function getNumberOfDigitsToShow(value, maxNumberOfDigits = 20) {
11
+ const defaultDigits = Math.min(4, maxNumberOfDigits);
12
+ let digits = defaultDigits;
13
+ if (typeof value !== "number") return defaultDigits;
14
+ const valueString = String(value);
15
+ if (/-?[0-9.,]*[Ee]-?[0-9]+/.test(valueString)) {
16
+ while (Math.abs(value) * 10 ** digits < 1 && digits < maxNumberOfDigits) digits += 1;
17
+ return Math.min(digits + (defaultDigits - 1), maxNumberOfDigits);
18
+ }
19
+ if (value > 1 || value < -1) return defaultDigits;
20
+ for (let index = 2; index < valueString.length; index += 1) if (valueString[index] !== "0") return Math.min(maxNumberOfDigits, digits + index - 2);
21
+ return digits;
22
+ }
23
+ //#endregion
24
+ //#region src/numbers/rounding/cosmetic-rounding.ts
4
25
  const COSMETIC_ROUNDING_DEFAULT_PRECISION = 14;
5
26
  /**
6
27
  * Applies display-only rounding to remove floating-point conversion noise.
@@ -19,80 +40,80 @@ const COSMETIC_ROUNDING_DEFAULT_PRECISION = 14;
19
40
  * roundCosmetic('9750.000000000004|m') -> '9750|m'
20
41
  */
21
42
  const roundCosmetic = (value) => {
22
- if (require_units.isScientificStringNum(value)) return value;
23
- return require_units.roundToPrecision(value, COSMETIC_ROUNDING_DEFAULT_PRECISION);
43
+ if (require_conversion.isScientificStringNum(value)) return value;
44
+ return require_conversion.roundToPrecision(value, COSMETIC_ROUNDING_DEFAULT_PRECISION);
24
45
  };
25
46
  //#endregion
26
47
  //#region src/index.ts
27
48
  /* istanbul ignore file */
28
49
  //#endregion
29
- exports.ALT_UNITS = require_units.ALT_UNITS;
30
- exports.DEPRECATED_UNITS = require_units.DEPRECATED_UNITS;
31
- exports.INTERMEDIATE_CONVERSIONS = require_units.INTERMEDIATE_CONVERSIONS;
32
- exports.KNOWN_CONVERSIONS = require_units.KNOWN_CONVERSIONS;
33
- exports.KNOWN_UNITS = require_units.KNOWN_UNITS;
34
- exports.LABELS = require_units.LABELS;
35
- exports.QUANTITIES_DESCRIPTION = require_units.QUANTITIES_DESCRIPTION;
36
- exports.UNITS_DESCRIPTION = require_units.UNITS_DESCRIPTION;
37
- exports.UNIT_ALIASES = require_units.UNIT_ALIASES;
38
- exports.UNIT_FROM_KEY = require_units.UNIT_FROM_KEY;
39
- exports.allNumbers = require_units.allNumbers;
50
+ exports.ALT_UNITS = require_conversion.ALT_UNITS;
51
+ exports.DEPRECATED_UNITS = require_conversion.DEPRECATED_UNITS;
52
+ exports.INTERMEDIATE_CONVERSIONS = require_conversion.INTERMEDIATE_CONVERSIONS;
53
+ exports.KNOWN_CONVERSIONS = require_conversion.KNOWN_CONVERSIONS;
54
+ exports.KNOWN_UNITS = require_conversion.KNOWN_UNITS;
55
+ exports.LABELS = require_conversion.LABELS;
56
+ exports.QUANTITIES_DESCRIPTION = require_conversion.QUANTITIES_DESCRIPTION;
57
+ exports.UNITS_DESCRIPTION = require_conversion.UNITS_DESCRIPTION;
58
+ exports.UNIT_ALIASES = require_conversion.UNIT_ALIASES;
59
+ exports.UNIT_FROM_KEY = require_conversion.UNIT_FROM_KEY;
60
+ exports.allNumbers = require_conversion.allNumbers;
40
61
  exports.altUnitsList = require_units.altUnitsList;
41
- exports.asFraction = require_units.asFraction;
42
- exports.charCount = require_units.charCount;
43
- exports.checkAndCleanDecimalComma = require_units.checkAndCleanDecimalComma;
44
- exports.cleanNum = require_units.cleanNum;
45
- exports.cleanNumStr = require_units.cleanNumStr;
46
- exports.convertAndGetValue = require_units.convertAndGetValue;
47
- exports.convertAndGetValueStrict = require_units.convertAndGetValueStrict;
48
- exports.convertSamePrecision = require_units.convertSamePrecision;
62
+ exports.asFraction = require_conversion.asFraction;
63
+ exports.charCount = require_conversion.charCount;
64
+ exports.checkAndCleanDecimalComma = require_conversion.checkAndCleanDecimalComma;
65
+ exports.cleanNum = require_conversion.cleanNum;
66
+ exports.cleanNumStr = require_conversion.cleanNumStr;
67
+ exports.convertAndGetValue = require_conversion.convertAndGetValue;
68
+ exports.convertAndGetValueStrict = require_conversion.convertAndGetValueStrict;
69
+ exports.convertSamePrecision = require_conversion.convertSamePrecision;
49
70
  exports.convertTable = require_units.convertTable;
50
- exports.displayNumber = require_units.displayNumber;
51
- exports.displayNumberToFixed = require_units.displayNumberToFixed;
52
- exports.formatNumber = require_units.formatNumber;
53
- exports.fraction = require_units.fraction;
54
- exports.getAltUnitsListByQuantity = require_units.getAltUnitsListByQuantity;
55
- exports.getNumberOfDigitsToShow = require_units.getNumberOfDigitsToShow;
56
- exports.getQuantities = require_units.getQuantities;
57
- exports.getUnit = require_units.getUnit;
58
- exports.getUnitsForQuantity = require_units.getUnitsForQuantity;
59
- exports.getValue = require_units.getValue;
60
- exports.isCloseTo = require_units.isCloseTo;
61
- exports.isCloseToOrGreaterThan = require_units.isCloseToOrGreaterThan;
62
- exports.isCloseToOrLessThan = require_units.isCloseToOrLessThan;
63
- exports.isDeepCloseTo = require_units.isDeepCloseTo;
64
- exports.isEmptyValueWithUnit = require_units.isEmptyValueWithUnit;
65
- exports.isFraction = require_units.isFraction;
66
- exports.isNonNumerical = require_units.isNonNumerical;
67
- exports.isNumeric = require_units.isNumeric;
68
- exports.isScientificStringNum = require_units.isScientificStringNum;
69
- exports.isValidNum = require_units.isValidNum;
70
- exports.isValueWithUnit = require_units.isValueWithUnit;
71
- exports.label = require_units.label;
72
- exports.numFraction = require_units.numFraction;
73
- exports.round = require_units.round;
74
- exports.roundByMagnitude = require_units.roundByMagnitude;
75
- exports.roundByMagnitudeToFixed = require_units.roundByMagnitudeToFixed;
76
- exports.roundByRange = require_units.roundByRange;
71
+ exports.displayNumber = require_conversion.displayNumber;
72
+ exports.displayNumberToFixed = require_conversion.displayNumberToFixed;
73
+ exports.formatNumber = require_conversion.formatNumber;
74
+ exports.fraction = require_conversion.fraction;
75
+ exports.getAltUnitsListByQuantity = require_conversion.getAltUnitsListByQuantity;
76
+ exports.getNumberOfDigitsToShow = getNumberOfDigitsToShow;
77
+ exports.getQuantities = require_conversion.getQuantities;
78
+ exports.getUnit = require_conversion.getUnit;
79
+ exports.getUnitsForQuantity = require_conversion.getUnitsForQuantity;
80
+ exports.getValue = require_conversion.getValue;
81
+ exports.isCloseTo = require_conversion.isCloseTo;
82
+ exports.isCloseToOrGreaterThan = require_conversion.isCloseToOrGreaterThan;
83
+ exports.isCloseToOrLessThan = require_conversion.isCloseToOrLessThan;
84
+ exports.isDeepCloseTo = require_conversion.isDeepCloseTo;
85
+ exports.isEmptyValueWithUnit = require_conversion.isEmptyValueWithUnit;
86
+ exports.isFraction = require_conversion.isFraction;
87
+ exports.isNonNumerical = require_conversion.isNonNumerical;
88
+ exports.isNumeric = require_conversion.isNumeric;
89
+ exports.isScientificStringNum = require_conversion.isScientificStringNum;
90
+ exports.isValidNum = require_conversion.isValidNum;
91
+ exports.isValueWithUnit = require_conversion.isValueWithUnit;
92
+ exports.label = require_conversion.label;
93
+ exports.numFraction = require_conversion.numFraction;
94
+ exports.round = require_conversion.round;
95
+ exports.roundByMagnitude = require_conversion.roundByMagnitude;
96
+ exports.roundByMagnitudeToFixed = require_conversion.roundByMagnitudeToFixed;
97
+ exports.roundByRange = require_conversion.roundByRange;
77
98
  exports.roundCosmetic = roundCosmetic;
78
99
  exports.roundNumberWithLabel = require_units.roundNumberWithLabel;
79
- exports.roundToDecimalPrecision = require_units.roundToDecimalPrecision;
80
- exports.roundToFixed = require_units.roundToFixed;
81
- exports.roundToPrecision = require_units.roundToPrecision;
82
- exports.showAltUnitsList = require_units.showAltUnitsList;
83
- exports.split = require_units.split;
84
- exports.stripLeadingZeros = require_units.stripLeadingZeros;
85
- exports.to = require_units.to;
86
- exports.toBase = require_units.toBase;
87
- exports.toNum = require_units.toNum;
88
- exports.toString = require_units.toString;
89
- exports.unitFromKey = require_units.unitFromKey;
90
- exports.unitFromQuantity = require_units.unitFromQuantity;
91
- exports.unum = require_units.unum;
92
- exports.unumWithUnit = require_units.unumWithUnit;
93
- exports.validateAndClean = require_units.validateAndClean;
94
- exports.validateNumber = require_units.validateNumber;
95
- exports.withPrettyUnitLabel = require_units.withPrettyUnitLabel;
96
- exports.withUnit = require_units.withUnit;
100
+ exports.roundToDecimalPrecision = require_conversion.roundToDecimalPrecision;
101
+ exports.roundToFixed = require_conversion.roundToFixed;
102
+ exports.roundToPrecision = require_conversion.roundToPrecision;
103
+ exports.showAltUnitsList = require_conversion.showAltUnitsList;
104
+ exports.split = require_conversion.split;
105
+ exports.stripLeadingZeros = require_conversion.stripLeadingZeros;
106
+ exports.to = require_conversion.to;
107
+ exports.toBase = require_conversion.toBase;
108
+ exports.toNum = require_conversion.toNum;
109
+ exports.toString = require_conversion.toString;
110
+ exports.unitFromKey = require_conversion.unitFromKey;
111
+ exports.unitFromQuantity = require_conversion.unitFromQuantity;
112
+ exports.unum = require_conversion.unum;
113
+ exports.unumWithUnit = require_conversion.unumWithUnit;
114
+ exports.validateAndClean = require_conversion.validateAndClean;
115
+ exports.validateNumber = require_conversion.validateNumber;
116
+ exports.withPrettyUnitLabel = require_conversion.withPrettyUnitLabel;
117
+ exports.withUnit = require_conversion.withUnit;
97
118
 
98
119
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
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>(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';\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 { toNum, toString, isValidNum, isScientificStringNum } from './numbers/numbers.ts';\n\nimport { displayNumber, displayNumberToFixed } 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 { isCloseTo, isDeepCloseTo, isCloseToOrLessThan, isCloseToOrGreaterThan } 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,iBAAgD,UAAwB;AACnF,KAAIA,cAAAA,sBAAsB,MAAM,CAC9B,QAAO;AAGT,QAAOC,cAAAA,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"],"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,7 +1,7 @@
1
- import { altUnitsList, checkAndCleanDecimalComma, convertAndGetValue, convertAndGetValueStrict, convertSamePrecision, convertTable, getAltUnitsListByQuantity, getQuantities, getUnit, getUnitsForQuantity, getValue, isValueWithUnit, label, roundNumberWithLabel, showAltUnitsList, split, to, toBase, unitFromKey, unitFromQuantity, unum, unumWithUnit, validateAndClean, validateNumber, withPrettyUnitLabel, withUnit } from "./units.cjs";
1
+ 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, 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, u as convertSamePrecision, v as isEmptyValueWithUnit, w as getQuantities, x as withPrettyUnitLabel, y as isValueWithUnit } from "./chunks/units.cjs";
2
2
  import { isScientificStringNum, isValidNum, toNum, toString } from "./numbers/numbers.cjs";
3
3
 
4
- //#region src/constants.d.ts
4
+ //#region src/units/constants.d.ts
5
5
  declare const LABELS: Record<string, string>;
6
6
  declare const ALT_UNITS: Record<string, string[]>;
7
7
  declare const UNIT_FROM_KEY: Record<string, string>;
@@ -90,7 +90,6 @@ declare const QUANTITIES_DESCRIPTION: {
90
90
  Entalphy: string;
91
91
  shearStress: string;
92
92
  volumeGradient: string;
93
- wellheadGrowthMovement: string;
94
93
  deg: string;
95
94
  dls: string;
96
95
  wgrad: string;
@@ -318,23 +317,27 @@ declare const UNITS_DESCRIPTION: {
318
317
  g: string;
319
318
  };
320
319
  //#endregion
321
- //#region src/utils.d.ts
322
- declare function isEmptyValueWithUnit(val: string | number): boolean;
320
+ //#region src/numbers/fractions/fractions.d.ts
323
321
  declare const isFraction: (value: unknown) => boolean;
324
- declare function isNumeric(v: unknown): boolean;
325
- declare function allNumbers(arr: (number | string)[]): boolean;
326
- declare const formatNumber: (number: number | string | undefined | null) => string;
327
- declare function charCount(chr: string | number, str: string): number;
328
- declare function getNumberOfDigitsToShow(num: number | string, maxNumDigits?: number): number;
329
- declare function fraction(str: any): number | typeof Infinity | typeof NaN;
330
- declare function asFraction(str: number | string): string;
331
- declare function numFraction(str: any): any;
332
- declare function cleanNumStr(str: string | number): string;
322
+ declare function fraction(value: any): number | typeof Infinity | typeof NaN;
323
+ declare function asFraction(value: number | string): string;
324
+ declare function numFraction(value: any): any;
325
+ //#endregion
326
+ //#region src/numbers/parsing/number-input.d.ts
327
+ declare function charCount(character: string | number, value: string): number;
328
+ declare function cleanNumStr(value: string | number): string;
333
329
  declare const stripLeadingZeros: (value: string) => string;
334
- declare function cleanNum(str: string | number): number;
330
+ declare function cleanNum(value: string | number): number;
331
+ //#endregion
332
+ //#region src/numbers/predicates.d.ts
333
+ declare function isNumeric(value: unknown): boolean;
335
334
  declare const isNonNumerical: (value: any) => boolean;
335
+ declare function allNumbers(values: (number | string)[]): boolean;
336
336
  //#endregion
337
- //#region src/numbers/display-number.d.ts
337
+ //#region src/numbers/rounding/number-digits.d.ts
338
+ declare function getNumberOfDigitsToShow(value: number | string, maxNumberOfDigits?: number): number;
339
+ //#endregion
340
+ //#region src/numbers/format/display-number.d.ts
338
341
  type NumberDisplayOptions = {
339
342
  scientific?: 'auto' | boolean;
340
343
  eNotation?: boolean;
@@ -347,8 +350,9 @@ type NumberDisplayOptions = {
347
350
  };
348
351
  declare const displayNumber: <Value extends number | string | null | undefined>(value: Value, options?: NumberDisplayOptions) => string;
349
352
  declare const displayNumberToFixed: <Value extends string | null | undefined>(value: Value, options?: NumberDisplayOptions) => string;
353
+ declare const formatNumber: (number: number | string | undefined | null) => string;
350
354
  //#endregion
351
- //#region src/rounding/rounding.d.ts
355
+ //#region src/numbers/rounding/rounding.d.ts
352
356
  declare const round: <Value extends number | string | null | undefined>(value: Value, n?: number) => Value;
353
357
  declare const roundToPrecision: <Value extends number | string | null | undefined>(value: Value, n?: number) => Value;
354
358
  declare const roundToDecimalPrecision: <Value extends number | string | null | undefined>(value: Value, n?: number) => Value;
@@ -357,10 +361,10 @@ declare const roundByMagnitudeToFixed: <Value extends number | string | null | u
357
361
  declare const roundByRange: <Value extends number | string | null | undefined>(value: Value, min: number, max: number, n?: number) => Value;
358
362
  declare const roundToFixed: <Value extends number | string | null | undefined>(value: Value, n?: number) => Value;
359
363
  //#endregion
360
- //#region src/rounding/cosmetic-rounding.d.ts
364
+ //#region src/numbers/rounding/cosmetic-rounding.d.ts
361
365
  declare const roundCosmetic: <Value extends number | string>(value: Value) => Value;
362
366
  //#endregion
363
- //#region src/comparison/comparison.d.ts
367
+ //#region src/numbers/comparison/comparison.d.ts
364
368
  type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
365
369
  type XOR<T, U> = T | U extends Record<string, unknown> ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
366
370
  type toleranceType = XOR<{
@@ -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,cAiIX,aAAA,EAAe,MAAA;AAAA,cA+Gf,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+FA,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCruCG,oBAAA,CAAqB,GAAA;AAAA,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AA,EAAO,KAAA,KAAQ,KAAA;;;KCdvE,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,cAyDE,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"}
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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AAA;AAAA,cAmCU,uBAAA,qDACX,KAAA,EAAO,KAAA,EACP,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,7 +1,7 @@
1
- import { altUnitsList, checkAndCleanDecimalComma, convertAndGetValue, convertAndGetValueStrict, convertSamePrecision, convertTable, getAltUnitsListByQuantity, getQuantities, getUnit, getUnitsForQuantity, getValue, isValueWithUnit, label, roundNumberWithLabel, showAltUnitsList, split, to, toBase, unitFromKey, unitFromQuantity, unum, unumWithUnit, validateAndClean, validateNumber, withPrettyUnitLabel, withUnit } from "./units.js";
1
+ 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, 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, u as convertSamePrecision, v as isEmptyValueWithUnit, w as getQuantities, x as withPrettyUnitLabel, y as isValueWithUnit } from "./chunks/units.js";
2
2
  import { isScientificStringNum, isValidNum, toNum, toString } from "./numbers/numbers.js";
3
3
 
4
- //#region src/constants.d.ts
4
+ //#region src/units/constants.d.ts
5
5
  declare const LABELS: Record<string, string>;
6
6
  declare const ALT_UNITS: Record<string, string[]>;
7
7
  declare const UNIT_FROM_KEY: Record<string, string>;
@@ -90,7 +90,6 @@ declare const QUANTITIES_DESCRIPTION: {
90
90
  Entalphy: string;
91
91
  shearStress: string;
92
92
  volumeGradient: string;
93
- wellheadGrowthMovement: string;
94
93
  deg: string;
95
94
  dls: string;
96
95
  wgrad: string;
@@ -318,23 +317,27 @@ declare const UNITS_DESCRIPTION: {
318
317
  g: string;
319
318
  };
320
319
  //#endregion
321
- //#region src/utils.d.ts
322
- declare function isEmptyValueWithUnit(val: string | number): boolean;
320
+ //#region src/numbers/fractions/fractions.d.ts
323
321
  declare const isFraction: (value: unknown) => boolean;
324
- declare function isNumeric(v: unknown): boolean;
325
- declare function allNumbers(arr: (number | string)[]): boolean;
326
- declare const formatNumber: (number: number | string | undefined | null) => string;
327
- declare function charCount(chr: string | number, str: string): number;
328
- declare function getNumberOfDigitsToShow(num: number | string, maxNumDigits?: number): number;
329
- declare function fraction(str: any): number | typeof Infinity | typeof NaN;
330
- declare function asFraction(str: number | string): string;
331
- declare function numFraction(str: any): any;
332
- declare function cleanNumStr(str: string | number): string;
322
+ declare function fraction(value: any): number | typeof Infinity | typeof NaN;
323
+ declare function asFraction(value: number | string): string;
324
+ declare function numFraction(value: any): any;
325
+ //#endregion
326
+ //#region src/numbers/parsing/number-input.d.ts
327
+ declare function charCount(character: string | number, value: string): number;
328
+ declare function cleanNumStr(value: string | number): string;
333
329
  declare const stripLeadingZeros: (value: string) => string;
334
- declare function cleanNum(str: string | number): number;
330
+ declare function cleanNum(value: string | number): number;
331
+ //#endregion
332
+ //#region src/numbers/predicates.d.ts
333
+ declare function isNumeric(value: unknown): boolean;
335
334
  declare const isNonNumerical: (value: any) => boolean;
335
+ declare function allNumbers(values: (number | string)[]): boolean;
336
336
  //#endregion
337
- //#region src/numbers/display-number.d.ts
337
+ //#region src/numbers/rounding/number-digits.d.ts
338
+ declare function getNumberOfDigitsToShow(value: number | string, maxNumberOfDigits?: number): number;
339
+ //#endregion
340
+ //#region src/numbers/format/display-number.d.ts
338
341
  type NumberDisplayOptions = {
339
342
  scientific?: 'auto' | boolean;
340
343
  eNotation?: boolean;
@@ -347,8 +350,9 @@ type NumberDisplayOptions = {
347
350
  };
348
351
  declare const displayNumber: <Value extends number | string | null | undefined>(value: Value, options?: NumberDisplayOptions) => string;
349
352
  declare const displayNumberToFixed: <Value extends string | null | undefined>(value: Value, options?: NumberDisplayOptions) => string;
353
+ declare const formatNumber: (number: number | string | undefined | null) => string;
350
354
  //#endregion
351
- //#region src/rounding/rounding.d.ts
355
+ //#region src/numbers/rounding/rounding.d.ts
352
356
  declare const round: <Value extends number | string | null | undefined>(value: Value, n?: number) => Value;
353
357
  declare const roundToPrecision: <Value extends number | string | null | undefined>(value: Value, n?: number) => Value;
354
358
  declare const roundToDecimalPrecision: <Value extends number | string | null | undefined>(value: Value, n?: number) => Value;
@@ -357,10 +361,10 @@ declare const roundByMagnitudeToFixed: <Value extends number | string | null | u
357
361
  declare const roundByRange: <Value extends number | string | null | undefined>(value: Value, min: number, max: number, n?: number) => Value;
358
362
  declare const roundToFixed: <Value extends number | string | null | undefined>(value: Value, n?: number) => Value;
359
363
  //#endregion
360
- //#region src/rounding/cosmetic-rounding.d.ts
364
+ //#region src/numbers/rounding/cosmetic-rounding.d.ts
361
365
  declare const roundCosmetic: <Value extends number | string>(value: Value) => Value;
362
366
  //#endregion
363
- //#region src/comparison/comparison.d.ts
367
+ //#region src/numbers/comparison/comparison.d.ts
364
368
  type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
365
369
  type XOR<T, U> = T | U extends Record<string, unknown> ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
366
370
  type toleranceType = XOR<{
@@ -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,cAiIX,aAAA,EAAe,MAAA;AAAA,cA+Gf,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+FA,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCruCG,oBAAA,CAAqB,GAAA;AAAA,cAkBxB,UAAA,GAAc,KAAA;AAAA,iBAeX,SAAA,CAAU,CAAA;AAAA,iBA4BV,UAAA,CAAW,GAAA;AAAA,cAWd,YAAA,GAAgB,MAAA;AAAA,iBASb,SAAA,CAAU,GAAA,mBAAsB,GAAA;AAAA,i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AAA,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,cAyDE,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"}
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;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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AA,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.js CHANGED
@@ -1,5 +1,26 @@
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
- //#region src/rounding/cosmetic-rounding.ts
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";
2
+ import { n as roundNumberWithLabel, r as convertTable, t as altUnitsList } from "./chunks/units.js";
3
+ //#region src/numbers/rounding/number-digits.ts
4
+ /**
5
+ * Calculates a useful decimal precision for small values used by legacy rounding.
6
+ *
7
+ * @deprecated Use `roundByMagnitude` or another current rounding function instead.
8
+ */
9
+ function getNumberOfDigitsToShow(value, maxNumberOfDigits = 20) {
10
+ const defaultDigits = Math.min(4, maxNumberOfDigits);
11
+ let digits = defaultDigits;
12
+ if (typeof value !== "number") return defaultDigits;
13
+ const valueString = String(value);
14
+ if (/-?[0-9.,]*[Ee]-?[0-9]+/.test(valueString)) {
15
+ while (Math.abs(value) * 10 ** digits < 1 && digits < maxNumberOfDigits) digits += 1;
16
+ return Math.min(digits + (defaultDigits - 1), maxNumberOfDigits);
17
+ }
18
+ if (value > 1 || value < -1) return defaultDigits;
19
+ for (let index = 2; index < valueString.length; index += 1) if (valueString[index] !== "0") return Math.min(maxNumberOfDigits, digits + index - 2);
20
+ return digits;
21
+ }
22
+ //#endregion
23
+ //#region src/numbers/rounding/cosmetic-rounding.ts
3
24
  const COSMETIC_ROUNDING_DEFAULT_PRECISION = 14;
4
25
  /**
5
26
  * Applies display-only rounding to remove floating-point conversion noise.