Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function replaceWithEmojis (message: string): string {
var words = message.split(' ');
for (var i = 0; i < words.length; i++) {
var query = words[i].toLowerCase().replace(/[^\w]/gi, '');
// Search over all emojis, looking for a matching keyword.
for (var key in emojis) {
if (emojis.hasOwnProperty(key)) {
if (key === query) {
words[i] = words[i].toLowerCase().replace(key, ':' + query + ':');
break;
}
}
}
}
return words.join(' ');
}
export function bySearch (query: string): string {
var options = [];
// Search over all emojis, looking for a matching keyword.
for (var key in emojis) {
if (emojis.hasOwnProperty(key)) {
// If the keyword matches, add the emoji to an array of options.
if (emojis[key].keywords && emojis[key].keywords.indexOf(query) > -1) {
options.push(key);
} else if (key.indexOf(query) > -1) {
options.push(key);
}
}
}
// If any options have been found, return a random option.
if (options.length > 0) {
return ':' + options[Math.floor(Math.random() * options.length)] + ': ';
} else {
return null;
}
}
function replaceWithEmojis(message) {
var words = message.split(' ');
for (var i = 0; i < words.length; i++) {
var query = words[i].toLowerCase().replace(/[^\w]/gi, '');
for (var key in emojis) {
if (emojis.hasOwnProperty(key)) {
if (key === query) {
words[i] = words[i].toLowerCase().replace(key, ':' + query + ':');
break;
}
}
}
}
return words.join(' ');
}
exports.replaceWithEmojis = replaceWithEmojis;
function bySearch(query) {
var options = [];
for (var key in emojis) {
if (emojis.hasOwnProperty(key)) {
if (emojis[key].keywords && emojis[key].keywords.indexOf(query) > -1) {
options.push(key);
}
else if (key.indexOf(query) > -1) {
options.push(key);
}
}
}
if (options.length > 0) {
return ':' + options[Math.floor(Math.random() * options.length)] + ': ';
}
else {
return null;
}
}
exports.bySearch = bySearch;