1
0
mirror of https://github.com/twitter/twemoji.git synced 2024-11-16 20:25:58 +00:00
twemoji/README.md

263 lines
11 KiB
Markdown
Raw Normal View History

# Twitter Emoji (Twemoji) [![Build Status](https://travis-ci.org/twitter/twemoji.svg?branch=gh-pages)](https://travis-ci.org/twitter/twemoji)
A simple library that provides standard Unicode [emoji](http://en.wikipedia.org/wiki/Emoji) support across all platforms.
**Twemoji v13.1** adheres to the [Unicode 13.0 spec](https://unicode.org/versions/Unicode13.0.0/) and supports the [Emoji 13.1 spec](https://www.unicode.org/reports/tr51/tr51-19.html). _We do not support custom emoji._
2016-03-01 18:25:41 +00:00
The Twemoji library offers support for **3,521** Unicode-defined emojis.
2016-03-01 18:25:41 +00:00
## Usage
2017-07-20 08:31:15 +00:00
### CDN Support
Gender equal emojis, new emojis for professions, and tweaks to existing emojis Includes additions to address gender equality, expanded professions, increased skin tone support, family representations, and minor modifications to some existing emojis. Many of the additions included are based on the [Emoji 4.0 draft spec](http://unicode.org/reports/tr51/proposed.html) and are subject to change prior to ratification. This change also moves the Twemoji version number to 2.2. ### New * Woman with turban * Blonde woman * Man getting face massage * Man getting haircut * Man frowning * Man pouting * Man gesturing not ok * Man gesturing ok * Man tipping hand * Man raising hand * Woman bowing deeply * Man facepalming * Man shrugging * Man doing cartwheel * Woman juggling * Man juggling * Woman walking * Woman running * Women wrestling * Woman playing water polo * Man playing handball * Men with bunny ears * Woman rowing boat * Woman golfing * Woman surfing * Woman swimming * Man with ball * Woman weight lifting * Woman biking * Woman mountain biking * Male health worker * Female health worker * Male judge * Female judge * Male pilot * Female pilot * Male farmer * Female farmer * Male cook * Female cook * Male student * Female student * Male singer * Female singer * Male artist * Female artist * Male teacher * Female teacher * Male factory worker * Female factory worker * Male technologist * Female technologist * Male office worker * Female office worker * Male mechanic * Female mechanic * Male scientist * Female scientist * Male astronaut * Female astronaut * Male firefighter * Female firefighter * Female police officer * Female construction worker * Female guard * Female sleuth * Family (man, boy) * Family (man, boy, boy) * Family (man, girl) * Family (man, girl, boy) * Family (man, girl, girl) * Family (woman, boy) * Family (woman, boy, boy) * Family (woman, girl) * Family (woman, girl, boy) * Family (woman, girl, girl) * UN Flag * Female sign * Male sign * Staff of aesculapius ### Modified * Man with turban * Person with ball * Family * Man and woman holding hands * Two men holding hands * Two women holding hands * Women with bunny ears * Man in business suit levitating * Sleeping accommodation * Skier * Snowboarder * Flag of Réunion * Grinning face with smiling eyes * Roasted sweet potato * Bird * Man with gua pi mao * Railway car * Face with rolling eyes * Astonished face
2016-09-20 17:29:59 +00:00
The folks over at [MaxCDN](https://www.maxcdn.com) have graciously provided CDN support.
Use the following in the `<head>` tag of your HTML document(s):
2016-03-01 18:25:41 +00:00
```html
2019-06-27 23:45:07 +00:00
<script src="https://twemoji.maxcdn.com/v/latest/twemoji.min.js" crossorigin="anonymous"></script>
2016-03-01 18:25:41 +00:00
```
This guarantees that you will always use the latest version of the library.
2016-03-01 18:25:41 +00:00
If, instead, you'd like to include the latest version explicitly, you can add the following tag:
```html
2021-05-28 01:30:22 +00:00
<script src="https://twemoji.maxcdn.com/v/13.1.0/twemoji.min.js" integrity="sha384-gPMUf7aEYa6qc3MgqTrigJqf4gzeO6v11iPCKv+AP2S4iWRWCoWyiR+Z7rWHM/hU" crossorigin="anonymous"></script>
```
### Download
2016-03-01 18:25:41 +00:00
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.
2016-03-01 18:25:41 +00:00
## API
Following are all the methods exposed in the `twemoji` namespace.
2016-03-01 18:25:41 +00:00
### 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](https://github.com/twitter/twemoji#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](https://github.com/twitter/twemoji/blob/master/LEGACY.md#string-parsing). 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*.
```js
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
2019-09-04 20:01:26 +00:00
img.src; // https://twemoji.maxcdn.com/v/latest/72x72/2764.png
img.alt; // \u2764\uFE0F
2014-11-07 23:36:32 +00:00
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.
```js
{
2014-11-07 23:36:32 +00:00
callback: Function, // default the common replacer
2015-04-11 13:49:52 +00:00
attributes: Function, // default returns {}
2014-11-07 23:36:32 +00:00
base: string, // default MaxCDN
ext: string, // default ".png"
2014-11-08 00:21:51 +00:00
className: string, // default "emoji"
size: string|number, // default "72x72"
2014-11-08 00:21:51 +00:00
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:
```js
2015-01-02 22:04:33 +00:00
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.
2014-11-08 00:21:51 +00:00
##### size
2019-09-04 18:55:29 +00:00
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
2014-11-08 00:21:51 +00:00
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.
2014-11-08 00:21:51 +00:00
```js
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.
2014-11-08 00:21:51 +00:00
## 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.
```js
twemoji.convert.fromCodePoint('1f1e8');
// "\ud83c\udde8"
```
### twemoji.convert.toCodePoint()
For given UTF-16 surrogate pairs, returns the equivalent HEX codepoint.
```js
twemoji.convert.toCodePoint('\ud83c\udde8\ud83c\uddf3');
// "1f1e8-1f1f3"
2016-06-07 16:28:35 +00:00
twemoji.convert.toCodePoint('\ud83c\udde8\ud83c\uddf3', '~');
// "1f1e8~1f1f3"
```
2014-11-08 00:21:51 +00:00
## 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:
```css
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>`
```html
<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:
```js
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](https://github.com/twitter/twemoji/tree/master/LEGACY.md).
## Contributing
The contributing documentation can be found [here](https://github.com/twitter/twemoji/tree/master/CONTRIBUTING.md).
## 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](https://wiki.creativecommons.org/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.
2014-11-11 03:50:52 +00:00
## Community Projects
* [Twemoji Amazing](https://github.com/SebastianAigner/twemoji-amazing) by [@SebastianAigner](https://github.com/SebastianAigner): Use Twemoji using CSS classes (like [Font Awesome](http://fortawesome.github.io/Font-Awesome/)).
* [Twemoji Ruby](https://github.com/jollygoodcode/twemoji) by [@JollyGoodCode](https://twitter.com/jollygoodcode): Use Twemoji in Ruby.
2015-12-11 11:53:29 +00:00
* [Twemoji for Pencil](https://github.com/nathanielw/Twemoji-for-Pencil) by [@Nathanielnw](https://twitter.com/nathanielnw): Use Twemoji in Pencil.
* [FrwTwemoji - Twemoji in dotnet](http://github.frenchw.net/FrwTwemoji/) by [@FrenchW](https://twitter.com/frenchw): Use Twemoji in any dotnet project (C#, asp.net ...).
* [Emojiawesome - Twemoji for Yellow](https://github.com/datenstrom/yellow-extensions/tree/master/source/emojiawesome) by [@datenstrom](https://github.com/datenstrom/): Use Twemoji on your website.
2016-07-03 14:21:35 +00:00
* [EmojiPanel for Twitter](https://github.com/danbovey/EmojiPanel) by [@danielbovey](https://twitter.com/danielbovey/status/749580050274582528): Insert Twemoji into your tweets on twitter.com.
* [Twitter Color Emoji font](https://github.com/eosrei/twemoji-color-font) by [@bderickson](https://twitter.com/bderickson): Use Twemoji as your system default font on Linux & OS X.
2016-12-09 18:15:13 +00:00
* [Emojica](https://github.com/xoudini/emojica) by [@xoudini](https://twitter.com/xoudini): An iOS framework allowing you to replace all standard emoji in strings with Twemoji.
2020-05-21 22:34:35 +00:00
* [gwt-twemoji](https://github.com/phpmonkeys-de/gwt-twemoji) by [@nbartels](https://github.com/nbartels): Use Twemoji in GWT
* [JavaFXEmojiTextFlow](https://github.com/pavlobu/emoji-text-flow-javafx) by [@pavlobu](https://github.com/pavlobu): A JavaFX library allowing you to replace all standard emoji in extended EmojiTextFlow with Twemoji.
* [Vue Twemoji Picker](https://github.com/kevinfaguiar/vue-twemoji-picker) by [@kevinfaguiar](https://github.com/kevinfaguiar): A fast plug-n-play Twemoji Picker (+textarea for Twemoji rendering) for Vue.
* [Unmaintained] [Twemoji Awesome](http://ellekasai.github.io/twemoji-awesome/) by [@ellekasai](https://twitter.com/ellekasai/): Use Twemoji using CSS classes (like [Font Awesome](http://fortawesome.github.io/Font-Awesome/)).
2020-12-16 01:29:40 +00:00
* [EmojiOnRoku](https://github.com/KasperGam/EmojiOnRoku) by [@KasperGam](https://github.com/KasperGam): Use Twemoji on Roku!
2021-03-02 00:51:57 +00:00
* [LaTeX Twemoji](https://gitlab.com/rossel.jost/latex-twemojis) by [@rossel.jost](https://gitlab.com/rossel.jost): Use Twemoji in LaTeX.
* [PHP Twemoji](https://github.com/Astrotomic/php-twemoji) by [@Astrotomic](https://github.com/Astrotomic): Use twemoji within your PHP website project's by replacing standard Emoji with twemoji urls.
2014-11-11 03:50:52 +00:00
## Committers and Contributors
2020-05-09 00:17:41 +00:00
* Justine De Caires (Twitter)
* Jason Sofonia (Twitter)
* Bryan Haggerty (ex-Twitter)
* Nathan Downs (ex-Twitter)
Unicode 10.0/Emoji 5.0 additions + modifications to a subset of existing emojis Adds new emojis based on the finalized [Emoji 5.0 spec](http://unicode.org/reports/tr51/index.html). Modifications to some existing emojis included as well, see change list below for specifics. This change also moves the Twemoji version number to 2.3. ### New * Star-Struck * Face With Raised Eyebrow * Exploding Head * Crazy Face * Face With Symbols Over Mouth * Face Vomiting * Shushing Face * Face With Hand Over Mouth * Face With Monocle * Child * Adult * Older Adult * Woman With Headscarf * Bearded Person * Breast-Feeding * Mage * Woman Mage * Man Mage * Fairy * Woman Fairy * Man Fairy * Vampire * Woman Vampire * Man Vampire * Merperson * Mermaid * Merman * Elf * Woman Elf * Man Elf * Genie * Woman Genie * Man Genie * Zombie * Woman Zombie * Man Zombie * Person in Steamy Room * Woman in Steamy Room * Man in Steamy Room * Person Climbing * Woman Climbing * Man Climbing * Person in Lotus Position * Woman in Lotus Position * Man in Lotus Position * Love-You Gesture * Palms Up Together * Brain * Orange Heart * Scarf * Gloves * Coat * Socks * Billed Cap * Zebra * Giraffe * Hedgehog * Sauropod * T-Rex * Cricket * Coconut * Broccoli * Pretzel * Cut of Meat * Sandwich * Bowl With Spoon * Canned Food * Dumpling * Fortune Cookie * Takeout Box * Pie * Cup With Straw * Chopsticks * Flying Saucer * Sled * Curling Stone * Flag for England * Flag for Scotland * Flag for Wales ### Modified * Index Pointing Up * Person Facepalming * Man in Business Suit Levitating * Person Getting Massage * Hamburger * Ogre * Full Moon With Face * New Moon Face * First Quarter Moon With Face * Last Quarter Moon With Face * Japanese "vacancy" button
2017-05-23 21:10:35 +00:00
* 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](https://github.com/twitter/twemoji/graphs/contributors).
## License
Twemoji 12.0 update Adds support for the new emojis included in Unicode 12.0/Emoji 12.0. Additions to Twemoji with this release include: * Yawning Face * Brown Heart * White Heart * Pinching Hand * Mechanical Arm * Mechanical Leg * Ear With Hearing Aid * Deaf Person * Deaf Man * Deaf Woman * Person Standing * Man Standing * Woman Standing * Person Kneeling * Man Kneeling * Woman Kneeling * Man With Probing Cane * Woman With Probing Cane * Man in Motorized Wheelchair * Woman in Motorized Wheelchair * Man in Manual Wheelchair * Woman in Manual Wheelchair * People Holding Hands (skin tone combinations) * Women Holding Hands (skin tone combinations) * Woman and Man Holding Hands (skin tone combinations) * Men Holding Hands (skin tone combinations) * Orangutan * Guide Dog * Service Dog * Sloth * Otter * Skunk * Flamingo * Garlic * Onion * Waffle * Falafel * Butter * Oyster * Beverage Box * Maté * Ice Cube * Hindu Temple * Manual Wheelchair * Motorized Wheelchair * Auto Rickshaw * Parachute * Ringed Planet * Diving Mask * Yo-Yo * Kite * Safety Vest * Sari * One-Piece Swimsuit * Briefs * Shorts * Ballet Shoes * Banjo * Diya Lamp * Axe * Probing Cane * Drop of Blood * Adhesive Bandage * Stethoscope * Chair * Razor * Orange Circle * Yellow Circle * Green Circle * Purple Circle * Brown Circle * Red Square * Orange Square * Yellow Square * Green Square * Blue Square * Purple Square * Brown Square Plus an additional tweak to the guitar to make it actually a guitar and not a bass guitar.
2019-04-04 22:42:48 +00:00
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/>