UNPKG

polyfill-service

Version:
62 lines (56 loc) 1.55 kB
// A modification of https://github.com/medikoo/es6-iterator // Copyright (C) 2013-2015 Mariusz Nowak (www.medikoo.com) /* global Iterator */ var StringIterator = (function() { // eslint-disable-line no-unused-vars var StringIterator = function (str) { if (!(this instanceof StringIterator)) return new StringIterator(str); str = String(str); Iterator.call(this, str); Object.defineProperty(this, '__length__', { value: str.length, configurable: false, enumerable: false, writable: false }); }; if (Object.setPrototypeOf) Object.setPrototypeOf(StringIterator, Iterator); StringIterator.prototype = Object.create(Iterator.prototype, { constructor: { value: StringIterator, configurable: true, enumerable: false, writable: true }, _next: { value: function() { if (!this.__list__) return; if (this.__nextIndex__ < this.__length__) return this.__nextIndex__++; this._unBind(); }, configurable: true, enumerable: false, writable: true }, _resolve: { value: 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; }, configurable: true, enumerable: false, writable: true }, toString: { value: function() { return '[object String Iterator]'; }, configurable: true, enumerable: false, writable: true } }); return StringIterator; }());