Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Commit ab5ca4e

Browse files
committed
add currency formatting
1 parent 93d7ae1 commit ab5ca4e

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/*
22
npm-debug.log
33
coverage/
44
build/
5+
package-lock.json

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"colors": "^1.1.2 ",
1313
"commander": "^2.9.0",
1414
"convert-units": "^2.0.1",
15-
"currency-symbol-map": "^3.1.0",
1615
"enumify": "^1.0.4",
1716
"immutable": "^3.8.1",
1817
"node-emoji": "^1.4.3",

src/services/tables/TripPriceEstimateRowFormatter.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import emoji from 'node-emoji';
2-
import CurrencySymbol from 'currency-symbol-map';
32
import { List, Map } from 'immutable';
43

54
import DistanceUnit from '../../data/DistanceUnit';
@@ -26,8 +25,15 @@ export default class TripPriceEstimateRowFormatter {
2625
}
2726

2827
formatRange(range) {
29-
const currencySymbol = CurrencySymbol(range.currencyCode);
30-
return `${currencySymbol}${range.low}-${currencySymbol}${range.high}`;
28+
return `${this.formatCurrencyValue(range.low, range.currencyCode)}-${this.formatCurrencyValue(range.high, range.currencyCode)}`;
29+
}
30+
31+
formatCurrencyValue(value, currencyCode) {
32+
return Intl.NumberFormat('en-US', {
33+
style: 'currency',
34+
maximumFractionDigits: 0,
35+
currency: currencyCode,
36+
}).format(value);
3137
}
3238

3339
formatDistance(distance, rowDistanceUnit) {

test/services/tables/TripPriceEstimateRowFormatterTest.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use es6';
2-
31
import chai from 'chai';
42
import chaiImmutable from 'chai-immutable';
53
import sinon from 'sinon';
@@ -50,19 +48,26 @@ describe('Trip Price Estimate Row Formatter', () => {
5048
it('throws exception', () => expect(() => rowFormatter.getDistanceUnitAbbreviation('foo')).to.throw(TypeError));
5149
});
5250

53-
describe('format range', () => {
51+
describe('#formatRange', () => {
5452
const range = {
5553
currencyCode: 'USD',
5654
low: 'foo',
5755
high: 'bar',
5856
};
5957

6058
it('successfully', () => {
61-
const expected = '$foo-$bar';
59+
sandbox.stub(rowFormatter, 'formatCurrencyValue').callsFake((value, currencyCode) => `${value}-${currencyCode}`);
60+
const expected = 'foo-USD-bar-USD';
6261
expect(rowFormatter.formatRange(range)).to.eql(expected);
6362
});
6463
});
6564

65+
describe('#formatCurrencyValue', () => {
66+
it('succeeds', () => {
67+
expect(rowFormatter.formatCurrencyValue(1234.567, 'USD')).to.eql('$1,235');
68+
});
69+
});
70+
6671
describe('format distance', () => {
6772
it('succeeds', () => {
6873
const distanceConversion = sinon.stub(distanceConverter, 'convert').returns({ value: 1 });

0 commit comments

Comments
 (0)