From: Feross Aboukhadijeh Date: Wed, 5 Apr 2017 18:27:26 +0000 (-0700) Subject: use `Number.isNaN` consistently X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=24d98b901d826ddb8de43389c494a8dd91fd99bc;p=buffer.git use `Number.isNaN` consistently --- diff --git a/index.js b/index.js index 848299b..7010056 100644 --- a/index.js +++ b/index.js @@ -252,8 +252,8 @@ function fromObject (obj) { } if (obj) { - if (typeof obj.length !== 'number' || isnan(obj.length)) { if (isArrayBufferView(obj) || 'length' in obj) { + if (typeof obj.length !== 'number' || Number.isNaN(obj.length)) { return createBuffer(0) } return fromArrayLike(obj) @@ -630,7 +630,7 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { byteOffset = -0x80000000 } byteOffset = +byteOffset // Coerce to Number. - if (isNaN(byteOffset)) { + if (Number.isNaN(byteOffset)) { // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer byteOffset = dir ? 0 : (buffer.length - 1) } @@ -761,7 +761,7 @@ function hexWrite (buf, string, offset, length) { } for (var i = 0; i < length; ++i) { var parsed = parseInt(string.substr(i * 2, 2), 16) - if (isNaN(parsed)) return i + if (Number.isNaN(parsed)) return i buf[offset + i] = parsed } return i @@ -1701,10 +1701,6 @@ function blitBuffer (src, dst, offset, length) { return i } -function isnan (val) { - return val !== val // eslint-disable-line no-self-compare -} - // Node 0.10 supports `ArrayBuffer` but lacks `ArrayBuffer.isView` function isArrayBufferView (obj) { return (typeof ArrayBuffer.isView === 'function') && ArrayBuffer.isView(obj)