function _get(emoji) { if (Emoji.emoji.hasOwnProperty(emoji)) { return Emoji.emoji[emoji]; } return ':' + emoji + ':'; }
...
* get emoji code from :emoji: string or name
* @param {string} emoji
* @return {string}
*/
Emoji.get = function get(emoji) {
emoji = trim(emoji);
return Emoji._get(emoji);
};
/**
* get emoji name from code
* @param {string} emoji_code
* @return {string}
*/
...
function emojify(str, on_missing) { if (!str) return ''; return str.split(parser) // parse emoji via regex .map(function parseEmoji(s, i) { // every second element is an emoji, e.g. "test :fast_forward:" -> [ "test ", "fast_forward" ] if (i % 2 === 0) return s; var emoji = Emoji._get(s); if (emoji.indexOf(':') > -1 && typeof on_missing === 'function') { return on_missing(emoji.substr(1, emoji.length-2)); } return emoji; }) .join('') // convert back to string ; }
...
## Usage
```javascript
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'}]`
```
## 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
...
function get(emoji) { emoji = trim(emoji); return Emoji._get(emoji); }
...
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
```javascript
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 ❤️ ☕️!
x22;
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'}]`
```
...
function random() { var emojiKeys = Object.keys(Emoji.emoji); var randomIndex = Math.floor(Math.random() * emojiKeys.length); var key = emojiKeys[randomIndex]; var emoji = Emoji._get(key); return {key: key, emoji: emoji}; }
...
## Usage
```javascript
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 ❤️ ☕️!
x22;
emoji.random() // returns a random emoji + key, e.g. `{ emoji: '❤️', key:
x27;heart' }`
emoji.search('cof') // returns an array of objects with matching emoji's. `[{ emoji: '☕️', key: 'coffee
' }, { emoji: ⚰', key: 'coffin'}]`
```
## 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`.
...
function search(str) { var emojiKeys = Object.keys(Emoji.emoji); var matcher = trim(str) var matchingKeys = emojiKeys.filter(function(key) { return key.toString().indexOf(matcher) === 0; }); return matchingKeys.map(function(key) { return { key: key, emoji: Emoji._get(key), }; }); }
...
```javascript
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 ❤️ ☕️!
x22;
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'}]`
```
## 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.
...
function which(emoji_code) { for (var prop in Emoji.emoji) { if (Emoji.emoji.hasOwnProperty(prop)) { if (Emoji.emoji[prop].codePointAt() === emoji_code.codePointAt()) { return prop; } } } }
...
You're now ready to use emoji in your node projects! Awesome! :metal:
## Usage
```javascript
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 ❤️ ☕️!
x22;
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'}]`
```
## Adding new emoji
...
function _get(emoji) { if (Emoji.emoji.hasOwnProperty(emoji)) { return Emoji.emoji[emoji]; } return ':' + emoji + ':'; }
...
* get emoji code from :emoji: string or name
* @param {string} emoji
* @return {string}
*/
Emoji.get = function get(emoji) {
emoji = trim(emoji);
return Emoji._get(emoji);
};
/**
* get emoji name from code
* @param {string} emoji_code
* @return {string}
*/
...
function emojify(str, on_missing) { if (!str) return ''; return str.split(parser) // parse emoji via regex .map(function parseEmoji(s, i) { // every second element is an emoji, e.g. "test :fast_forward:" -> [ "test ", "fast_forward" ] if (i % 2 === 0) return s; var emoji = Emoji._get(s); if (emoji.indexOf(':') > -1 && typeof on_missing === 'function') { return on_missing(emoji.substr(1, emoji.length-2)); } return emoji; }) .join('') // convert back to string ; }
...
## Usage
```javascript
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'}]`
```
## 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
...
function get(emoji) { emoji = trim(emoji); return Emoji._get(emoji); }
...
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
```javascript
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 ❤️ ☕️!
x22;
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'}]`
```
...
function random() { var emojiKeys = Object.keys(Emoji.emoji); var randomIndex = Math.floor(Math.random() * emojiKeys.length); var key = emojiKeys[randomIndex]; var emoji = Emoji._get(key); return {key: key, emoji: emoji}; }
...
## Usage
```javascript
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 ❤️ ☕️!
x22;
emoji.random() // returns a random emoji + key, e.g. `{ emoji: '❤️', key:
x27;heart' }`
emoji.search('cof') // returns an array of objects with matching emoji's. `[{ emoji: '☕️', key: 'coffee
' }, { emoji: ⚰', key: 'coffin'}]`
```
## 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`.
...
function search(str) { var emojiKeys = Object.keys(Emoji.emoji); var matcher = trim(str) var matchingKeys = emojiKeys.filter(function(key) { return key.toString().indexOf(matcher) === 0; }); return matchingKeys.map(function(key) { return { key: key, emoji: Emoji._get(key), }; }); }
...
```javascript
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 ❤️ ☕️!
x22;
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'}]`
```
## 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.
...
function which(emoji_code) { for (var prop in Emoji.emoji) { if (Emoji.emoji.hasOwnProperty(prop)) { if (Emoji.emoji[prop].codePointAt() === emoji_code.codePointAt()) { return prop; } } } }
...
You're now ready to use emoji in your node projects! Awesome! :metal:
## Usage
```javascript
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 ❤️ ☕️!
x22;
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'}]`
```
## Adding new emoji
...