Skip to content

Commit

Permalink
Merge pull request #1555 from jmm/use-native-isarray
Browse files Browse the repository at this point in the history
Use native Array.isArray
  • Loading branch information
jmm committed May 6, 2016
2 parents 8f7adc9 + 14e92f9 commit 50b4e8d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var concat = require('concat-stream');
var inherits = require('inherits');
var EventEmitter = require('events').EventEmitter;
var xtend = require('xtend');
var isarray = require('isarray');
var isArray = Array.isArray;
var defined = require('defined');
var has = require('has');
var sanitize = require('htmlescape').sanitize;
Expand All @@ -38,7 +38,7 @@ function Browserify (files, opts) {
if (!(this instanceof Browserify)) return new Browserify(files, opts);
if (!opts) opts = {};

if (typeof files === 'string' || isarray(files) || isStream(files)) {
if (typeof files === 'string' || isArray(files) || isStream(files)) {
opts = xtend(opts, { entries: [].concat(opts.entries || [], files) });
}
else opts = xtend(files, opts);
Expand Down Expand Up @@ -72,7 +72,7 @@ function Browserify (files, opts) {

var ignoreTransform = [].concat(opts.ignoreTransform).filter(Boolean);
self._filterTransform = function (tr) {
if (Array.isArray(tr)) {
if (isArray(tr)) {
return ignoreTransform.indexOf(tr[0]) === -1;
}
return ignoreTransform.indexOf(tr) === -1;
Expand Down Expand Up @@ -100,7 +100,7 @@ function Browserify (files, opts) {

Browserify.prototype.require = function (file, opts) {
var self = this;
if (isarray(file)) {
if (isArray(file)) {
file.forEach(function (x) {
if (typeof x === 'object') {
self.require(x.file, xtend(opts, x));
Expand Down Expand Up @@ -193,7 +193,7 @@ Browserify.prototype.require = function (file, opts) {
Browserify.prototype.add = function (file, opts) {
var self = this;
if (!opts) opts = {};
if (isarray(file)) {
if (isArray(file)) {
file.forEach(function (x) { self.add(x, opts) });
return this;
}
Expand All @@ -202,7 +202,7 @@ Browserify.prototype.add = function (file, opts) {

Browserify.prototype.external = function (file, opts) {
var self = this;
if (isarray(file)) {
if (isArray(file)) {
file.forEach(function (f) {
if (typeof f === 'object') {
self.external(f, xtend(opts, f));
Expand Down Expand Up @@ -285,7 +285,7 @@ Browserify.prototype.transform = function (tr, opts) {
if (typeof opts === 'function' || typeof opts === 'string') {
tr = [ opts, tr ];
}
if (isarray(tr)) {
if (isArray(tr)) {
opts = tr[1];
tr = tr[0];
}
Expand Down Expand Up @@ -341,7 +341,7 @@ Browserify.prototype.transform = function (tr, opts) {
};

Browserify.prototype.plugin = function (p, opts) {
if (isarray(p)) {
if (isArray(p)) {
opts = p[1];
p = p[0];
}
Expand Down Expand Up @@ -496,7 +496,7 @@ Browserify.prototype._createDeps = function (opts) {
mopts.modules = {};
self._exclude.push.apply(self._exclude, Object.keys(builtins));
}
else if (opts.builtins && isarray(opts.builtins)) {
else if (opts.builtins && isArray(opts.builtins)) {
mopts.modules = {};
opts.builtins.forEach(function (key) {
mopts.modules[key] = builtins[key];
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@
"glob": "^5.0.15",
"has": "^1.0.0",
"htmlescape": "^1.1.0",
"stream-http": "^2.0.0",
"https-browserify": "~0.0.0",
"inherits": "~2.0.1",
"insert-module-globals": "^7.0.0",
"isarray": "0.0.1",
"labeled-stream-splicer": "^2.0.0",
"module-deps": "^4.0.2",
"os-browserify": "~0.1.1",
Expand All @@ -57,6 +55,7 @@
"shasum": "^1.0.0",
"shell-quote": "^1.4.3",
"stream-browserify": "^2.0.0",
"stream-http": "^2.0.0",
"string_decoder": "~0.10.0",
"subarg": "^1.0.0",
"syntax-error": "^1.1.1",
Expand Down
18 changes: 9 additions & 9 deletions test/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test('array add', function (t) {
t.plan(expected.length);

var b = browserify();
var files = [
var files = [
__dirname + '/array/one.js',
__dirname + '/array/two.js',
__dirname + '/array/three.js'
Expand All @@ -25,14 +25,14 @@ test('array require', function (t) {
t.plan(3);

var b = browserify();
var files = [ 'isarray', 'subarg' ];
var files = [ 'defined', 'subarg' ];
b.require(files);
b.bundle(function (err, src) {
var c = {};
vm.runInNewContext(src, c);
t.equal(c.require('isarray')([]), true);
t.equal(c.require('isarray')({}), false);

t.equal(c.require('defined')(undefined, true), true);
t.equal(c.require('defined')(undefined, false), false);
t.deepEqual(c.require('subarg')(['-x', '3']), { x: 3, _: [] });
});
});
Expand All @@ -42,16 +42,16 @@ test('array require opts', function (t) {

var b = browserify();
var files = [
{ file: require.resolve('isarray'), expose: 'abc' },
{ file: require.resolve('defined'), expose: 'abc' },
{ file: require.resolve('subarg'), expose: 'def' }
];
b.require(files);
b.bundle(function (err, src) {
var c = {};
vm.runInNewContext(src, c);
t.equal(c.require('abc')([]), true);
t.equal(c.require('abc')({}), false);

t.equal(c.require('abc')(undefined, true), true);
t.equal(c.require('abc')(undefined, false), false);
t.deepEqual(c.require('def')(['-x', '3']), { x: 3, _: [] });
});
});
Expand Down

0 comments on commit 50b4e8d

Please sign in to comment.