Skip to content

Commit 5b42808

Browse files
feat(formatNumber): render numbers with spaces instead of comas (#778)
Co-authored-by: mufazalov <[email protected]>
1 parent b13344d commit 5b42808

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

src/containers/App/App.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* {
55
// FIXME: this is an overkill, potentially could break external components, needs refactoring
66
box-sizing: border-box;
7+
8+
// Make all digits in the app monospace
9+
font-variant-numeric: tabular-nums;
710
}
811

912
.yc-select-popup__tick-icon {

src/utils/bytesParsers/__test__/formatBytes.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ describe('formatBytes', () => {
99
expect(formatBytes({value: 100_000_000_000_000})).toBe('100 TB');
1010
});
1111
it('should convert to size', () => {
12-
expect(formatBytes({value: 100_000, size: 'b'})).toBe('100,000 B');
13-
expect(formatBytes({value: 100_000_000_000_000, size: 'gb'})).toBe('100,000 GB');
12+
expect(formatBytes({value: 100_000, size: 'b'})).toBe('100 000 B');
13+
expect(formatBytes({value: 100_000_000_000_000, size: 'gb'})).toBe('100 000 GB');
1414
});
1515
it('should convert without labels', () => {
16-
expect(formatBytes({value: 100_000, size: 'b', withSizeLabel: false})).toBe('100,000');
16+
expect(formatBytes({value: 100_000, size: 'b', withSizeLabel: false})).toBe('100 000');
1717
expect(formatBytes({value: 100_000_000_000_000, size: 'gb', withSizeLabel: false})).toBe(
18-
'100,000',
18+
'100 000',
1919
);
2020
});
2121
it('should convert to speed', () => {
2222
expect(formatBytes({value: 100_000, withSpeedLabel: true})).toBe('100 KB/s');
23-
expect(formatBytes({value: 100_000, size: 'b', withSpeedLabel: true})).toBe('100,000 B/s');
23+
expect(formatBytes({value: 100_000, size: 'b', withSpeedLabel: true})).toBe('100 000 B/s');
2424
});
2525
it('should return fixed amount of significant digits', () => {
26-
expect(formatBytes({value: 99_000, significantDigits: 2})).toEqual('99,000 B');
26+
expect(formatBytes({value: 99_000, significantDigits: 2})).toEqual('99 000 B');
2727
expect(formatBytes({value: 100_000, significantDigits: 2})).toEqual('100 KB');
28-
expect(formatBytes({value: 99_000_000_000_000, significantDigits: 2})).toEqual('99,000 GB');
28+
expect(formatBytes({value: 99_000_000_000_000, significantDigits: 2})).toEqual('99 000 GB');
2929
expect(formatBytes({value: 100_000_000_000_000, significantDigits: 2})).toEqual('100 TB');
3030
});
3131
it('should return empty string on invalid data', () => {

src/utils/dataFormatters/dataFormatters.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export const formatNumber = (number?: unknown) => {
9595
return '';
9696
}
9797

98+
// "," in format is delimiter sign, not delimiter itself
9899
return configuredNumeral(number).format('0,0.[00000]');
99100
};
100101

src/utils/numeral.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import numeral from 'numeral';
22
import 'numeral/locales'; // Without this numeral will throw an error when using not 'en' locale
33

4-
import {i18n} from './i18n';
4+
import {Lang, i18n} from './i18n';
5+
6+
// Set space delimiter for all locales possible in project
7+
Object.values(Lang).forEach((value) => {
8+
if (numeral.locales[value]) {
9+
numeral.locales[value].delimiters.thousands = ' ';
10+
}
11+
});
512

613
numeral.locale(i18n.lang);
714

0 commit comments

Comments
 (0)