2017-11-14 22:36:45 +00:00
|
|
|
"use strict";
|
|
|
|
|
2017-12-25 12:43:37 +00:00
|
|
|
const nickRegExp = /([\w[\]\\`^{|}-]+)/g;
|
|
|
|
|
2017-11-14 22:36:45 +00:00
|
|
|
function findNames(text, users) {
|
|
|
|
const result = [];
|
2017-11-30 12:16:11 +00:00
|
|
|
|
2017-12-25 12:43:37 +00:00
|
|
|
// 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],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 12:16:11 +00:00
|
|
|
|
2017-11-14 22:36:45 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = findNames;
|