Skip to content

Commit

Permalink
fix: favor extended array toStringTag where available
Browse files Browse the repository at this point in the history
  • Loading branch information
dvlsg authored and keithamus committed Apr 18, 2017
1 parent 9af1fee commit c0c5ed4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ module.exports = function typeDetect(obj) {
* Post:
* array literal x 22,479,650 ops/sec ±0.96% (81 runs sampled)
*/
if (Array.isArray(obj)) {
if (
Array.isArray(obj) &&
(symbolToStringTagExists === false || typeof obj[Symbol.toStringTag] === 'undefined')
) {
return 'Array';
}

Expand Down
9 changes: 8 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ describe('Generic', function () {
Object.prototype.toString = originalObjectToString; // eslint-disable-line no-extend-native
});


it('plain object', function () {
var obj = {};
obj[Symbol.toStringTag] = function () {
Expand All @@ -267,6 +266,14 @@ describe('Generic', function () {
assert(type(obj) === 'Foo', 'type(obj) === "Foo"');
});

it('array', function () {
var arr = [];
arr[Symbol.toStringTag] = function () {
return 'Foo';
};
assert(type(arr) === 'Foo', 'type(arr) === "Foo"');
});

});

});

0 comments on commit c0c5ed4

Please sign in to comment.