Skip to content

Commit 191b333

Browse files
committed
Update Words-away.js
1 parent d619042 commit 191b333

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

js/Words-away.js

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
function WordsAway() {}
2+
23
WordsAway.prototype.mixin = function (text, mixin = '\u200b', missBrackets = true) {
34
return this.stringListed(text, missBrackets).join(mixin);
45
}
@@ -171,21 +172,14 @@ WordsAway.prototype.styles = {
171172
}
172173
WordsAway.prototype.back = function (text, marks) {
173174
text = text.replace(/[\u200b\u200e]/g, '');
174-
var one = text.match(/(?<=\u202e).*?(?=\u202c)/g);
175-
var two = text.match(/(?<=\u202e)[^\n\r\u202c]*$/gm);
176-
var reversed = [];
177-
if (one) {
178-
reversed = reversed.concat(one);
175+
var reg1 = /\u202e(.*?)\u202c/g;
176+
var reg2 = /\u202e([^\n\r\u202c]*)$/gm;
177+
let array1, array2;
178+
while ((array1 = reg1.exec(text)) !== null) {
179+
text = text.replace(array1[1], this.toggleBrackets(this.stringListed(array1[1], marks).reverse().join(''), marks));
179180
}
180-
if (two) {
181-
reversed = reversed.concat(two);
181+
while ((array2 = reg2.exec(text)) !== null) {
182+
text = text.replace(array2[1], this.toggleBrackets(this.stringListed(array2[1], marks).reverse().join(''), marks));
182183
}
183-
if (reversed.length == 0) {
184-
return text;
185-
}
186-
for (let i of reversed) {
187-
text = text.replace(i, this.toggleBrackets(this.stringListed(i, marks).reverse().join(''), marks))
188-
.replace(/[\u202e\u202c]/g, '');
189-
}
190-
return text;
184+
return text.replace(/[\u202e\u202c]/g, '');;
191185
}

0 commit comments

Comments
 (0)