mirror of
https://github.com/jakejarvis/imagemoji.git
synced 2025-04-26 13:38:27 -04:00
![dependabot[bot]](/assets/img/avatar_default.png)
Bumps [microbundle](https://github.com/developit/microbundle) from 0.14.1 to 0.15.1. - [Release notes](https://github.com/developit/microbundle/releases) - [Changelog](https://github.com/developit/microbundle/blob/master/CHANGELOG.md) - [Commits](https://github.com/developit/microbundle/compare/v0.14.1...v0.15.1) --- updated-dependencies: - dependency-name: microbundle dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
🖼️ imagemoji
Replaces emojis in strings or DOM nodes with corresponding images of your choosing. A barebones, mostly drop-in replacement for Twemoji's twemoji.parse()
(and heavily cherry-picked from Twitter's original script to cut some cruft and save a few bytes).
Usage
via unpkg
<html>
<head>
<style>
/* All inserted images have class="emoji" */
img.emoji {
width: 30px;
height: 30px;
}
</style>
</head>
<body>
<p>I 💩 emoji!</p>
<script src="https://unpkg.com/imagemoji/dist/imagemoji.min.js"></script>
<script>
imagemoji.parse(document.body);
//=> <p>I <img class="emoji" draggable="false" alt="💩" src="https://twemoji.maxcdn.com/v/latest/svg/1f4a9.svg"/> emoji!</p>
imagemoji.parse(document.body, (icon) => `/assets/emoji/${icon}.png`);
//=> <p>I <img class="emoji" draggable="false" alt="💩" src="/assets/emoji/1f4a9.png"/> emoji!</p>
</script>
</body>
</html>
via NPM
npm install imagemoji
or yarn add imagemoji
import { parse as parseEmoji } from "imagemoji";
// or...
// const parseEmoji = require("imagemoji").parse;
parseEmoji(document.body);
parseEmoji(document.body, (icon) => `https://cdn.example.com/emoji/${icon}.svg`);
API
.parse(what, how?)
what
Type: string
or Node
Either a plain string or a DOM node (e.g. document.body
) containing emojis to replace with <img>
s.
how
Type: function
Default: (icon) => "https://twemoji.maxcdn.com/v/latest/svg/" + icon + ".svg"
A callback function to determine the image source URL of a given emoji codepoint (always lowercase, e.g. 1f4a9
for 💩, and variations are joined with dashes, e.g. 1f468-200d-1f4bb
for 👨💻). Defaults to pulling SVGs from the Twemoji CDN.
License
MIT
Languages
TypeScript
100%