神刀安全网

Github emoji parsing done right

gh-emoji Github emoji parsing done right Github emoji parsing done right Github emoji parsing done right Github emoji parsing done right Github emoji parsing done right DEMO

Github emoji parsing done right :+1: :raised_hands: :wave: :clap: :hankey: :raising_hand: :smiling_imp: :smile: :baby: :bow: :person_with_blond_hair: :hamburger: :pizza: :ghost: :nail_care: :japanese_ogre: :bike: :steam_locomotive:

Gh-emoji aims to be the simplest Github emoji parser. It’s built on the top of theGithub 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(() => {   let editor = document.getElementById('editor');   let preview = document.getElementById('preview');    preview.innerHTML = parse(editor.value); });

Demo

Take a look at the online demo

Github emoji parsing done right

Methods

load

Fetch the emoji data from Github

import {load as loadEmojis} from 'gh-emoji';  loadEmojis().then((emojis) => {   console.log(emojis['+1'] === :+1: === 'https://assets-cdn.github.com/images/icons/emoji/unicode/1f44d.png?v6')  });

Returns Promise

parse

Converts text into parsed html containing the github emojis

parameters

  • text String
  • options Object
import {load, parse} from 'gh-emoji';  const text = 'Do you believe in :alien:...? :scream:'; load().then(() => {   console.log(parse(text) === 'Do you believe in :alien:...? :scream:');  });

Returns String

all

Return all existing emojis

import {load, all} from 'gh-emoji';  load().then(() => {   console.log(all());  });

Returns Object

getUrl

Return github image url of the emojiId

parameters

  • emojiId String
import {load, getUrl} from 'gh-emoji';  load().then(() => {   console.log(getUrl('apple') === 'https://assets-cdn.github.com/images/icons/emoji/unicode/1f34e.png?v6');  });

Returns String

exist

Return if the requested emoji exist

parameters

  • emojiId String
import {load, exist} from 'gh-emoji';  load().then(() => {   console.log(exist('foo') === false);    console.log(exist('smile') === true);  });

Returns Boolean

References

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Github emoji parsing done right

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮