Skip to content

Commit

Permalink
fast check 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 14, 2024
1 parent 53fd628 commit 54b35d1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ module.exports = class Serializer {

asNumber (i) {
const num = Number(i)
if (Number.isNaN(num)) {
// check if number is NaN
// eslint-disable-next-line no-self-compare
if (num !== num) {
throw new Error(`The value "${i}" cannot be converted to a number.`)
} else if (!Number.isFinite(num)) {
return 'null'
Expand Down

0 comments on commit 54b35d1

Please sign in to comment.