mirror of
https://github.com/jakejarvis/imagemoji.git
synced 2026-09-11 22:55:31 -04:00
oops, forgot a few more readme fixes
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
[](https://www.npmjs.com/package/imagemoji)
|
[](https://www.npmjs.com/package/imagemoji)
|
||||||
[](LICENSE)
|
[](LICENSE)
|
||||||
|
|
||||||
Replaces emojis in strings or DOM nodes with corresponding images of your choosing. A barebones, mostly drop-in replacement for Twemoji's [`twemoji.parse()`](https://github.com/twitter/twemoji#twemojiparse---v1) (and heavily cherry-picked from Twitter's [original script](https://github.com/twitter/twemoji/blob/master/scripts/build.js)) to cut some cruft and save a few bytes.
|
Replaces emojis in strings or DOM nodes with corresponding images of your choosing. A barebones, mostly drop-in replacement for Twemoji's [`twemoji.parse()`](https://github.com/twitter/twemoji#twemojiparse---v1) (and heavily cherry-picked from Twitter's [original script](https://github.com/twitter/twemoji/blob/master/scripts/build.js) to cut some cruft and save a few bytes).
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@@ -12,30 +12,41 @@ Replaces emojis in strings or DOM nodes with corresponding images of your choosi
|
|||||||
|
|
||||||
```html
|
```html
|
||||||
<html>
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
/* All inserted images have class="emoji" */
|
||||||
|
img.emoji {
|
||||||
|
width: 30px;
|
||||||
|
height: 30px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p>I ❤️ emoji!</p>
|
<p>I 💩 emoji!</p>
|
||||||
|
|
||||||
<script src="https://unpkg.com/imagemoji/dist/imagemoji.min.js"></script>
|
<script src="https://unpkg.com/imagemoji/dist/imagemoji.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
imagemoji.parse(document.body);
|
imagemoji.parse(document.body);
|
||||||
//=> <p>I <img class="emoji" draggable="false" alt="❤️" src="https://twemoji.maxcdn.com/v/latest/svg/2764.svg"/> emoji!</p>
|
//=> <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`);
|
imagemoji.parse(document.body, (icon) => `/assets/emoji/${icon}.png`);
|
||||||
//=> <p>I <img class="emoji" draggable="false" alt="❤️" src="/assets/emoji/2764.png"/> emoji!</p>
|
//=> <p>I <img class="emoji" draggable="false" alt="💩" src="/assets/emoji/1f4a9.png"/> emoji!</p>
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
```
|
```
|
||||||
|
|
||||||
### via NPM
|
### via [NPM](https://www.npmjs.com/package/imagemoji)
|
||||||
|
|
||||||
`npm install imagemoji` or `yarn add imagemoji`
|
`npm install imagemoji` or `yarn add imagemoji`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { parse as parseEmoji } from "imagemoji";
|
import { parse as parseEmoji } from "imagemoji";
|
||||||
|
// or...
|
||||||
|
// const parseEmoji = require("imagemoji").parse;
|
||||||
|
|
||||||
parseEmoji(document.body);
|
parseEmoji(document.body);
|
||||||
parseEmoji(document.body, (icon) => `/assets/emoji/${icon}.png`);
|
parseEmoji(document.body, (icon) => `https://cdn.example.com/emoji/${icon}.svg`);
|
||||||
```
|
```
|
||||||
|
|
||||||
## API
|
## API
|
||||||
@@ -51,7 +62,7 @@ Either a plain string or a DOM node (e.g. `document.body`) containing emojis to
|
|||||||
#### how
|
#### how
|
||||||
|
|
||||||
Type: `function`\
|
Type: `function`\
|
||||||
Default: `(icon: string): string => "https://twemoji.maxcdn.com/v/latest/svg/" + icon + ".svg"`
|
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](https://github.com/twitter/twemoji#cdn-support).
|
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](https://github.com/twitter/twemoji#cdn-support).
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user