Giter VIP home page Giter VIP logo

twemoji-parser's Introduction

Twemoji Parser

A simple library for identifying emoji entities within a string in order to render them as Twemoji.

For example, this parser is used within the rendering flow for Tweets and other text on mobile.twitter.com

Setup

Important

The twemoji-parser package is now being published as @twemoji/parser

Add @twemoji/parser as a dependency to your project:

yarn add @twemoji/parser

Or, to work directly in this repo, clone it and run yarn install from the repo root.

Usage

The tests are intended to serve as a more exhaustive source of documentation, but the general idea is that the parser takes a string and returns an array of the emoji entities it finds:

import { parse } from '@twemoji/parser';
const entities = parse('I 🧡 Twemoji! 🥳');
/*
entities = [
  {
    url: 'https://cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets/svg/1f9e1.svg',
    indices: [ 2, 4 ],
    text: '🧡',
    type: 'emoji'
  },
  {
    url: 'https://cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets/svg/1f973.svg',
    indices: [ 12, 14 ],
    text: '🥳',
    type: 'emoji'
  }
]
*/

Authors

  • Nathan Downs (ex-Twitter)
  • Justine De Caires (ex-Twitter)

Contributing

We feel that a welcoming community is important and we ask that you follow our Open Source Code of Conduct in all interactions with the community.

Support

Create a new issue on GitHub.

License

MIT https://github.com/jdecked/twemoji-parser/blob/master/LICENSE.md

twemoji-parser's People

Contributors

andypiper avatar jdecked avatar k-kozika avatar msftenhanceprovenance avatar thatonecalculator avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

twemoji-parser's Issues

Feature request: Export the regex

Could the regular expression used internally to match Twemoji be exported? I think it could be very useful to find supported Unicode emojis within a string. Over 85% of this package's source code is the regex, and it's not even directly usable, which just seems a bit odd to me. It's really the most important part of the whole package.

You can currently import it directly with the full path (import twemojiRegexp from "@twemoji/parser/dist/lib/regex.js";), but it'd be preferable if it was explicitly exported.

Migrate to TypeScript?

Currently, twemoji-parser is written in JS + Flow, with the regex generator / build step written in Scala and using the Pants build system. While this may have fit in well with other Twitter projects (Twitter seems to do a lot in Scala; not sure about Flow), twemoji is no longer a Twitter project. It may make more sense to migrate twemoji-parser and the regex-generation build step completely to TypeScript, which the Node ecosystem seems to be coalescing around.

Currently, building twemoji-parser (or at least regenerating the regex) requires installing the JVM, Scala, and Python, despite this being a Node package. I believe it would be more friendly to new contributors to rewrite the regex generator in JavaScript or TypeScript, so that developers more used to the Node ecosystem would have an easier time contributing and wouldn't have to worry about so many non-Node language setups.

I believe that migrating the parser from Flow to TypeScript would also be beneficial. There's a lot more tooling built up around TypeScript than Flow, easing the development process, and the unofficial definitely-typed TS definitions could be replaced with official type definitions.

I would be more than willing to take on this work, provided that you think it'd be beneficial.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.