Skip to content

Commit 8868db7

Browse files
authored
fix(formatNumber): format null value as empty string (#20)
* fix(formatNumber): format null value as empty string * chore(travis-ci): upgrade node.js version
1 parent e6d277b commit 8868db7

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cache:
1313
notifications:
1414
email: false
1515
node_js:
16-
- '4'
16+
- '6'
1717
before_install:
1818
- npm i -g npm@^3.8.0
1919
- export CHROME_BIN=/usr/bin/google-chrome

src/numbers/format-number.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function getFormatOptions(format) {
4646
}
4747

4848
export default function formatNumber(number, format = "n", locale = "en") {
49-
if (number === undefined) {
49+
if (number === undefined || number === null) {
5050
return "";
5151
}
5252

test/numbers.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ describe('formatNumber', () => {
4343
expect(formatNumber(10000)).toEqual("10,000");
4444
});
4545

46-
it('should return empty string if not value is passed', () => {
46+
it('should return empty string if no value is passed', () => {
4747
expect(formatNumber()).toEqual("");
4848
});
4949

50+
it('should return empty string if null value is passed', () => {
51+
expect(formatNumber(null)).toEqual("");
52+
});
53+
5054
it('should return value if not finite value is passed', () => {
5155
expect(formatNumber(Infinity)).toBe(Infinity);
5256
expect(formatNumber("foo")).toEqual("foo");
@@ -621,4 +625,4 @@ describe('parseNumber', () => {
621625
}).not.toThrow();
622626
});
623627
});
624-
});
628+
});

0 commit comments

Comments
 (0)