"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/es5-ext/node_modules/es6-iterator/for-of.js" (7 Feb 2017, 1275 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 'use strict';
    2 
    3 var isArguments = require('es5-ext/function/is-arguments')
    4   , callable    = require('es5-ext/object/valid-callable')
    5   , isString    = require('es5-ext/string/is-string')
    6   , get         = require('./get')
    7 
    8   , isArray = Array.isArray, call = Function.prototype.call
    9   , some = Array.prototype.some;
   10 
   11 module.exports = function (iterable, cb/*, thisArg*/) {
   12     var mode, thisArg = arguments[2], result, doBreak, broken, i, l, char, code;
   13     if (isArray(iterable) || isArguments(iterable)) mode = 'array';
   14     else if (isString(iterable)) mode = 'string';
   15     else iterable = get(iterable);
   16 
   17     callable(cb);
   18     doBreak = function () { broken = true; };
   19     if (mode === 'array') {
   20         some.call(iterable, function (value) {
   21             call.call(cb, thisArg, value, doBreak);
   22             if (broken) return true;
   23         });
   24         return;
   25     }
   26     if (mode === 'string') {
   27         l = iterable.length;
   28         for (i = 0; i < l; ++i) {
   29             char = iterable[i];
   30             if ((i + 1) < l) {
   31                 code = char.charCodeAt(0);
   32                 if ((code >= 0xD800) && (code <= 0xDBFF)) char += iterable[++i];
   33             }
   34             call.call(cb, thisArg, char, doBreak);
   35             if (broken) break;
   36         }
   37         return;
   38     }
   39     result = iterable.next();
   40 
   41     while (!result.done) {
   42         call.call(cb, thisArg, result.value, doBreak);
   43         if (broken) return;
   44         result = iterable.next();
   45     }
   46 };