Home

Awesome

gh-emoji Build Status npm version Bower version Dependency Status npm license DEMO

Github emoji parsing done right πŸ‘πŸ™ŒπŸ‘‹πŸ‘πŸ’©πŸ™‹πŸ˜ˆπŸ˜„πŸ‘ΆπŸ™‡πŸ‘±πŸ”πŸ•πŸ‘»πŸ’…πŸ‘ΉπŸš²πŸš‚

Gh-emoji aims to be the simplest Github emoji parser. It's built on the top of the Github Emoji Api with no dependencies and having a couple of functions as public api.

Installation

$ npm i gh-emoji

$ bower i gh-emoji

Usage

import { load, parse } from 'gh-emoji'

load().then(() => {
  const editor = document.getElementById('editor');
  const preview = document.getElementById('preview');

  preview.innerHTML = parse(editor.value);
});

Demo

Take a look at the online demo

API

all

src/index.js:89-91

Return all fetched emojis.

Examples

import { load as loadEmojis, all as allEmojis } from 'gh-emoji';

loadEmojis().then(() => {
  console.log(allEmojis()); // {emojiName: emojiImageTag}
});

Returns Object Object with emoji names as keys and generated image tags as values.

exist

src/index.js:108-116

Check if requested emoji exists.

Parameters

Examples

import { load as loadEmojis, exist as emojiExists } from 'gh-emoji';

loadEmojis().then(() => {
  console.log(emojiExists('foo')); // false
  console.log(emojiExists('smile')); // true
});

Returns Boolean

find

src/index.js:48-50

Return array with matched emojis in text.

Parameters

Examples

import { load as loadEmojis, find as findEmojis } from 'gh-emoji';

const text = 'Do you believe in :alien:...? :scream:';

loadEmojis().then((emojis) => {
  console.log(findEmojis(text)); // [':alien:', ':scream:']
});

Returns Array.<String> Array with matched emojis.

getUrl

src/index.js:132-140

Return github's image url of emoji.

Parameters

Examples

import { load as loadEmojis, getUrl } from 'gh-emoji';

loadEmojis().then(() => {
  console.log(getUrl('apple')); // 'https://assets-cdn.github.com/images/icons/emoji/unicode/1f34e.png?v6'
});

Returns String Image url of given emoji.

load

src/index.js:65-74

Fetch the emoji data from Github's api.

Examples

import { load as loadEmojis } from 'gh-emoji';

loadEmojis().then((emojis) => {
  console.log(emojis['+1']); // πŸ‘
});

Returns Promise.<Object> Promise which passes Object with emoji names as keys and generated image tags as values to callback.

parse

src/index.js:161-185

Parse text and replace emoji tags with actual emoji symbols.

Parameters

Examples

import { load as loadEmojis, parse } from 'gh-emoji';

const text = 'Do you believe in :alien:...? :scream:';

loadEmojis().then(() => {
  console.log(parse(text)) // 'Do you believe in πŸ‘½...? 😱';
});

Returns String Parsed text with emoji image tags in it.

References

Browser Support

<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_64x64.png" width="48px" height="48px" alt="Chrome logo"><img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_64x64.png" width="48px" height="48px" alt="Firefox logo"><img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_64x64.png" width="48px" height="48px" alt="Internet Explorer logo"><img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/opera/opera_64x64.png" width="48px" height="48px" alt="Opera logo"><img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_64x64.png" width="48px" height="48px" alt="Safari logo">
Latest βœ”Latest βœ”IE 9+ βœ”Latest βœ”Latest βœ”

License

MIT License Β© zzarcon