Skip to content

Commit f908120

Browse files
committed
fixe regex for price formatting - keep non-zero pennies
1 parent fc0faa6 commit f908120

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Examples/Complex/lib/price.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ type priceProp = {
44
};
55

66
export const parsePrice = ({ price }: priceProp) =>
7-
price.replace(/\.0*/, '').replace(/,/g, ' ');
7+
price.replace(/\.0+/, '').replace(/,/g, ' ');

Examples/Complex/lib/price.spec.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
import { parsePrice } from './price';
22

3-
it('remove penny', () => {
3+
it('removes zero pennies', () => {
44
expect(parsePrice({ price: '42.00 Kč' })).toEqual('42 Kč');
55
expect(parsePrice({ price: '1.00 Kč' })).toEqual('1 Kč');
66
expect(parsePrice({ price: '1.0000' })).toEqual('1');
77
expect(parsePrice({ price: '1.0' })).toEqual('1');
88
});
99

10+
it('keep non-zero pennies', () => {
11+
expect(parsePrice({ price: '42.80 Kč' })).toEqual('42.80 Kč');
12+
expect(parsePrice({ price: '1.8 Kč' })).toEqual('1.8 Kč');
13+
expect(parsePrice({ price: '1.42' })).toEqual('1.42');
14+
expect(parsePrice({ price: '1.4' })).toEqual('1.4');
15+
});
16+
1017
it('replace comma with space', () => {
1118
expect(parsePrice({ price: '42,000,243,000 Kč' })).toEqual(
1219
'42 000 243 000 Kč',
1320
);
1421
});
1522

16-
it('remove penny and replace comma with space', () => {
23+
it('remove pennies and replace commas with space', () => {
1724
expect(parsePrice({ price: '42,123.00 Kč' })).toEqual('42 123 Kč');
1825
});

0 commit comments

Comments
 (0)