Skip to content

Commit

Permalink
use Number.isInteger instead of bitwise operation (#606)
Browse files Browse the repository at this point in the history
* use Number.isInteger instead of bitwise operation

* add test
  • Loading branch information
Uzlopak authored Feb 23, 2023
1 parent cb736a2 commit a9adf56
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = class Serializer {
if (i === Infinity || i === -Infinity) {
throw new Error(`The value "${i}" cannot be converted to an integer.`)
}
if ((i | 0) === i) {
if (Number.isInteger(i)) {
return '' + i
}
if (Number.isNaN(i)) {
Expand Down
1 change: 1 addition & 0 deletions test/integer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ test('render a float as an integer', (t) => {
{ input: 42, output: '42' },
{ input: 1.99999, output: '1' },
{ input: -45.05, output: '-45' },
{ input: 3333333333333333, output: '3333333333333333' },
{ input: Math.PI, output: '3', rounding: 'trunc' },
{ input: 5.0, output: '5', rounding: 'trunc' },
{ input: null, output: '0', rounding: 'trunc' },
Expand Down

0 comments on commit a9adf56

Please sign in to comment.