From 0cfb70e5d271aefdb6c4e0f67c6e5ce240c4b5ac Mon Sep 17 00:00:00 2001 From: Ken Sheedlo Date: Mon, 24 Apr 2017 14:17:55 -0700 Subject: [PATCH] Remove unnecessary typeof Buffer check Fixes #9 --- browser.js | 30 +++++++++++++++++------------- index.js | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/browser.js b/browser.js index 76395ea..e0ea787 100644 --- a/browser.js +++ b/browser.js @@ -62,7 +62,7 @@ module.exports = function kindOf(val) { } // buffer - if (typeof Buffer !== 'undefined' && isBuffer(val)) { + if (isBuffer(val)) { return 'buffer'; } @@ -117,22 +117,26 @@ module.exports = function kindOf(val) { }; },{"is-buffer":2}],2:[function(require,module,exports){ -/** - * Determine if an object is Buffer - * - * Author: Feross Aboukhadijeh - * License: MIT +/*! + * Determine if an object is a Buffer * - * `npm install is-buffer` + * @author Feross Aboukhadijeh + * @license MIT */ +// The _isBuffer check is for Safari 5-7 support, because it's missing +// Object.prototype.constructor. Remove this eventually module.exports = function (obj) { - return !!(obj != null && - (obj._isBuffer || // For Safari 5-7 (missing Object.prototype.constructor) - (obj.constructor && - typeof obj.constructor.isBuffer === 'function' && - obj.constructor.isBuffer(obj)) - )) + return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer) +} + +function isBuffer (obj) { + return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj) +} + +// For Node v0.10 support. Remove this eventually. +function isSlowBuffer (obj) { + return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0)) } },{}]},{},[1])(1) diff --git a/index.js b/index.js index 8508386..b52c291 100644 --- a/index.js +++ b/index.js @@ -61,7 +61,7 @@ module.exports = function kindOf(val) { } // buffer - if (typeof Buffer !== 'undefined' && isBuffer(val)) { + if (isBuffer(val)) { return 'buffer'; }