source: trip-planner-front/node_modules/async/internal/iterator.js@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = iterator;
7
8var _isArrayLike = require('lodash/isArrayLike');
9
10var _isArrayLike2 = _interopRequireDefault(_isArrayLike);
11
12var _getIterator = require('./getIterator');
13
14var _getIterator2 = _interopRequireDefault(_getIterator);
15
16var _keys = require('lodash/keys');
17
18var _keys2 = _interopRequireDefault(_keys);
19
20function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
22function createArrayIterator(coll) {
23 var i = -1;
24 var len = coll.length;
25 return function next() {
26 return ++i < len ? { value: coll[i], key: i } : null;
27 };
28}
29
30function createES2015Iterator(iterator) {
31 var i = -1;
32 return function next() {
33 var item = iterator.next();
34 if (item.done) return null;
35 i++;
36 return { value: item.value, key: i };
37 };
38}
39
40function createObjectIterator(obj) {
41 var okeys = (0, _keys2.default)(obj);
42 var i = -1;
43 var len = okeys.length;
44 return function next() {
45 var key = okeys[++i];
46 return i < len ? { value: obj[key], key: key } : null;
47 };
48}
49
50function iterator(coll) {
51 if ((0, _isArrayLike2.default)(coll)) {
52 return createArrayIterator(coll);
53 }
54
55 var iterator = (0, _getIterator2.default)(coll);
56 return iterator ? createES2015Iterator(iterator) : createObjectIterator(coll);
57}
58module.exports = exports['default'];
Note: See TracBrowser for help on using the repository browser.