diff --git a/packages/react/src/lib/emoji.js b/packages/react/src/lib/emoji.js index d438099c7..3c861fd6b 100644 --- a/packages/react/src/lib/emoji.js +++ b/packages/react/src/lib/emoji.js @@ -1,12 +1,12 @@ import emojione from 'emoji-toolkit'; export const parseEmoji = (text) => { - const regx = /:([^:]*):/g; - const regx_data = text.match(regx); - if (regx_data) { - const result = regx_data[regx_data.length - 1]; - const d = emojione.shortnameToUnicode(result); - if (d !== undefined) text = text.replace(result, d); + if (!text || typeof text !== 'string') { + return text; } - return text; + const regx = /:([^:\s]+):/g; + return text.replace(regx, (match) => { + const unicode = emojione.shortnameToUnicode(match); + return unicode !== undefined ? unicode : match; + }); };