Pull callback args into variables

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-05-12 15:52:05 +05:30
parent 9d898bdf47
commit 55b7c55efe

View File

@ -4,12 +4,14 @@ export function linkify(text, callback) {
const matches = text.matchAll(regex); const matches = text.matchAll(regex);
let curr = 0; let curr = 0;
for (let match of matches) { for (let match of matches) {
callback(text.slice(curr, match.index), false); const precedingText = text.slice(curr, match.index);
callback(precedingText, false);
callback(match[0], true); callback(match[0], true);
const len = match[0].length; const len = match[0].length;
curr = match.index + len; curr = match.index + len;
} }
callback(text.slice(curr), false); const remainingText = text.slice(curr);
callback(remainingText, false);
} }
export function tests() { export function tests() {