source: frontend/node_modules/core-js-pure/modules/esnext.iterator.chunks.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.4 KB
Line 
1'use strict';
2var $ = require('../internals/export');
3var anObject = require('../internals/an-object');
4var call = require('../internals/function-call');
5var createIteratorProxy = require('../internals/iterator-create-proxy');
6var getIteratorDirect = require('../internals/get-iterator-direct');
7var iteratorClose = require('../internals/iterator-close');
8var uncurryThis = require('../internals/function-uncurry-this');
9
10var $RangeError = RangeError;
11var push = uncurryThis([].push);
12
13var IteratorProxy = createIteratorProxy(function () {
14 var iterator = this.iterator;
15 var next = this.next;
16 var chunkSize = this.chunkSize;
17 var buffer = [];
18 var result, done;
19 while (true) {
20 result = anObject(call(next, iterator));
21 done = !!result.done;
22 if (done) {
23 if (buffer.length) return buffer;
24 this.done = true;
25 return;
26 }
27 push(buffer, result.value);
28 if (buffer.length === chunkSize) return buffer;
29 }
30});
31
32// `Iterator.prototype.chunks` method
33// https://github.com/tc39/proposal-iterator-chunking
34$({ target: 'Iterator', proto: true, real: true, forced: true }, {
35 chunks: function chunks(chunkSize) {
36 var O = anObject(this);
37 if (typeof chunkSize != 'number' || !chunkSize || chunkSize >>> 0 !== chunkSize) {
38 return iteratorClose(O, 'throw', new $RangeError('chunkSize must be integer in [1, 2^32-1]'));
39 }
40 return new IteratorProxy(getIteratorDirect(O), {
41 chunkSize: chunkSize
42 });
43 }
44});
Note: See TracBrowser for help on using the repository browser.