Giter Site home page Giter Site logo

node-emoji's Introduction

node-emoji

NPM version (1.0.3) NPM Downloads Build Status Dependencies 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 [email protected]

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"

Note: There are some emojis that have "-" in their name, for example "t-rex" and refrencing them directly like this (emoji.t-rex) won't work. In such cases, use the emoji.get('t-rex') syntax instead

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!):

  • Paypal: daniel.bugl@gmail.com
  • Bitcoin: 1J5eKsrAcPPLv5gPxSjSUkXnbJpkhndFgA

Special Thanks

... to Anand Chowdhary (@AnandChowdhary) and his company Pabio (https://github.com/pabio) for sponsoring this project via GitHub Sponsors!

License

FOSSA Status

node-emoji's People

Contributors

omnidan avatar emctackett avatar shivkanthb avatar ritikbanger avatar timruffles avatar watadarkstar avatar danielhilton avatar charpeni avatar dependabot[bot] avatar ngryman avatar gabrielcsapo avatar greenkeeperio-bot avatar jackiehluo avatar cooperka avatar merceyz avatar orkon avatar histoiredebabar avatar ritik-banger-biz4group avatar roopakv avatar ahanriat avatar fossabot avatar wtgtybhertgeghgtwtg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.