Skip to content

Commit

Permalink
Remove dependency on is-buffer (#1816)
Browse files Browse the repository at this point in the history
* Remove dependency on is-buffer from package.json
  • Loading branch information
Chalarangelo authored and yasuf committed Nov 18, 2019
1 parent 0cc22c2 commit 1a32ca0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
12 changes: 11 additions & 1 deletion lib/utils.js
@@ -1,7 +1,6 @@
'use strict';

var bind = require('./helpers/bind');
var isBuffer = require('is-buffer');

/*global toString:true*/

Expand All @@ -19,6 +18,17 @@ function isArray(val) {
return toString.call(val) === '[object Array]';
}


/**
* Determine if a value is a Buffer
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a Buffer, otherwise false
*/
function isBuffer(val) {
return ![undefined, null].includes(val) && val.constructor === Buffer;
}

/**
* Determine if a value is an ArrayBuffer
*
Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -73,8 +73,7 @@
},
"typings": "./index.d.ts",
"dependencies": {
"follow-redirects": "1.5.10",
"is-buffer": "^2.0.2"
"follow-redirects": "^1.4.1"
},
"bundlesize": [
{
Expand Down
6 changes: 6 additions & 0 deletions test/specs/utils/isX.spec.js
Expand Up @@ -7,6 +7,12 @@ describe('utils::isX', function () {
expect(utils.isArray({length: 5})).toEqual(false);
});

it('should validate Buffer', function () {
expect(utils.isBuffer(Buffer.from('a'))).toEqual(true);
expect(utils.isBuffer(null)).toEqual(false);
expect(utils.isBuffer(undefined)).toEqual(false);
});

it('should validate ArrayBuffer', function () {
expect(utils.isArrayBuffer(new ArrayBuffer(2))).toEqual(true);
expect(utils.isArrayBuffer({})).toEqual(false);
Expand Down

0 comments on commit 1a32ca0

Please sign in to comment.