You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.2 KiB
36 lines
1.2 KiB
8 years ago
|
import emojione from 'emojione';
|
||
|
|
||
8 years ago
|
const toImage = str => shortnameToImage(unicodeToImage(str));
|
||
|
|
||
|
const unicodeToImage = str => {
|
||
|
const mappedUnicode = emojione.mapUnicodeToShort();
|
||
|
|
||
|
return str.replace(emojione.regUnicode, unicodeChar => {
|
||
|
if (typeof unicodeChar === 'undefined' || unicodeChar === '' || !(unicodeChar in emojione.jsEscapeMap)) {
|
||
|
return unicodeChar;
|
||
|
}
|
||
|
|
||
|
const unicode = emojione.jsEscapeMap[unicodeChar];
|
||
|
const short = mappedUnicode[unicode];
|
||
|
const filename = emojione.emojioneList[short].fname;
|
||
|
const alt = emojione.convert(unicode.toUpperCase());
|
||
|
|
||
|
return `<img draggable="false" class="emojione" alt="${alt}" src="/emoji/${filename}.svg" />`;
|
||
|
});
|
||
|
};
|
||
|
|
||
|
const shortnameToImage = str => str.replace(emojione.regShortNames, shortname => {
|
||
|
if (typeof shortname === 'undefined' || shortname === '' || !(shortname in emojione.emojioneList)) {
|
||
|
return shortname;
|
||
|
}
|
||
|
|
||
|
const unicode = emojione.emojioneList[shortname].unicode[emojione.emojioneList[shortname].unicode.length - 1];
|
||
|
const alt = emojione.convert(unicode.toUpperCase());
|
||
|
|
||
|
return `<img draggable="false" class="emojione" alt="${alt}" src="/emoji/${unicode}.svg" />`;
|
||
|
});
|
||
8 years ago
|
|
||
|
export default function emojify(text) {
|
||
8 years ago
|
return toImage(text);
|
||
8 years ago
|
};
|