Skip to content

Commit

Permalink
Merge pull request #12 from aretecode/iterator
Browse files Browse the repository at this point in the history
馃攣 Set Iterator + Map Iterator
  • Loading branch information
jonschlinkert committed Jun 21, 2017
2 parents 30bee16 + b6bf33a commit fcab845
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions index.js
Expand Up @@ -84,6 +84,12 @@ module.exports = function kindOf(val) {
if (type === '[object Symbol]') {
return 'symbol';
}
if (type === '[object Map Iterator]') {
return 'mapiterator';
}
if (type === '[object Set Iterator]') {
return 'setiterator';
}

// typed arrays
if (type === '[object Int8Array]') {
Expand Down
18 changes: 15 additions & 3 deletions test/es6/index.js
Expand Up @@ -13,17 +13,19 @@ module.exports = function() {

it('should work for rejected promises', function() {
var promise = Promise.reject(new Error('foo bar'));
promise.catch(function() {})
promise.catch(function() {});
assert.strictEqual(kindOf(promise), 'promise');
});

it('should work for generators', function() {
var gen = function * named() {return true;};
var gen = function * named() {
return true;
};
assert.equal(kindOf(gen), 'function');
});

it('should work for template strings', function() {
var str = `Welcome buddy`;
var str = 'Welcome buddy';
assert.equal(kindOf(str), 'string');
});

Expand Down Expand Up @@ -59,6 +61,16 @@ module.exports = function() {
assert.equal(kindOf(weakset.get), 'undefined');
});

it('should work for Set Iterator', function() {
var set = new Set().values();
assert.equal(kindOf(set), 'setiterator');
});

it('should work for Map Iterator', function() {
var map = new Map().values();
assert.equal(kindOf(map), 'mapiterator');
});

it('should work for Symbol', function() {
assert.equal(kindOf(Symbol('foo')), 'symbol');
assert.equal(kindOf(Symbol.prototype), 'symbol');
Expand Down

0 comments on commit fcab845

Please sign in to comment.