main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | /**
|
---|
4 | * GraphemerIterator
|
---|
5 | *
|
---|
6 | * Takes a string and a "BreakHandler" method during initialisation
|
---|
7 | * and creates an iterable object that returns individual graphemes.
|
---|
8 | *
|
---|
9 | * @param str {string}
|
---|
10 | * @return GraphemerIterator
|
---|
11 | */
|
---|
12 | class GraphemerIterator {
|
---|
13 | constructor(str, nextBreak) {
|
---|
14 | this._index = 0;
|
---|
15 | this._str = str;
|
---|
16 | this._nextBreak = nextBreak;
|
---|
17 | }
|
---|
18 | [Symbol.iterator]() {
|
---|
19 | return this;
|
---|
20 | }
|
---|
21 | next() {
|
---|
22 | let brk;
|
---|
23 | if ((brk = this._nextBreak(this._str, this._index)) < this._str.length) {
|
---|
24 | const value = this._str.slice(this._index, brk);
|
---|
25 | this._index = brk;
|
---|
26 | return { value: value, done: false };
|
---|
27 | }
|
---|
28 | if (this._index < this._str.length) {
|
---|
29 | const value = this._str.slice(this._index);
|
---|
30 | this._index = this._str.length;
|
---|
31 | return { value: value, done: false };
|
---|
32 | }
|
---|
33 | return { value: undefined, done: true };
|
---|
34 | }
|
---|
35 | }
|
---|
36 | exports.default = GraphemerIterator;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.