How to use the twemoji.replace function in twemoji

To help you get started, we’ve selected a few twemoji examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tahnik / devRantron / app / src / js / consts / utils.js View on Github external
export const getTextFromEmoji = (content) => {
  let contentToParse = content;
  const allEmojis = getAllEmojisRev();
  Twemoji.replace(content, (emoji) => {
    const unicodeEmoji = allEmojis[emoji];
    if (unicodeEmoji) {
      const regex = new RegExp(emoji, 'g');
      contentToParse = contentToParse.replace(regex, `:${unicodeEmoji}:`);
    }
  });
  return contentToParse;
};
github euphoria-io / heim / client / lib / ui / message-text.js View on Github external
if (!this.props.onlyEmoji) {
      html = html.replace(/\B&(\w+)(?=$|[^\w;])/g, (match, name) =>
        ReactDOMServer.renderToStaticMarkup(<a name="" href="{heimURL('/room/'">&amp;{name}</a>)
      )

      html = html.replace(chat.mentionRe, (match, name) =&gt; {
        const color = 'hsl(' + hueHash.hue(name) + ', 50%, 42%)'
        return ReactDOMServer.renderToStaticMarkup(<span style="{{color:">@{name}</span>)
      })
    }

    html = html.replace(emoji.namesRe, (match, name) =&gt;
      ReactDOMServer.renderToStaticMarkup(<div title="{match}">{match}</div>)
    )

    html = twemoji.replace(html, (match, icon, variant) =&gt; {
      if (variant === '\uFE0E') {
        return match
      }
      const codePoint = emoji.lookupEmojiCharacter(icon)
      if (!codePoint) {
        return match
      }
      const emojiName = emoji.names[codePoint] &amp;&amp; ':' + emoji.names[codePoint] + ':'
      return ReactDOMServer.renderToStaticMarkup(<div title="{emojiName}">{icon}</div>)
    })

    if (!this.props.onlyEmoji) {
      html = autolinker.link(html)
    }

    return (

twemoji

A Unicode standard based way to implement emoji across all platforms.

MIT
Latest version published 3 years ago

Package Health Score

68 / 100
Full package analysis