Skip to content

Commit 91b03ff

Browse files
committed
rename Lib.isArray -> Lib.isArrayOrTypedArray
... to avoid confusion with Array.isArray and upcoming Lib.isTypedArray
1 parent ce5bc97 commit 91b03ff

File tree

10 files changed

+27
-34
lines changed

10 files changed

+27
-34
lines changed

src/lib/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ lib.nestedProperty = require('./nested_property');
2222
lib.keyedContainer = require('./keyed_container');
2323
lib.relativeAttr = require('./relative_attr');
2424
lib.isPlainObject = require('./is_plain_object');
25-
lib.isArray = require('./is_array');
2625
lib.mod = require('./mod');
2726
lib.toLogRange = require('./to_log_range');
2827
lib.relinkPrivateKeys = require('./relink_private');
2928
lib.ensureArray = require('./ensure_array');
3029

30+
var isArrayModule = require('./is_array');
31+
lib.isArrayOrTypedArray = isArrayModule.isArrayOrTypedArray
32+
3133
var coerceModule = require('./coerce');
3234
lib.valObjectMeta = coerceModule.valObjectMeta;
3335
lib.coerce = coerceModule.coerce;

src/lib/is_array.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88

99
'use strict';
1010

11-
/**
12-
* Return true for arrays, whether they're untyped or not.
13-
*/
14-
1511
// IE9 fallback
1612
var ab = (typeof ArrayBuffer === 'undefined' || !ArrayBuffer.isView) ?
1713
{isView: function() { return false; }} :
1814
ArrayBuffer;
1915

20-
module.exports = function isArray(a) {
16+
exports.isArrayOrTypedArray = function(a) {
2117
return Array.isArray(a) || ab.isView(a);
2218
};

src/lib/nested_property.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'use strict';
1111

1212
var isNumeric = require('fast-isnumeric');
13-
var isArray = require('./is_array');
13+
var isArrayOrTypedArray = require('./is_array').isArrayOrTypedArray;
1414
var isPlainObject = require('./is_plain_object');
1515
var containerArrayMatch = require('../plot_api/container_array_match');
1616

@@ -96,7 +96,7 @@ function npGet(cont, parts) {
9696
}
9797
return allSame ? out[0] : out;
9898
}
99-
if(typeof curPart === 'number' && !isArray(curCont)) {
99+
if(typeof curPart === 'number' && !isArrayOrTypedArray(curCont)) {
100100
return undefined;
101101
}
102102
curCont = curCont[curPart];
@@ -144,7 +144,7 @@ function isDeletable(val, propStr) {
144144
) {
145145
return false;
146146
}
147-
if(!isArray(val)) return true;
147+
if(!isArrayOrTypedArray(val)) return true;
148148

149149
if(propStr.match(INFO_PATTERNS)) return true;
150150

@@ -167,7 +167,7 @@ function npSet(cont, parts, propStr) {
167167
for(i = 0; i < parts.length - 1; i++) {
168168
curPart = parts[i];
169169

170-
if(typeof curPart === 'number' && !isArray(curCont)) {
170+
if(typeof curPart === 'number' && !isArrayOrTypedArray(curCont)) {
171171
throw 'array index but container is not an array';
172172
}
173173

@@ -211,7 +211,7 @@ function joinPropStr(propStr, newPart) {
211211

212212
// handle special -1 array index
213213
function setArrayAll(containerArray, innerParts, val, propStr) {
214-
var arrayVal = isArray(val),
214+
var arrayVal = isArrayOrTypedArray(val),
215215
allSet = true,
216216
thisVal = val,
217217
thisPropStr = propStr.replace('-1', 0),
@@ -261,7 +261,7 @@ function pruneContainers(containerLevels) {
261261
propPart = containerLevels[i][1];
262262

263263
remainingKeys = false;
264-
if(isArray(curCont)) {
264+
if(isArrayOrTypedArray(curCont)) {
265265
for(j = curCont.length - 1; j >= 0; j--) {
266266
if(isDeletable(curCont[j], joinPropStr(propPart, j))) {
267267
if(remainingKeys) curCont[j] = undefined;
@@ -287,7 +287,7 @@ function pruneContainers(containerLevels) {
287287
function emptyObj(obj) {
288288
if(obj === undefined || obj === null) return true;
289289
if(typeof obj !== 'object') return false; // any plain value
290-
if(isArray(obj)) return !obj.length; // []
290+
if(isArrayOrTypedArray(obj)) return !obj.length; // []
291291
return !Object.keys(obj).length; // {}
292292
}
293293

src/lib/relink_private.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
var isArray = require('./is_array');
12+
var isArrayOrTypedArray = require('./is_array').isArrayOrTypedArray;
1313
var isPlainObject = require('./is_plain_object');
1414

1515
/**
@@ -35,7 +35,7 @@ module.exports = function relinkPrivateKeys(toContainer, fromContainer) {
3535

3636
toContainer[k] = fromVal;
3737
}
38-
else if(isArray(fromVal) && isArray(toVal) && isPlainObject(fromVal[0])) {
38+
else if(isArrayOrTypedArray(fromVal) && isArrayOrTypedArray(toVal) && isPlainObject(fromVal[0])) {
3939

4040
// filter out data_array items that can contain user objects
4141
// most of the time the toVal === fromVal check will catch these early

src/plots/array_container_defaults.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
var Lib = require('../lib');
1212

13-
1413
/** Convenience wrapper for making array container logic DRY and consistent
1514
*
1615
* @param {object} parentObjIn
@@ -46,7 +45,7 @@ module.exports = function handleArrayContainerDefaults(parentObjIn, parentObjOut
4645

4746
var previousContOut = parentObjOut[name];
4847

49-
var contIn = Lib.isArray(parentObjIn[name]) ? parentObjIn[name] : [],
48+
var contIn = Lib.isArrayOrTypedArray(parentObjIn[name]) ? parentObjIn[name] : [],
5049
contOut = parentObjOut[name] = [],
5150
i;
5251

@@ -70,7 +69,7 @@ module.exports = function handleArrayContainerDefaults(parentObjIn, parentObjOut
7069

7170
// in case this array gets its defaults rebuilt independent of the whole layout,
7271
// relink the private keys just for this array.
73-
if(Lib.isArray(previousContOut)) {
72+
if(Lib.isArrayOrTypedArray(previousContOut)) {
7473
var len = Math.min(previousContOut.length, contOut.length);
7574
for(i = 0; i < len; i++) {
7675
Lib.relinkPrivateKeys(contOut[i], previousContOut[i]);

src/traces/carpet/cheater_basis.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
'use strict';
1010

11-
var isArray = require('../../lib').isArray;
11+
var isArrayOrTypedArray = require('../../lib').isArrayOrTypedArray;
1212

1313
/*
1414
* Construct a 2D array of cheater values given a, b, and a slope.
@@ -18,10 +18,10 @@ module.exports = function(a, b, cheaterslope) {
1818
var i, j, ascal, bscal, aval, bval;
1919
var data = [];
2020

21-
var na = isArray(a) ? a.length : a;
22-
var nb = isArray(b) ? b.length : b;
23-
var adata = isArray(a) ? a : null;
24-
var bdata = isArray(b) ? b : null;
21+
var na = isArrayOrTypedArray(a) ? a.length : a;
22+
var nb = isArrayOrTypedArray(b) ? b.length : b;
23+
var adata = isArrayOrTypedArray(a) ? a : null;
24+
var bdata = isArrayOrTypedArray(b) ? b : null;
2525

2626
// If we're using data, scale it so that for data that's just barely
2727
// not evenly spaced, the switch to value-based indexing is continuous.

src/traces/parcoords/calc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var Lib = require('../../lib');
1414
var wrap = require('../../lib/gup').wrap;
1515

1616
module.exports = function calc(gd, trace) {
17-
var cs = !!trace.line.colorscale && Lib.isArray(trace.line.color);
17+
var cs = !!trace.line.colorscale && Lib.isArrayOrTypedArray(trace.line.color);
1818
var color = cs ? trace.line.color : Array.apply(0, Array(trace.dimensions.reduce(function(p, n) {return Math.max(p, n.values.length);}, 0))).map(function() {return 0.5;});
1919
var cscale = cs ? trace.line.colorscale : [[0, trace.line.color], [1, trace.line.color]];
2020

src/traces/parcoords/defaults.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
1818

1919
coerce('line.color', defaultColor);
2020

21-
if(hasColorscale(traceIn, 'line') && Lib.isArray(traceIn.line.color)) {
21+
if(hasColorscale(traceIn, 'line') && Lib.isArrayOrTypedArray(traceIn.line.color)) {
2222
coerce('line.colorscale');
2323
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'});
2424
}

src/traces/sankey/render.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ function sankeyModel(layout, d, i) {
8787
return {
8888
pointNumber: i,
8989
label: l,
90-
color: Lib.isArray(nodeSpec.color) ? nodeSpec.color[i] : nodeSpec.color
90+
color: Lib.isArrayOrTypedArray(nodeSpec.color) ? nodeSpec.color[i] : nodeSpec.color
9191
};
9292
});
9393

9494
var links = linkSpec.value.map(function(d, i) {
9595
return {
9696
pointNumber: i,
9797
label: linkSpec.label[i],
98-
color: Lib.isArray(linkSpec.color) ? linkSpec.color[i] : linkSpec.color,
98+
color: Lib.isArrayOrTypedArray(linkSpec.color) ? linkSpec.color[i] : linkSpec.color,
9999
source: linkSpec.source[i],
100100
target: linkSpec.target[i],
101101
value: d

test/jasmine/tests/is_array_test.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
var Lib = require('@src/lib');
22

3-
describe('isArray', function() {
4-
'use strict';
5-
6-
var isArray = Lib.isArray;
7-
3+
describe('isArrayOrTypedArray', function() {
84
function A() {}
95

106
var shouldPass = [
@@ -35,13 +31,13 @@ describe('isArray', function() {
3531

3632
shouldPass.forEach(function(obj) {
3733
it('treats ' + JSON.stringify(obj) + ' as an array', function() {
38-
expect(isArray(obj)).toBe(true);
34+
expect(Lib.isArrayOrTypedArray(obj)).toBe(true);
3935
});
4036
});
4137

4238
shouldFail.forEach(function(obj) {
4339
it('treats ' + JSON.stringify(obj !== window ? obj : 'window') + ' as NOT an array', function() {
44-
expect(isArray(obj)).toBe(false);
40+
expect(Lib.isArrayOrTypedArray(obj)).toBe(false);
4541
});
4642
});
4743
});

0 commit comments

Comments
 (0)