Sha256: 8075bc0140556949a71668c6457220a917067789811377b0f63903c1d5d96d2f

Contents?: true

Size: 1.35 KB

Versions: 47

Compression:

Stored size: 1.35 KB

Contents

// Thanks @mathiasbynens
// http://mathiasbynens.be/notes/javascript-unicode#iterating-over-symbols

"use strict";

var setPrototypeOf = require("es5-ext/object/set-prototype-of")
  , d              = require("d")
  , Symbol         = require("es6-symbol")
  , Iterator       = require("./");

var defineProperty = Object.defineProperty, StringIterator;

StringIterator = module.exports = function (str) {
	if (!(this instanceof StringIterator)) throw new TypeError("Constructor requires 'new'");
	str = String(str);
	Iterator.call(this, str);
	defineProperty(this, "__length__", d("", str.length));
};
if (setPrototypeOf) setPrototypeOf(StringIterator, Iterator);

// Internal %ArrayIteratorPrototype% doesn't expose its constructor
delete StringIterator.prototype.constructor;

StringIterator.prototype = Object.create(Iterator.prototype, {
	_next: d(function () {
		if (!this.__list__) return undefined;
		if (this.__nextIndex__ < this.__length__) return this.__nextIndex__++;
		this._unBind();
		return undefined;
	}),
	_resolve: d(function (i) {
		var char = this.__list__[i], code;
		if (this.__nextIndex__ === this.__length__) return char;
		code = char.charCodeAt(0);
		if (code >= 0xd800 && code <= 0xdbff) return char + this.__list__[this.__nextIndex__++];
		return char;
	})
});
defineProperty(StringIterator.prototype, Symbol.toStringTag, d("c", "String Iterator"));

Version data entries

47 entries across 47 versions & 3 rubygems

Version Path
govuk_publishing_components-17.6.1 node_modules/es6-iterator/string.js
govuk_publishing_components-17.6.0 node_modules/es6-iterator/string.js
govuk_publishing_components-17.5.0 node_modules/es6-iterator/string.js
govuk_publishing_components-17.4.0 node_modules/es6-iterator/string.js
govuk_publishing_components-17.3.0 node_modules/es6-iterator/string.js
govuk_publishing_components-17.2.0 node_modules/es6-iterator/string.js
govuk_publishing_components-17.1.1 node_modules/es6-iterator/string.js
govuk_publishing_components-17.1.0 node_modules/es6-iterator/string.js
govuk_publishing_components-17.0.0 node_modules/es6-iterator/string.js
govuk_publishing_components-16.29.0 node_modules/es6-iterator/string.js
govuk_publishing_components-16.28.0 node_modules/es6-iterator/string.js
govuk_publishing_components-16.27.1 node_modules/es6-iterator/string.js
govuk_publishing_components-16.27.0 node_modules/es6-iterator/string.js
govuk_publishing_components-16.26.0 node_modules/es6-iterator/string.js
govuk_publishing_components-16.25.0 node_modules/es6-iterator/string.js
govuk_publishing_components-16.24.0 node_modules/es6-iterator/string.js
govuk_publishing_components-16.23.0 node_modules/es6-iterator/string.js
govuk_publishing_components-16.22.0 node_modules/es6-iterator/string.js
govuk_publishing_components-16.21.0 node_modules/es6-iterator/string.js
govuk_publishing_components-16.20.1 node_modules/es6-iterator/string.js