Skip to content

Commit a9adf56

Browse files
authored
use Number.isInteger instead of bitwise operation (#606)
* use Number.isInteger instead of bitwise operation * add test
1 parent cb736a2 commit a9adf56

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

lib/serializer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = class Serializer {
2727
if (i === Infinity || i === -Infinity) {
2828
throw new Error(`The value "${i}" cannot be converted to an integer.`)
2929
}
30-
if ((i | 0) === i) {
30+
if (Number.isInteger(i)) {
3131
return '' + i
3232
}
3333
if (Number.isNaN(i)) {

test/integer.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ test('render a float as an integer', (t) => {
4545
{ input: 42, output: '42' },
4646
{ input: 1.99999, output: '1' },
4747
{ input: -45.05, output: '-45' },
48+
{ input: 3333333333333333, output: '3333333333333333' },
4849
{ input: Math.PI, output: '3', rounding: 'trunc' },
4950
{ input: 5.0, output: '5', rounding: 'trunc' },
5051
{ input: null, output: '0', rounding: 'trunc' },

0 commit comments

Comments
 (0)