@ultimat3/entity 31.33.0 → 31.35.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/entity",
3
- "version": "31.33.0",
3
+ "version": "31.35.0",
4
4
  "description": "A table + its domain type + invariants the database also enforces",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -44,9 +44,9 @@
44
44
  "test": "bun test"
45
45
  },
46
46
  "dependencies": {
47
- "@ultimat3/core": "31.33.0",
48
- "@ultimat3/db": "31.33.0",
49
- "@ultimat3/schema": "31.33.0",
50
- "@ultimat3/time": "31.33.0"
47
+ "@ultimat3/core": "31.35.0",
48
+ "@ultimat3/db": "31.35.0",
49
+ "@ultimat3/schema": "31.35.0",
50
+ "@ultimat3/time": "31.35.0"
51
51
  }
52
52
  }
@@ -62,6 +62,16 @@ const DECIMAL_PARTS = /^([+-]?)(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/;
62
62
  /** Past this an exponent would have the padding below build a string nobody asked for. */
63
63
  const MAX_EXPONENT = 1000;
64
64
 
65
+ /**
66
+ * `digits` without its trailing zeros. A loop, never `/0+$/`: that retried a zero run from each of
67
+ * its zeros — 10.7 s on 100k zeros and a 1 (CodeQL polynomial-redos).
68
+ */
69
+ const trimTrailingZeros = (digits: string): string => {
70
+ let end = digits.length;
71
+ while (end > 0 && digits[end - 1] === '0') end -= 1;
72
+ return digits.slice(0, end);
73
+ };
74
+
65
75
  const textOf = (value: unknown): string | undefined => {
66
76
  if (typeof value === 'string') return value.trim();
67
77
  return isNumber(value) ? plainDecimal(value) : undefined;
@@ -94,7 +104,7 @@ export const canonicalDecimal = (value: unknown): string | undefined => {
94
104
  const integer = point <= 0 ? '' : digits.slice(0, point).padEnd(point, '0');
95
105
  const rest = point <= 0 ? '0'.repeat(-point) + digits : digits.slice(point);
96
106
  const before = integer.replace(/^0+/, '') || '0';
97
- const after = rest.replace(/0+$/, '');
107
+ const after = trimTrailingZeros(rest);
98
108
  const unsigned = after === '' ? before : `${before}.${after}`;
99
109
  return sign === '-' && unsigned !== '0' ? `-${unsigned}` : unsigned;
100
110
  };