Skip to content

Commit 7eb74ad

Browse files
committed
fix: review
1 parent f42551f commit 7eb74ad

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
import {unbreakableGap} from '../../utils';
1+
import {UNBREAKABLE_GAP} from '../../utils';
22
import {formatBytes} from '../formatBytes';
33

44
describe('formatBytes', () => {
55
it('should work with only value', () => {
6-
expect(formatBytes({value: 100})).toBe(`100${unbreakableGap}B`);
7-
expect(formatBytes({value: 100_000})).toBe(`100${unbreakableGap}KB`);
8-
expect(formatBytes({value: 100_000_000})).toBe(`100${unbreakableGap}MB`);
9-
expect(formatBytes({value: 100_000_000_000})).toBe(`100${unbreakableGap}GB`);
10-
expect(formatBytes({value: 100_000_000_000_000})).toBe(`100${unbreakableGap}TB`);
6+
expect(formatBytes({value: 100})).toBe(`100${UNBREAKABLE_GAP}B`);
7+
expect(formatBytes({value: 100_000})).toBe(`100${UNBREAKABLE_GAP}KB`);
8+
expect(formatBytes({value: 100_000_000})).toBe(`100${UNBREAKABLE_GAP}MB`);
9+
expect(formatBytes({value: 100_000_000_000})).toBe(`100${UNBREAKABLE_GAP}GB`);
10+
expect(formatBytes({value: 100_000_000_000_000})).toBe(`100${UNBREAKABLE_GAP}TB`);
1111
});
1212
it('should convert to size', () => {
1313
expect(formatBytes({value: 100_000, size: 'b'})).toBe(
14-
`100${unbreakableGap}000${unbreakableGap}B`,
14+
`100${UNBREAKABLE_GAP}000${UNBREAKABLE_GAP}B`,
1515
);
1616
expect(formatBytes({value: 100_000_000_000_000, size: 'gb'})).toBe(
17-
`100${unbreakableGap}000${unbreakableGap}GB`,
17+
`100${UNBREAKABLE_GAP}000${UNBREAKABLE_GAP}GB`,
1818
);
1919
});
2020
it('should convert without labels', () => {
2121
expect(formatBytes({value: 100_000, size: 'b', withSizeLabel: false})).toBe(
22-
`100${unbreakableGap}000`,
22+
`100${UNBREAKABLE_GAP}000`,
2323
);
2424
expect(formatBytes({value: 100_000_000_000_000, size: 'gb', withSizeLabel: false})).toBe(
25-
`100${unbreakableGap}000`,
25+
`100${UNBREAKABLE_GAP}000`,
2626
);
2727
});
2828
it('should convert to speed', () => {
2929
expect(formatBytes({value: 100_000, withSpeedLabel: true})).toBe(
30-
`100${unbreakableGap}KB/s`,
30+
`100${UNBREAKABLE_GAP}KB/s`,
3131
);
3232
expect(formatBytes({value: 100_000, size: 'b', withSpeedLabel: true})).toBe(
33-
`100${unbreakableGap}000${unbreakableGap}B/s`,
33+
`100${UNBREAKABLE_GAP}000${UNBREAKABLE_GAP}B/s`,
3434
);
3535
});
3636
it('should return fixed amount of significant digits', () => {
3737
expect(formatBytes({value: 99_000, significantDigits: 2})).toEqual(
38-
`99${unbreakableGap}000${unbreakableGap}B`,
38+
`99${UNBREAKABLE_GAP}000${UNBREAKABLE_GAP}B`,
3939
);
4040
expect(formatBytes({value: 100_000, significantDigits: 2})).toEqual(
41-
`100${unbreakableGap}KB`,
41+
`100${UNBREAKABLE_GAP}KB`,
4242
);
4343
expect(formatBytes({value: 99_000_000_000_000, significantDigits: 2})).toEqual(
44-
`99${unbreakableGap}000${unbreakableGap}GB`,
44+
`99${UNBREAKABLE_GAP}000${UNBREAKABLE_GAP}GB`,
4545
);
4646
expect(formatBytes({value: 100_000_000_000_000, significantDigits: 2})).toEqual(
47-
`100${unbreakableGap}TB`,
47+
`100${UNBREAKABLE_GAP}TB`,
4848
);
4949
});
5050
it('should return empty string on invalid data', () => {
@@ -55,12 +55,12 @@ describe('formatBytes', () => {
5555
expect(formatBytes({value: '123qwe'})).toEqual('');
5656
});
5757
it('should work with precision', () => {
58-
expect(formatBytes({value: 123.123, precision: 2})).toBe(`123${unbreakableGap}B`);
59-
expect(formatBytes({value: 12.123, precision: 2})).toBe(`12${unbreakableGap}B`);
60-
expect(formatBytes({value: 1.123, precision: 2})).toBe(`1.1${unbreakableGap}B`);
61-
expect(formatBytes({value: 0.123, precision: 2})).toBe(`0.12${unbreakableGap}B`);
62-
expect(formatBytes({value: 0.012, precision: 2})).toBe(`0.01${unbreakableGap}B`);
63-
expect(formatBytes({value: 0.001, precision: 2})).toBe(`0${unbreakableGap}B`);
64-
expect(formatBytes({value: 0, precision: 2})).toBe(`0${unbreakableGap}B`);
58+
expect(formatBytes({value: 123.123, precision: 2})).toBe(`123${UNBREAKABLE_GAP}B`);
59+
expect(formatBytes({value: 12.123, precision: 2})).toBe(`12${UNBREAKABLE_GAP}B`);
60+
expect(formatBytes({value: 1.123, precision: 2})).toBe(`1.1${UNBREAKABLE_GAP}B`);
61+
expect(formatBytes({value: 0.123, precision: 2})).toBe(`0.12${UNBREAKABLE_GAP}B`);
62+
expect(formatBytes({value: 0.012, precision: 2})).toBe(`0.01${UNBREAKABLE_GAP}B`);
63+
expect(formatBytes({value: 0.001, precision: 2})).toBe(`0${UNBREAKABLE_GAP}B`);
64+
expect(formatBytes({value: 0, precision: 2})).toBe(`0${UNBREAKABLE_GAP}B`);
6565
});
6666
});

src/utils/bytesParsers/formatBytes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {GIGABYTE, KILOBYTE, MEGABYTE, TERABYTE} from '../constants';
22
import {formatNumber, roundToPrecision} from '../dataFormatters/dataFormatters';
3-
import {isNumeric, unbreakableGap} from '../utils';
3+
import {UNBREAKABLE_GAP, isNumeric} from '../utils';
44

55
import i18n from './i18n';
66

@@ -84,7 +84,7 @@ const formatToSize = ({value, size = 'mb', precision = 0}: FormatToSizeArgs) =>
8484
return formatNumber(result);
8585
};
8686

87-
const addSizeLabel = (result: string, size: BytesSizes, delimiter = unbreakableGap) => {
87+
const addSizeLabel = (result: string, size: BytesSizes, delimiter = UNBREAKABLE_GAP) => {
8888
return result + delimiter + sizes[size].label;
8989
};
9090

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {unbreakableGap} from '../../utils';
1+
import {UNBREAKABLE_GAP} from '../../utils';
22
import {formatStorageValues} from '../dataFormatters';
33

44
describe('formatStorageValues', () => {
@@ -9,27 +9,27 @@ describe('formatStorageValues', () => {
99

1010
it('should format value correctly when total is undefined', () => {
1111
const result = formatStorageValues(1024);
12-
expect(result).toEqual([`1${unbreakableGap}KB`, '']);
12+
expect(result).toEqual([`1${UNBREAKABLE_GAP}KB`, '']);
1313
});
1414

1515
it('should format total correctly when value is undefined', () => {
1616
const result = formatStorageValues(undefined, 2048);
17-
expect(result).toEqual(['', `2${unbreakableGap}KB`]);
17+
expect(result).toEqual(['', `2${UNBREAKABLE_GAP}KB`]);
1818
});
1919

2020
it('should format both value and total correctly', () => {
2121
const result = formatStorageValues(1024, 2048);
22-
expect(result).toEqual(['1', `2${unbreakableGap}KB`]);
22+
expect(result).toEqual(['1', `2${UNBREAKABLE_GAP}KB`]);
2323
});
2424

2525
it('should handle small value compared to total and increase precision', () => {
2626
const result = formatStorageValues(1, 1024);
27-
expect(result).toEqual(['0.001', `1${unbreakableGap}KB`]);
27+
expect(result).toEqual(['0.001', `1${UNBREAKABLE_GAP}KB`]);
2828
});
2929

3030
it('should return ["0", formattedTotal] when value is 0', () => {
3131
const result = formatStorageValues(0, 2048);
32-
expect(result).toEqual(['0', `2${unbreakableGap}KB`]);
32+
expect(result).toEqual(['0', `2${UNBREAKABLE_GAP}KB`]);
3333
});
3434

3535
it('should use provided size and delimiter', () => {
@@ -39,6 +39,6 @@ describe('formatStorageValues', () => {
3939

4040
it('should handle non-numeric total gracefully', () => {
4141
const result = formatStorageValues(2048, 'Not a number' as any);
42-
expect(result).toEqual([`2${unbreakableGap}KB`, '']);
42+
expect(result).toEqual([`2${UNBREAKABLE_GAP}KB`, '']);
4343
});
4444
});

src/utils/numeral.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import numeral from 'numeral';
22
import 'numeral/locales'; // Without this numeral will throw an error when using not 'en' locale
33

44
import {Lang, i18n} from './i18n';
5-
import {unbreakableGap} from './utils';
5+
import {UNBREAKABLE_GAP} from './utils';
66

77
// Set space delimiter for all locales possible in project
88
Object.values(Lang).forEach((value) => {
99
if (numeral.locales[value]) {
10-
numeral.locales[value].delimiters.thousands = unbreakableGap;
10+
numeral.locales[value].delimiters.thousands = UNBREAKABLE_GAP;
1111
}
1212
});
1313

src/utils/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ export function toExponential(value: number, precision?: number) {
105105
return Number(value).toExponential(precision);
106106
}
107107

108-
export const unbreakableGap = '\xa0';
108+
export const UNBREAKABLE_GAP = '\xa0';

0 commit comments

Comments
 (0)