Gathering detailed insights and metrics for @twemoji/api
Gathering detailed insights and metrics for @twemoji/api
Gathering detailed insights and metrics for @twemoji/api
Gathering detailed insights and metrics for @twemoji/api
npm install @twemoji/api
Typescript
Module System
Node Version
NPM Version
Twemoji v16.0.1 update
Updated on Apr 14, 2025
Twemoji v16.0.0 update
Updated on Apr 14, 2025
Twemoji 15.1.0 update
Updated on Mar 28, 2024
Twemoji 15.0.3 update
Updated on Dec 15, 2023
Twemoji v15 (15.0.2) update
Updated on Dec 04, 2023
Twemoji 14.1.2 update
Updated on Mar 22, 2023
HTML (73.93%)
JavaScript (25.78%)
Shell (0.29%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1,304 Stars
492 Commits
82 Forks
22 Watchers
12 Branches
11 Contributors
Updated on Jul 15, 2025
Latest Version
16.0.1
Package Id
@twemoji/api@16.0.1
Unpacked Size
149.76 kB
Size
27.67 kB
File Count
9
NPM Version
10.2.3
Node Version
21.2.0
Published on
Apr 14, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
4
3
A simple library that provides standard Unicode emoji support across all platforms.
Twemoji v16.0 adheres to the Unicode 16.0 spec and supports the Emoji 16.0 spec. We do not support custom emoji.
The Twemoji library offers support for all Unicode-defined emoji which are recommended for general interchange (RGI).
Run the following inside of your already-initialized project:
1npm install @twemoji/api
Default CDN support is provided via jsDelivr.
Use the following in the <head>
tag of your HTML document(s):
1<script src="https://cdn.jsdelivr.net/npm/@twemoji/api@latest/dist/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:
1<script src="https://cdn.jsdelivr.net/npm/@twemoji/api@16.0.1/dist/twemoji.min.js" integrity="sha384-D6GSzpW7fMH86ilu73eB95ipkfeXcMPoOGVst/L04yqSSe+RTUY0jXcuEIZk0wrT" crossorigin="anonymous"></script>
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.
Following are all the methods exposed in the twemoji
namespace.
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.
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.
1var div = document.createElement('div'); 2div.textContent = 'I \u2764\uFE0F emoji!'; 3document.body.appendChild(div); 4 5twemoji.parse(document.body); 6 7var img = div.querySelector('img'); 8 9// note the div is preserved 10img.parentNode === div; // true 11 12img.src; // https://cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets/72x72/2764.png 13img.alt; // \u2764\uFE0F 14img.className; // emoji 15img.draggable; // false 16
All other overloads described for string
are available in exactly the same way for DOM parsing.
Here's the list of properties accepted by the optional object that can be passed to the parse
function.
1 { 2 callback: Function, // default the common replacer 3 attributes: Function, // default returns {} 4 base: string, // default jsDelivr 5 ext: string, // default ".png" 6 className: string, // default "emoji" 7 size: string|number, // default "72x72" 8 folder: string // in case it's specified 9 // it replaces .size info, if any 10 }
The function to invoke in order to generate image src
(s).
By default it is a function like the following one:
1function imageSourceGenerator(icon, options) { 2 return ''.concat( 3 options.base, // by default jsDelivr 4 options.size, // by default "72x72" string 5 '/', 6 icon, // the found emoji as code point 7 options.ext // by default ".png" 8 ); 9}
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.
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.
The default class
for each generated image is emoji
. It is possible to specify a different one through this property.
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.
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.
1twemoji.parse(genericNode, { 2 folder: 'svg', 3 ext: '.svg' 4});
This will generate urls such https://cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets/svg/2764.svg
instead of using a specific size based image.
Basic utilities / helpers to convert code points to JavaScript surrogates and vice versa.
For a given HEX codepoint, returns UTF-16 surrogate pairs.
1twemoji.convert.fromCodePoint('1f1e8'); 2 // "\ud83c\udde8"
For given UTF-16 surrogate pairs, returns the equivalent HEX codepoint.
1 twemoji.convert.toCodePoint('\ud83c\udde8\ud83c\uddf3'); 2 // "1f1e8-1f1f3" 3 4 twemoji.convert.toCodePoint('\ud83c\udde8\ud83c\uddf3', '~'); 5 // "1f1e8~1f1f3"
If you'd like to size the emoji according to the surrounding text, you can add the following CSS to your stylesheet:
1img.emoji { 2 height: 1em; 3 width: 1em; 4 margin: 0 .05em 0 .1em; 5 vertical-align: -0.1em; 6}
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.
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>
1<meta charset="utf-8">
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:
1twemoji.parse(document.body, { 2 callback: function(icon, options, variant) { 3 switch ( icon ) { 4 case 'a9': // © copyright 5 case 'ae': // ® registered trademark 6 case '2122': // ™ trademark 7 return false; 8 } 9 return ''.concat(options.base, options.size, '/', icon, options.ext); 10 } 11});
If you're still using our V1 API, you can read our legacy documentation here.
The contributing documentation can be found here.
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.
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.
See the LICENSE and LICENSE-GRAPHICS files for full license texts.
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/
No vulnerabilities found.
No security vulnerabilities found.