@vuu-ui/vuu-utils 4.0.0-beta.1 → 4.0.0-beta.3

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.0.0-beta.1",
2
+ "version": "4.0.0-beta.3",
3
3
  "author": "heswell",
4
4
  "main": "./src/index.js",
5
5
  "license": "Apache-2.0",
@@ -15,14 +15,14 @@
15
15
  },
16
16
  "devDependencies": {
17
17
  "@dnd-kit/react": "^0.1.21",
18
- "@vuu-ui/vuu-data-types": "4.0.0-beta.1",
19
- "@vuu-ui/vuu-table-types": "4.0.0-beta.1",
20
- "@vuu-ui/vuu-filter-types": "4.0.0-beta.1",
21
- "@vuu-ui/vuu-protocol-types": "4.0.0-beta.1"
18
+ "@vuu-ui/vuu-data-types": "4.0.0-beta.3",
19
+ "@vuu-ui/vuu-table-types": "4.0.0-beta.3",
20
+ "@vuu-ui/vuu-filter-types": "4.0.0-beta.3",
21
+ "@vuu-ui/vuu-protocol-types": "4.0.0-beta.3"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@internationalized/date": "^3.0.0",
25
- "@vuu-ui/vuu-filter-parser": "4.0.0-beta.1",
25
+ "@vuu-ui/vuu-filter-parser": "4.0.0-beta.3",
26
26
  "clsx": "^2.0.0",
27
27
  "react": "^19.2.3",
28
28
  "react-dom": "^19.2.3"
@@ -52,7 +52,8 @@ const numericFormatter = ({ align = "right", serverDataType, type })=>{
52
52
  {
53
53
  const { alignOnDecimals = false, decimals, roundingRule, useLocaleString, zeroPad = false } = type.formatting ?? DEFAULT_NUMERIC_FORMAT;
54
54
  return (value)=>{
55
- if (serverDataType?.startsWith("scaleddecimal")) if ("string" == typeof value) return roundScaledDecimal(value, align, decimals, zeroPad, alignOnDecimals, useLocaleString, roundingRule);
55
+ if (serverDataType?.startsWith("scaleddecimal")) if (null == value) return "";
56
+ else if ("string" == typeof value) return roundScaledDecimal(value, align, decimals, zeroPad, alignOnDecimals, useLocaleString, roundingRule);
56
57
  else throw Error(`[formatting-utils] numericFormatter, invalid data for ${serverDataType}: '${value}'`);
57
58
  if ("string" == typeof value && (value.startsWith("Σ") || value.startsWith("["))) return value;
58
59
  const number = "number" == typeof value ? value : "string" == typeof value ? parseFloat(value) : void 0;
@@ -4,6 +4,12 @@ const DECIMALS_AUTO = -1;
4
4
  const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER.toString();
5
5
  const MAX_INTEGER_DIGITS = MAX_SAFE_INTEGER.length;
6
6
  const exceedsMaxSafeInteger = (value)=>value.length > MAX_INTEGER_DIGITS || value.length === MAX_INTEGER_DIGITS && value > MAX_SAFE_INTEGER;
7
+ const carriesIntoIntegral = (fraction, decimals, roundingRule)=>"round" === roundingRule && decimals !== DECIMALS_AUTO && fraction.length > decimals && parseFloat(`0.${fraction}`).toFixed(decimals).startsWith("1");
8
+ const incrementIntegral = (integral)=>{
9
+ const negative = integral.startsWith("-");
10
+ const magnitude = BigInt(negative ? integral.slice(1) : integral) + 1n;
11
+ return `${negative ? "-" : ""}${magnitude}`;
12
+ };
7
13
  const Space = {
8
14
  DIGIT: DIGIT_STR,
9
15
  TWO_DIGITS: DIGIT_STR + DIGIT_STR,
@@ -61,7 +67,8 @@ function roundDecimal(value, align = Align.Right, decimals = 4, zeroPad, alignOn
61
67
  let integral;
62
68
  let fraction;
63
69
  let Pad;
64
- const [part1, part2 = ""] = value.toString().split(".");
70
+ const [whole, part2 = ""] = value.toString().split(".");
71
+ const part1 = carriesIntoIntegral(part2, decimals, roundingRule) ? incrementIntegral(whole) : whole;
65
72
  const actualDecimals = part2.length;
66
73
  integral = "-0" === part1 ? "-0" : useLocaleString ? parseFloat(part1).toLocaleString() : parseFloat(part1).toString();
67
74
  if (align === Align.Left && alignOnDecimals) integral = padLeft(integral);
@@ -73,7 +80,8 @@ function roundScaledDecimal(value, align = Align.Right, decimals = 4, zeroPad, a
73
80
  let fraction;
74
81
  let Pad;
75
82
  if ("" === value) return "";
76
- const [part1, part2 = ""] = value.split(".");
83
+ const [whole, part2 = ""] = value.split(".");
84
+ const part1 = carriesIntoIntegral(part2, decimals, roundingRule) ? incrementIntegral(whole) : whole;
77
85
  const actualDecimals = part2.length;
78
86
  integral = "" === part1 ? "0" : "-0" === part1 ? "-0" : useLocaleString ? exceedsMaxSafeInteger(value) ? BigInt(part1).toLocaleString() : parseFloat(part1).toLocaleString() : part1;
79
87
  if (align === Align.Left && alignOnDecimals) integral = padLeft(integral);