Socket
Socket
Sign inDemoInstall

node-emoji

Package Overview
Dependencies
1
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-emoji

simple emoji support for node.js projects


Version published
Maintainers
1
Install size
206 kB
Created

Package description

What is node-emoji?

The node-emoji package provides a simple way to add Unicode emoji support to your Node.js applications. It allows you to easily include emoji characters in your strings and manipulate them as needed.

What are node-emoji's main functionalities?

Get emoji by name

Retrieve an emoji character using its name (alias).

const emoji = require('node-emoji');
console.log(emoji.get('coffee')); // outputs the coffee emoji

Find emoji in a string

Search for and return information about an emoji within a string.

const emoji = require('node-emoji');
console.log(emoji.find('I :heart: node-emoji!')); // finds and returns the heart emoji object

Replace emoji names with characters in a string

Convert emoji aliases in a string to their corresponding emoji characters.

const emoji = require('node-emoji');
console.log(emoji.emojify('I :heart: node-emoji!')); // replaces the :heart: alias with the actual heart emoji character

Replace characters with emoji names in a string

Convert emoji characters in a string to their corresponding emoji aliases.

const emoji = require('node-emoji');
console.log(emoji.unemojify('I ❤️ node-emoji!')); // replaces the heart emoji character with its alias :heart:

Random emoji

Get a random emoji object, which includes the emoji character and its alias.

const emoji = require('node-emoji');
console.log(emoji.random()); // returns a random emoji object

Other packages similar to node-emoji

Readme

Source

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

Help wanted: We are looking for volunteers to maintain this project, if you are interested, feel free to contact me at me@omnidan.net

Installation

To install node-emoji, you need node.js and npm. :rocket:

Once you have that set-up, just run npm install --save node-emoji in your project directory. :ship:

You're now ready to use emoji in your node projects! Awesome! :metal:

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 :thumbsup:). 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! :clap:

Support / Donations

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

Keywords

FAQs

Last updated on 15 Feb 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc