results = {
const input = `\\b${keywords}\\b`;
const regex = new RegExp(input, "ig");
return dataGrouped.map(d => {
const { name, lines } = d;
let count = 0;
const quotes = [];
const quotesSplit = [];
const matches = [];
lines.map(e => {
const quote = e;
const quoteMatchesIterator = quote.matchAll(regex);
const quoteMatches = [];
const quoteSplitPoints = [0];
for (const match of quoteMatchesIterator) {
quoteMatches.push(match[0]);
quoteSplitPoints.push(match.index);
quoteSplitPoints.push(match.index + match[0].length);
}
const quoteMatchesCount = quoteMatches.length;
const quoteSplit = [];
for (let i = 0; i < quoteSplitPoints.length; i++) {
if (i != quoteSplitPoints.length - 1) {
quoteSplit.push(
quote.slice(quoteSplitPoints[i], quoteSplitPoints[i + 1])
);
} else {
quoteSplit.push(quote.slice(quoteSplitPoints[i]));
}
}
if (keywords.length > 0) {
if (quoteMatches.length > 0) {
quotes.push(quote);
quotesSplit.push(quoteSplit);
}
matches.push(quoteMatches);
count = count + quoteMatchesCount;
}
});
return { name, count, quotes, quotesSplit };
});
}