},
/**
- * Returns true if `value` is an array, else returns false.
+ * Returns true if `value` is an array (including typed arrays), else returns false.
* @param {*} value - The value to test.
* @returns {Boolean}
* @function
*/
- isArray: Array.isArray ? Array.isArray : function(value) {
- return Object.prototype.toString.call(value) === '[object Array]';
+ isArray: function(value) {
+ if (Array.isArray && Array.isArray(value)) {
+ return true;
+ }
+ var type = Object.prototype.toString.call(value);
+ if (type.substr(0, 7) === '[object' && type.substr(-6) === 'Array]') {
+ return true;
+ }
+ return false;
},
/**
expect(helpers.isArray([42])).toBeTruthy();
expect(helpers.isArray(new Array())).toBeTruthy();
expect(helpers.isArray(Array.prototype)).toBeTruthy();
+ expect(helpers.isArray(new Int8Array(2))).toBeTruthy();
+ expect(helpers.isArray(new Uint8Array())).toBeTruthy();
+ expect(helpers.isArray(new Uint8ClampedArray([128, 244]))).toBeTruthy();
+ expect(helpers.isArray(new Int16Array())).toBeTruthy();
+ expect(helpers.isArray(new Uint16Array())).toBeTruthy();
+ expect(helpers.isArray(new Int32Array())).toBeTruthy();
+ expect(helpers.isArray(new Uint32Array())).toBeTruthy();
+ expect(helpers.isArray(new Float32Array([1.2]))).toBeTruthy();
+ expect(helpers.isArray(new Float64Array([]))).toBeTruthy();
});
it('should return false if value is not an array', function() {
expect(helpers.isArray()).toBeFalsy();