All Projects → twitter → Twemoji

twitter / Twemoji

Licence: other
Emoji for everyone. https://twemoji.twitter.com/

Programming Languages

HTML
75241 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Twemoji

EmojiBuilder
Construct (or destruct) emoji from layered SVGs
Stars: ✭ 13 (-99.9%)
Mutual labels:  emoji, twemoji
emojicodes
An extension to use emoji codes in your Sphinx documentation! 😍
Stars: ✭ 39 (-99.71%)
Mutual labels:  emoji, twemoji
Emoji Mart
One component to pick them all 👊🏼
Stars: ✭ 4,687 (-65.55%)
Mutual labels:  emoji, twemoji
Conventional Commit Types
List of conventional commit types with emoji 🎉
Stars: ✭ 119 (-99.13%)
Mutual labels:  emoji
Ng Embed
An AngularJS filter/directive for embedding emojis, media, maps, tweets, code and services
Stars: ✭ 124 (-99.09%)
Mutual labels:  emoji
Gacp
💬Git add, commit, push with Conventional Commits and Gitmoji.
Stars: ✭ 139 (-98.98%)
Mutual labels:  emoji
Github Complete.vim
Vim input completion for GitHub
Stars: ✭ 161 (-98.82%)
Mutual labels:  emoji
Emoji Swift
String extension converting to and from emoji character and Emoji-One
Stars: ✭ 119 (-99.13%)
Mutual labels:  emoji
Uitextviewdiyemojiexample
Example of insert custom emoji image in to UITextView. And get the represent string back after editing.
Stars: ✭ 148 (-98.91%)
Mutual labels:  emoji
Emojipackage
表情包资源合集,张张都是经典
Stars: ✭ 1,789 (-86.85%)
Mutual labels:  emoji
Laravel Emojione
Laravel package to make it easy to use the gorgeous emojis from EmojiOne
Stars: ✭ 133 (-99.02%)
Mutual labels:  emoji
Jquery Emoji
😄 Let textarea or editable div has ability to insert emoji. 让文本框或div具备插入表情功能。
Stars: ✭ 125 (-99.08%)
Mutual labels:  emoji
Laravel Emoji
😄 This package assist you in getting started with emoji easily.
Stars: ✭ 146 (-98.93%)
Mutual labels:  emoji
Croc
Swift emoji string parsing library
Stars: ✭ 124 (-99.09%)
Mutual labels:  emoji
Spacymoji
💙 Emoji handling and meta data for spaCy with custom extension attributes
Stars: ✭ 151 (-98.89%)
Mutual labels:  emoji
Turtle
Emojis for Go 😄🐢🚀
Stars: ✭ 120 (-99.12%)
Mutual labels:  emoji
Whatsbook
Create books from WhatsApp group chats with Python and LaTeX
Stars: ✭ 147 (-98.92%)
Mutual labels:  emoji
Git Commit Emoji Cn
😁 git commit message emoji 使用指南
Stars: ✭ 1,702 (-87.49%)
Mutual labels:  emoji
Emojipanel
😀 A customisable Javascript emoji picker
Stars: ✭ 129 (-99.05%)
Mutual labels:  emoji
Emoji Commit Messages
🌵 A fun paradigm to encourage cleaner commits.
Stars: ✭ 138 (-98.99%)
Mutual labels:  emoji

Twitter Emoji (Twemoji) Build Status

A simple library that provides standard Unicode emoji support across all platforms.

Twemoji v13.1 adheres to the Unicode 13.0 spec and supports the Emoji 13.1 spec. We do not support custom emoji.

The Twemoji library offers support for 3,521 Unicode-defined emojis.

Usage

CDN Support

The folks over at MaxCDN have graciously provided CDN support.

Use the following in the <head> tag of your HTML document(s):

<script src="https://twemoji.maxcdn.com/v/latest/twemoji.min.js" crossorigin="anonymous"></script>

This guarantees that you will always use the latest version of the library.

If, instead, you'd like to include the latest version explicitly, you can add the following tag:

<script src="https://twemoji.maxcdn.com/v/13.1.0/twemoji.min.js" integrity="sha384-gPMUf7aEYa6qc3MgqTrigJqf4gzeO6v11iPCKv+AP2S4iWRWCoWyiR+Z7rWHM/hU" crossorigin="anonymous"></script>

Download

If instead you want to download a specific version, please look at the gh-pages branch, where you will find the built assets for both our latest and older versions.

API

Following are all the methods exposed in the twemoji namespace.

twemoji.parse( ... ) V1

This is the main parsing utility and has 3 overloads per parsing type.

Although there are two kinds of parsing supported by this utility, we recommend you use DOM parsing, explained below. Each type of parsing accepts a callback to generate an image source or an options object with parsing info.

The second kind of parsing is string parsing, explained in the legacy documentation here. This is unrecommended because this method does not sanitize the string or otherwise prevent malicious code from being executed; such sanitization is out of scope.

DOM parsing

If the first argument to twemoji.parse is an HTMLElement, generated image tags will replace emoji that are inside #text nodes only without compromising surrounding nodes or listeners, and completely avoiding the usage of innerHTML.

If security is a major concern, this parsing can be considered the safest option but with a slight performance penalty due to DOM operations that are inevitably costly.

var div = document.createElement('div');
div.textContent = 'I \u2764\uFE0F emoji!';
document.body.appendChild(div);

twemoji.parse(document.body);

var img = div.querySelector('img');

// note the div is preserved
img.parentNode === div; // true

img.src;        // https://twemoji.maxcdn.com/v/latest/72x72/2764.png
img.alt;        // \u2764\uFE0F
img.className;  // emoji
img.draggable;  // false

All other overloads described for string are available in exactly the same way for DOM parsing.

Object as parameter

Here's the list of properties accepted by the optional object that can be passed to the parse function.

  {
    callback: Function,   // default the common replacer
    attributes: Function, // default returns {}
    base: string,         // default MaxCDN
    ext: string,          // default ".png"
    className: string,    // default "emoji"
    size: string|number,  // default "72x72"
    folder: string        // in case it's specified
                          // it replaces .size info, if any
  }

callback

The function to invoke in order to generate image src(s).

By default it is a function like the following one:

function imageSourceGenerator(icon, options) {
  return ''.concat(
    options.base, // by default Twitter Inc. CDN
    options.size, // by default "72x72" string
    '/',
    icon,         // the found emoji as code point
    options.ext   // by default ".png"
  );
}

base

The default url is the same as twemoji.base, so if you modify the former, it will reflect as default for all parsed strings or nodes.

ext

The default image extension is the same as twemoji.ext which is ".png".

If you modify the former, it will reflect as default for all parsed strings or nodes.

className

The default class for each generated image is emoji. It is possible to specify a different one through this property.

size

The default asset size is the same as twemoji.size which is "72x72".

If you modify the former, it will reflect as default for all parsed strings or nodes.

folder

In case you don't want to specify a size for the image. It is possible to choose a folder, as in the case of SVG emoji.

twemoji.parse(genericNode, {
  folder: 'svg',
  ext: '.svg'
});

This will generate urls such https://twemoji.maxcdn.com/svg/2764.svg instead of using a specific size based image.

Utilities

Basic utilities / helpers to convert code points to JavaScript surrogates and vice versa.

twemoji.convert.fromCodePoint()

For a given HEX codepoint, returns UTF-16 surrogate pairs.

twemoji.convert.fromCodePoint('1f1e8');
 // "\ud83c\udde8"

twemoji.convert.toCodePoint()

For given UTF-16 surrogate pairs, returns the equivalent HEX codepoint.

 twemoji.convert.toCodePoint('\ud83c\udde8\ud83c\uddf3');
 // "1f1e8-1f1f3"

 twemoji.convert.toCodePoint('\ud83c\udde8\ud83c\uddf3', '~');
 // "1f1e8~1f1f3"

Tips

Inline Styles

If you'd like to size the emoji according to the surrounding text, you can add the following CSS to your stylesheet:

img.emoji {
   height: 1em;
   width: 1em;
   margin: 0 .05em 0 .1em;
   vertical-align: -0.1em;
}

This will make sure emoji derive their width and height from the font-size of the text they're shown with. It also adds just a little bit of space before and after each emoji, and pulls them upwards a little bit for better optical alignment.

UTF-8 Character Set

To properly support emoji, the document character set must be set to UTF-8. This can be done by including the following meta tag in the document <head>

<meta charset="utf-8">

Exclude Characters (V1)

To exclude certain characters from being replaced by twemoji.js, call twemoji.parse() with a callback, returning false for the specific unicode icon. For example:

twemoji.parse(document.body, {
    callback: function(icon, options, variant) {
        switch ( icon ) {
            case 'a9':      // © copyright
            case 'ae':      // ® registered trademark
            case '2122':    // ™ trademark
                return false;
        }
        return ''.concat(options.base, options.size, '/', icon, options.ext);
    }
});

Legacy API (V1)

If you're still using our V1 API, you can read our legacy documentation here.

Contributing

The contributing documentation can be found here.

Attribution Requirements

As an open source project, attribution is critical from a legal, practical and motivational perspective in our opinion. The graphics are licensed under the CC-BY 4.0 which has a pretty good guide on best practices for attribution.

However, we consider the guide a bit onerous and as a project, will accept a mention in a project README or an 'About' section or footer on a website. In mobile applications, a common place would be in the Settings/About section (for example, see the mobile Twitter application Settings->About->Legal section). We would consider a mention in the HTML/JS source sufficient also.

Community Projects

Committers and Contributors

  • Justine De Caires (Twitter)
  • Jason Sofonia (Twitter)
  • Bryan Haggerty (ex-Twitter)
  • Nathan Downs (ex-Twitter)
  • Tom Wuttke (ex-Twitter)
  • Andrea Giammarchi (ex-Twitter)
  • Joen Asmussen (WordPress)
  • Marcus Kazmierczak (WordPress)

The goal of this project is to simply provide emoji for everyone. We definitely welcome improvements and fixes, but we may not merge every pull request suggested by the community due to the simple nature of the project.

The rules for contributing are available in the CONTRIBUTING.md file.

Thank you to all of our contributors.

License

Copyright 2019 Twitter, Inc and other contributors

Code licensed under the MIT License: http://opensource.org/licenses/MIT

Graphics licensed under CC-BY 4.0: https://creativecommons.org/licenses/by/4.0/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].