node package manager
Stop writing boring code. Discover, share, and reuse within your team. Create a free org ¬Ľ

node-emoji

node-emoji

NPM version (1.0.3) NPM Downloads Build Status Dependencies Code Climate https://paypal.me/DanielBugl/9

simple emoji support for node.js projects

node-emoji example

Installation

To install node-emoji, you need node.js and npm. ūüöÄ

Once you have that set-up, just run npm install --save node-emoji in your project directory. ūüöĘ

You're now ready to use emoji in your node projects! Awesome! ūü§ė

Usage

var emoji = require('node-emoji')
emoji.get('coffee') // returns the emoji code for coffee (displays emoji on terminals that support it) 
emoji.which(emoji.get('coffee')) // returns the string "coffee" 
emoji.get(':fast_forward:') // `.get` also supports github flavored markdown emoji (http://www.emoji-cheat-sheet.com/) 
emoji.emojify('I¬†:heart:¬†:coffee:!')¬†//¬†replaces¬†all¬†:emoji:¬†with¬†the¬†actual¬†emoji,¬†in¬†this¬†case:¬†returns¬†"I¬†‚̧ԳŹ¬†‚ėēÔłŹ!"¬†
emoji.random()¬†//¬†returns¬†a¬†random¬†emoji¬†+¬†key,¬†e.g.¬†`{¬†emoji:¬†'‚̧ԳŹ',¬†key:¬†'heart'¬†}`¬†
emoji.search('cof')¬†//¬†returns¬†an¬†array¬†of¬†objects¬†with¬†matching¬†emoji's.¬†`[{¬†emoji:¬†'‚ėēÔłŹ',¬†key:¬†'coffee'¬†},¬†{¬†emoji:¬†‚öį',¬†key:¬†'coffin'}]`¬†
emoji.unemojify('I¬†‚̧ԳŹ¬†ūüćē')¬†//¬†replaces¬†the¬†actual¬†emoji¬†with¬†:emoji:,¬†in¬†this¬†case:¬†returns¬†"I¬†:heart:¬†:pizza:"¬†
emoji.find('ūüćē')¬†//¬†Find¬†the¬†`pizza`¬†emoji,¬†and¬†returns¬†`({¬†emoji:¬†'ūüćē',¬†key:¬†'pizza'¬†})`;¬†
emoji.find('pizza')¬†//¬†Find¬†the¬†`pizza`¬†emoji,¬†and¬†returns¬†`({¬†emoji:¬†'ūüćē',¬†key:¬†'pizza'¬†})`;¬†
emoji.hasEmoji('ūüćē')¬†//¬†Validate¬†if¬†this¬†library¬†knows¬†an¬†emoji¬†like¬†`ūüćē`¬†
emoji.hasEmoji('pizza') // Validate if this library knowns a emoji with the name `pizza` 
emoji.strip('‚ö†ÔłŹ¬†„ÄįÔłŹ¬†„ÄįÔłŹ¬†low¬†disk¬†space')¬†//¬†Strips¬†the¬†string¬†from¬†emoji's,¬†in¬†this¬†case¬†returns:¬†"low¬†disk¬†space".¬†
emoji.replace('‚ö†ÔłŹ¬†„ÄįÔłŹ¬†„ÄįÔłŹ¬†low¬†disk¬†space',¬†(emoji)¬†=>¬†`${emoji.key}:`)¬†//¬†Replace¬†emoji's¬†by¬†callback¬†method:¬†"warning:¬†low¬†disk¬†space"¬†

Options

onMissing

emoji.emojify(str, onMissing)

As second argument, emojify takes an handler to parse unknown emojis. Provide a function to add your own handler:

var onMissing = function (name) {
  return name;
});
 
var emojified = emoji.emojify('I :unknown_emoji: :star: :another_one:', onMissing);
//¬†emojified:¬†I¬†unknown_emoji¬†‚≠źÔłŹ¬†another_one¬†

format

emoji.emojify(str, onMissing, format)

As third argument, emojify takes an handler to wrap parsed emojis. Provide a function to place emojis in custom elements, and to apply your custom styling:

var format = function (code, name) {
  return '<img alt="' + code + '" src="' + name + '.png" />';
});
 
var emojified = emoji.emojify('I :unknown_emoji: :star: :another_one:', null, format);
//¬†emojified:¬†I¬†<img¬†alt="‚̧ԳŹ"¬†src="heart.png"¬†/>¬†<img¬†alt="‚ėēÔłŹ"¬†src="coffee.png"¬†/>¬†

Adding new emoji

Emoji come from js-emoji (Thanks a lot ūüĎć). You can get a JSON file with all emoji here: https://raw.githubusercontent.com/omnidan/node-emoji/master/lib/emoji.json

To update the list or add custom emoji, clone this repository and put them into lib/emojifile.js. Then run npm run-script emojiparse in the project directory or node emojiparse in the lib directory. This should generate the new emoji.json file and output Done..

That's all, you now have more emoji you can use! ūüĎŹ

Support / Donations

If you want to support node-emoji development, please consider donating (it helps me keeping my projects active and alive!):