Skip to content

Commit

Permalink
chore(perf): reduce if statement for NaN
Browse files Browse the repository at this point in the history
Signed-off-by: francesco <[email protected]>
  • Loading branch information
cesco69 authored Mar 13, 2024
1 parent a63ed55 commit 7caca28
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions lib/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ module.exports = class Serializer {

asInteger (i) {
if (typeof i === 'number') {
if (i === Infinity || i === -Infinity) {
if (i === Infinity || i === -Infinity || Number.isNaN(i)) {
throw new Error(`The value "${i}" cannot be converted to an integer.`)
}
if (Number.isInteger(i)) {
return '' + i
}
if (Number.isNaN(i)) {
throw new Error(`The value "${i}" cannot be converted to an integer.`)
}
return this.parseInteger(i)
} else if (i === null) {
return '0'
Expand Down

0 comments on commit 7caca28

Please sign in to comment.