Coder Social home page Coder Social logo

emoji-node's Introduction

emoji-node

simple emoji support for node.js projects

Installation

To install emoji-node, you need node.js and npm. ๐Ÿš€

Once you have that set-up, just run npm install --save emoji-node or yarn add emoji-node in your project directory. ๐Ÿšข

You're now ready to use emoji in your node projects! Awesome! ๐Ÿค˜

Usage

var emoji = require('emoji-node')
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.get('heart') //โค๏ธ
emoji.get(':)') //๐Ÿ˜„
emoji.emojify('I :heart: :coffee:!') // replaces all :emoji: with the actual emoji, in this case: returns "I โค๏ธ โ˜•๏ธ!"
emoji.emojify(":-) :* <3 ^_^ >:o (y) -_- :smile: ;) :P O:) :/ :'( 3:)") // replace almost all shorthand emoji support ๐Ÿ˜„ ๐Ÿ˜˜ โค๏ธ ๐Ÿ˜™ ๐Ÿ˜† ๐Ÿ‘ ๐Ÿ˜‘ ๐Ÿ˜„ ๐Ÿ˜‰ ๐Ÿ˜› ๐Ÿ‘ผ ๐Ÿ˜• ๐Ÿ˜ข ๐Ÿ˜ˆ
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/wadehrarshpreet/emoji-node/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! ๐Ÿ‘

emoji-node's People

Contributors

ahanriat avatar cooperka avatar gabrielcsapo avatar greenkeeperio-bot avatar histoiredebabar avatar jackiehluo avatar ngryman avatar omnidan avatar orkon avatar shivkanthb avatar timruffles avatar wadehrarshpreet avatar wtgtybhertgeghgtwtg avatar

Stargazers

 avatar

Watchers

 avatar  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.