This repository has been archived on 2020-11-02. You can view files and clone it, but cannot push or open issues or pull requests.
TripSit_Suite/client/js/helpers/ircmessageparser/findNames.js
2020-11-01 22:46:04 +00:00

29 lines
472 B
JavaScript

"use strict";
const nickRegExp = /([\w[\]\\`^{|}-]+)/g;
function findNames(text, users) {
const result = [];
// Return early if we don't have any nicknames to find
if (users.length === 0) {
return result;
}
let match;
while ((match = nickRegExp.exec(text))) {
if (users.indexOf(match[1]) > -1) {
result.push({
start: match.index,
end: match.index + match[1].length,
nick: match[1],
});
}
}
return result;
}
export default findNames;