Skip to content
This repository has been archived by the owner on Jul 13, 2024. It is now read-only.

Commit

Permalink
Passing nextBreak to GraphmerIterator, instead of referencing it
Browse files Browse the repository at this point in the history
  • Loading branch information
stigi committed Jun 13, 2022
1 parent 6148859 commit 193c1ef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Graphemer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default class Graphemer {
* @returns {GraphemerIterator}
*/
iterateGraphemes(str: string): GraphemerIterator {
return new GraphemerIterator(str);
return new GraphemerIterator(str, Graphemer.nextBreak);
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/GraphemerIterator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Graphemer from './Graphemer';

/**
* GraphemerIterator
*
Expand All @@ -12,9 +10,11 @@ import Graphemer from './Graphemer';
class GraphemerIterator implements Iterator<string> {
private _index: number = 0;
private _str: string;
private _nextBreak: (str: string, index: number) => number;

constructor(str: string) {
constructor(str: string, nextBreak: (str: string, index: number) => number) {
this._str = str;
this._nextBreak = nextBreak;
}

[Symbol.iterator]() {
Expand All @@ -23,9 +23,7 @@ class GraphemerIterator implements Iterator<string> {

next() {
let brk;
if (
(brk = Graphemer.nextBreak(this._str, this._index)) < this._str.length
) {
if ((brk = this._nextBreak(this._str, this._index)) < this._str.length) {
const value = this._str.slice(this._index, brk);
this._index = brk;
return { value: value, done: false };
Expand Down

0 comments on commit 193c1ef

Please sign in to comment.