Skip to content

Commit 14e7d50

Browse files
committed
[formatNumber] Fix default style handling and update tests
1 parent 49b31d3 commit 14e7d50

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

packages/svelte-ux/src/lib/utils/number.test.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, expect } from 'vitest';
22

33
import { clamp, formatNumber, formatNumberWithLocale, round } from './number';
4-
import { knownLocales } from './locale';
4+
import { createLocaleSettings, knownLocales } from './locale';
55

66
describe('clamp()', () => {
77
it('no change', () => {
@@ -61,17 +61,21 @@ describe('formatNumber()', () => {
6161
});
6262

6363
it('returns value as string for style "none"', () => {
64-
const actual = formatNumber(1234.5678, { style: 'none' });
64+
const actual = formatNumber(1234.5678, 'none');
6565
expect(actual).equal('1234.5678');
6666
});
6767

6868
it('formats number with integer default', () => {
69-
const actual = formatNumber(1234.5678, { style: 'integer' });
69+
const actual = formatNumber(1234.5678, 'integer');
7070
expect(actual).equal('1,235');
7171
});
7272

7373
it('formats number with integer fr', () => {
74-
const actual = formatNumber(1234.5678, { style: 'integer', locales: 'fr' });
74+
const actual = formatNumberWithLocale(
75+
createLocaleSettings({ locale: 'fr' }),
76+
1234.5678,
77+
'integer'
78+
);
7579
expect(actual).equal('1 235');
7680
});
7781

packages/svelte-ux/src/lib/utils/number.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ export function formatNumberWithLocale(
6060
// Let's always starts with all defaults
6161
...defaults,
6262

63-
style,
63+
...(style !== 'default' && {
64+
style,
65+
}),
6466

6567
// If currency is specified, then style must be currency
6668
...(options.currency != null && {

0 commit comments

Comments
 (0)