Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for typed arrays #5905

Merged
merged 1 commit into from Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/helpers/helpers.core.js
Expand Up @@ -32,13 +32,20 @@ var helpers = {
},

/**
* 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;
},

/**
Expand Down
4 changes: 4 additions & 0 deletions test/.eslintrc.yml
@@ -1,4 +1,8 @@
parserOptions:
ecmaVersion: 5 # don't rely on default, since its changed by env: es6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fine if our tests use es6 features, we only don't want our sources to use es6 feature because we don't want to integrate babel in v2.


env:
es6: true # also changes default ecmaVersion to 6
jasmine: true

globals:
Expand Down
9 changes: 9 additions & 0 deletions test/specs/helpers.core.tests.js
Expand Up @@ -21,6 +21,15 @@ describe('Chart.helpers.core', function() {
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();
Expand Down