diff --git a/lib/serializer.js b/lib/serializer.js index 387e8927..c6865226 100644 --- a/lib/serializer.js +++ b/lib/serializer.js @@ -25,13 +25,12 @@ module.exports = class Serializer { asInteger (i) { if (typeof i === 'number') { - if (i === Infinity || i === -Infinity) { - throw new Error(`The value "${i}" cannot be converted to an integer.`) - } if (Number.isInteger(i)) { return '' + i } - if (Number.isNaN(i)) { + // check if number is Infinity or NaN + // eslint-disable-next-line no-self-compare + if (i === Infinity || i === -Infinity || i !== i) { throw new Error(`The value "${i}" cannot be converted to an integer.`) } return this.parseInteger(i) @@ -52,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'