Sha256: a788f6cdb66fd300b9ade7bff02438018019a7d91d9712353322d6c6efc8e475

Contents?: true

Size: 1.25 KB

Versions: 47

Compression:

Stored size: 1.25 KB

Contents

"use strict";

var isArguments = require("es5-ext/function/is-arguments")
  , callable    = require("es5-ext/object/valid-callable")
  , isString    = require("es5-ext/string/is-string")
  , get         = require("./get");

var isArray = Array.isArray, call = Function.prototype.call, some = Array.prototype.some;

module.exports = function (iterable, cb /*, thisArg*/) {
	var mode, thisArg = arguments[2], result, doBreak, broken, i, length, char, code;
	if (isArray(iterable) || isArguments(iterable)) mode = "array";
	else if (isString(iterable)) mode = "string";
	else iterable = get(iterable);

	callable(cb);
	doBreak = function () {
		broken = true;
	};
	if (mode === "array") {
		some.call(iterable, function (value) {
			call.call(cb, thisArg, value, doBreak);
			return broken;
		});
		return;
	}
	if (mode === "string") {
		length = iterable.length;
		for (i = 0; i < length; ++i) {
			char = iterable[i];
			if (i + 1 < length) {
				code = char.charCodeAt(0);
				if (code >= 0xd800 && code <= 0xdbff) char += iterable[++i];
			}
			call.call(cb, thisArg, char, doBreak);
			if (broken) break;
		}
		return;
	}
	result = iterable.next();

	while (!result.done) {
		call.call(cb, thisArg, result.value, doBreak);
		if (broken) return;
		result = iterable.next();
	}
};

Version data entries

47 entries across 47 versions & 3 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/es6-iterator/for-of.js
govuk_publishing_components-18.0.0 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.21.0 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.20.0 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.19.1 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.19.0 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.18.0 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.17.0 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.16.0 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.15.0 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.14.0 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.13.0 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.12.2 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.12.1 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.12.0 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.11.0 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.10.0 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.9.0 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.8.0 node_modules/es6-iterator/for-of.js
govuk_publishing_components-17.7.0 node_modules/es6-iterator/for-of.js