We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c650966 commit 07a9bccCopy full SHA for 07a9bcc
lib/serializer.js
@@ -50,14 +50,17 @@ module.exports = class Serializer {
50
}
51
52
asNumber (i) {
53
- const num = Number(i)
54
- if (Number.isNaN(num)) {
+ if (typeof i !== 'number') {
+ i = Number(i)
55
+ }
56
+ // NaN !== NaN
57
+ if (i !== i) { // eslint-disable-line no-self-compare
58
throw new Error(`The value "${i}" cannot be converted to a number.`)
- } else if (!Number.isFinite(num)) {
- return null
- } else {
59
- return '' + num
60
+ if (i === Infinity || i === -Infinity) {
61
+ return 'null'
62
63
+ return '' + i
64
65
66
asBoolean (bool) {
0 commit comments