Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

chore(core): upgrade numfmt (#6814)

白熱066c9a1f7209
diff --git a/SECURITY.md b/SECURITY.md
index 37cad9a3fe..89b7ed9037 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -9,8 +9,6 @@ We provide security updates for the following versions of Univer.
| Version | Supported |
| ------- | ------------------ |
| latest | :white_check_mark: |
-| 0.6.0 | :white_check_mark: |
-| < 0.6.0 | :x: |
As Univer is still not reaching version 1.0 and we are moving fast with latest feature updates, unsupported versions may contain unpatched vulnerabilities. We recommend upgrading to the latest supported version.
diff --git a/packages/core/package.json b/packages/core/package.json
index 543c7e2412..351ce1f4e4 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -82,7 +82,7 @@
"kdbush": "^4.0.2",
"lodash-es": "^4.18.1",
"nanoid": "5.1.9",
- "numfmt": "^3.2.3",
+ "numfmt": "3.2.6",
"ot-json1": "^1.0.2",
"rbush": "^4.0.1"
},
diff --git a/packages/core/src/shared/__tests__/numfmt.spec.ts b/packages/core/src/shared/__tests__/numfmt.spec.ts
index 88b0d09db2..084370ca53 100644
--- a/packages/core/src/shared/__tests__/numfmt.spec.ts
+++ b/packages/core/src/shared/__tests__/numfmt.spec.ts
@@ -23,6 +23,7 @@ import {
isDefaultFormat,
isPatternEqualWithoutDecimal,
isTextFormat,
+ numfmt,
} from '../numfmt';
describe('numfmt helpers', () => {
@@ -56,3 +57,117 @@ describe('numfmt helpers', () => {
expect(getNumfmtParseValueFilter('25%')?.z).toBe('0%');
});
});
+
+describe('numfmt compatibility regression tests', () => {
+ describe('numfmt.format', () => {
+ it('should format numbers with common patterns', () => {
+ expect(numfmt.format('#,##0.00', 1234.5)).toBe('1,234.50');
+ expect(numfmt.format('0.00', 12.3)).toBe('12.30');
+ expect(numfmt.format('0%', 0.25)).toBe('25%');
+ expect(numfmt.format('0.00%', 0.255)).toBe('25.50%');
+ expect(numfmt.format('$#,##0', 1000)).toBe('$1,000');
+ expect(numfmt.format('General', 123)).toBe('123');
+ });
+
+ it('should handle locale formatting', () => {
+ expect(numfmt.format('#,##0.00', 1234.5, { locale: 'en' })).toBe('1,234.50');
+ });
+
+ it('should not throw when throws option is false', () => {
+ expect(numfmt.format('[invalid', 42, { throws: false })).toBe('######');
+ });
+ });
+
+ describe('numfmt.formatColor', () => {
+ it('should return color for colored patterns', () => {
+ expect(numfmt.formatColor('[red]0', 42)).toBe('red');
+ expect(numfmt.formatColor('[blue]0', -1)).toBe('blue');
+ expect(numfmt.formatColor('0', 42)).toBeNull();
+ });
+ });
+
+ describe('numfmt.parseDate', () => {
+ it('should parse date strings', () => {
+ expect(numfmt.parseDate('asdasdasd')).toBeNull();
+ expect(numfmt.parseDate('1988/12/12 21:21:21')?.z).toBe('yyyy/mm/dd hh:mm:ss');
+ expect(numfmt.parseDate('12/12 21:21:21')?.z).toBe('mm/dd hh:mm:ss');
+ expect(numfmt.parseDate('2012/12 21:21:21')?.z).toBe('yyyy/m hh:mm:ss');
+ expect(numfmt.parseDate('2012/12 21:21')?.z).toBe('yyyy/m hh:mm');
+ expect(numfmt.parseDate('2012/12')?.z).toBe('yyyy/m');
+ expect(numfmt.parseDate('2012/12/12')?.z).toBe('yyyy/mm/dd');
+ expect(numfmt.parseDate('21:21')).toBeNull();
+ });
+ });
+
+ describe('numfmt.parseTime', () => {
+ it('should parse time strings', () => {
+ expect(numfmt.parseTime('12:30')?.z).toBe('hh:mm');
+ expect(numfmt.parseTime('25:00')).toBeNull();
+ });
+ });
+
+ describe('numfmt.parseNumber', () => {
+ it('should parse number strings', () => {
+ expect(numfmt.parseNumber('25%')?.z).toBe('0%');
+ expect(numfmt.parseNumber('$1000')?.z).toBe('$#,##0');
+ expect(numfmt.parseNumber('1,00,0')?.z).toBe('#,##0');
+ });
+ });
+
+ describe('numfmt.parseValue', () => {
+ it('should parse mixed values (date/time/number)', () => {
+ expect(numfmt.parseValue('25%')?.z).toBe('0%');
+ expect(numfmt.parseValue('1988/12/12')?.z).toBe('yyyy/mm/dd');
+ expect(numfmt.parseValue('12:30')?.z).toBe('hh:mm');
+ expect(numfmt.parseValue('not-a-value')).toBeNull();
+ });
+ });
+
+ describe('numfmt.getFormatInfo', () => {
+ it('should return type information', () => {
+ expect(numfmt.getFormatInfo('0%').type).toBe('percent');
+ expect(numfmt.getFormatInfo('yyyy/mm/dd').isDate).toBe(true);
+ expect(numfmt.getFormatInfo('#,##0.00').isDate).toBe(false);
+ });
+
+ it('should return maxDecimals', () => {
+ expect(numfmt.getFormatInfo('0.00').maxDecimals).toBe(2);
+ expect(numfmt.getFormatInfo('0').maxDecimals).toBe(0);
+ expect(numfmt.getFormatInfo('General').maxDecimals).toBe(9);
+ });
+ });
+
+ describe('numfmt.tokenize', () => {
+ it('should tokenize patterns correctly', () => {
+ const tokens = numfmt.tokenize('0.00');
+ expect(tokens.length).toBeGreaterThan(0);
+ expect(tokens.some((t) => t.type === numfmt.tokenTypes.POINT)).toBe(true);
+ expect(tokens.some((t) => t.type === numfmt.tokenTypes.ZERO)).toBe(true);
+ });
+
+ it('should tokenize colored patterns', () => {
+ const tokens = numfmt.tokenize('[red]0.00');
+ expect(tokens.some((t) => t.type === numfmt.tokenTypes.COLOR)).toBe(true);
+ });
+
+ it('should tokenize patterns with minus', () => {
+ const tokens = numfmt.tokenize('-0.00');
+ expect(tokens.some((t) => t.type === numfmt.tokenTypes.MINUS)).toBe(true);
+ });
+
+ it('should tokenize patterns with grouping', () => {
+ const tokens = numfmt.tokenize('#,##0');
+ expect(tokens.some((t) => t.type === numfmt.tokenTypes.GROUP)).toBe(true);
+ });
+ });
+
+ describe('numfmt.tokenTypes', () => {
+ it('should expose expected token type constants', () => {
+ expect(typeof numfmt.tokenTypes.POINT).toBe('string');
+ expect(typeof numfmt.tokenTypes.ZERO).toBe('string');
+ expect(typeof numfmt.tokenTypes.COLOR).toBe('string');
+ expect(typeof numfmt.tokenTypes.MINUS).toBe('string');
+ expect(typeof numfmt.tokenTypes.GROUP).toBe('string');
+ });
+ });
+});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 6b770f383b..d573205628 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -796,8 +796,8 @@ importers:
specifier: 5.1.9
version: 5.1.9
numfmt:
- specifier: ^3.2.3
- version: 3.2.3
+ specifier: 3.2.6
+ version: 3.2.6
ot-json1:
specifier: ^1.0.2
version: 1.0.2
@@ -9230,8 +9230,8 @@ packages:
resolution: {integrity: sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==}
- resolution: {integrity: sha512-q5vjJSiuomxYNNVhB/TWqjtctZz+fnscUchvwonutXZ/neY2XLw6z4q3DS4ijLDrP5Y/tgrVeP1/7PjgHRoZuw==}
+ resolution: {integrity: sha512-MXc2KP3j+2usdHTY5/ENUc2S+3BRF/cJqnR6RHeq6LBqKoIZOAQ62DQw974nnaZOencbfkmkTPyTmMnlkCpjzg==}
resolution: {integrity: sha512-7eM+hpOtrKrBDCh7Ypu2lJ9Z7PNZBdi/8AT3AX8xoCj43BBVHD0hPSTEvMtkMpfs8FCqBGhxB+uToIQimA111g==}
@@ -17811,7 +17811,7 @@ snapshots:
dependencies:
boolbase: 1.0.0
dependencies: