README.md

November 18, 2023 ยท View on GitHub

node-emoji

Friendly emoji lookups and parsing utilities for Node.js. ๐Ÿ’–

All Contributors: 32 ๐Ÿ‘ช Codecov Test Coverage Contributor Covenant License: MIT Sponsor: On GitHub Style: Prettier TypeScript: Strict npm package version Contributor Covenant

node-emoji provides a fun, straightforward interface on top of the following excellent libraries:

  • emojilib: provides a list of emojis and keyword search on top of it
  • skin-tone: parses out base emojis from skin tones

Install

npm install node-emoji

2.0 Release ๐Ÿš€

This is the new 2.0 release of node-emoji, supporting ESM, new emoji and a new API.

If you want to use the old version, please check out the legacy branch.

Usage

import * as emoji from 'node-emoji'

emoji.emojify('I :heart: :coffee:!') // 'I โค๏ธ โ˜•๏ธ!'

emoji.find('heart') // { emoji: 'โค', name: 'heart' }
emoji.find('โค๏ธ') // { emoji: 'โค', name: 'heart' }

emoji.get('unicorn') // ๐Ÿฆ„
emoji.get(':unicorn:') // ๐Ÿฆ„

emoji.has(':pizza:') // true
emoji.has('๐Ÿ•') // true
emoji.has('unknown') // false

emoji.random() // { name: 'house', emoji: '๐Ÿ ' }

emoji.replace('I โค๏ธ coffee!', 'love', { preserveSpaces: true }) // 'I love coffee!'

emoji.search(':uni:') // [ { emoji: '๐Ÿฆ„', name: 'unicorn' }, ... ]

emoji.strip('I โค๏ธ coffee!') // 'I coffee!'

emoji.unemojify('๐Ÿ• for ๐Ÿ’ƒ') // ':pizza: for :dancer:'

emoji.which('๐Ÿฆ„') // 'unicorn'

API

emoji.emojify(input, options?)

Parse all markdown-encoded emojis in a string.

Parameters:

  1. input (string): The input string containing the markdown-encoding emojis.
  2. options (optional):
    • fallback (string; default: ""): The string to fallback to if an emoji was not found.
    • format (() => (emoji: string, part: string, string: string) => string; default: value => value): Add a middleware layer to modify each matched emoji after parsing.
import * as emoji from 'node-emoji'

console.log(emoji.emojify('The :unicorn: is a fictitious animal.'))
// 'The ๐Ÿฆ„ is a fictitious animal.'

emoji.find(emoji)

Get the name and character of an emoji.

Parameters:

  1. emoji (string): The emoji to get the data of.
import * as emoji from 'node-emoji'

console.log(emoji.find('๐Ÿฆ„'))
// { name: 'unicorn', emoji: '๐Ÿฆ„' }

emoji.get(name)

Get an emoji from an emoji name.

Parameters:

  1. name (string): The name of the emoji to get.
import * as emoji from 'node-emoji'

console.log(emoji.get('unicorn'))
// '๐Ÿฆ„'

emoji.has(emoji)

Check if this library supports a specific emoji.

Parameters:

  1. emoji (string): The emoji to check.
import * as emoji from 'node-emoji'

console.log(emoji.has('๐Ÿฆ„'))
// true

emoji.random()

Get a random emoji.

import * as emoji from 'node-emoji'

console.log(emoji.random())
// { name: 'unicorn', emoji: '๐Ÿฆ„' }

emoji.replace(input, replacement)

Replace the emojis in a string.

Parameters:

  • input (string): The input string.
  • replacement (string | (emoji: string, index: number, string: string) => string): The character to replace the emoji with. Can be either a string or a callback that returns a string.
import * as emoji from 'node-emoji'

console.log(emoji.replace('The ๐Ÿฆ„ is a fictitious animal.', 'unicorn'))
// 'The unicorn is a fictitious animal.'

emoji.search(keyword)

Search for emojis containing the provided name in their name.

Parameters:

  1. keyword (string): The keyword to search for.
import * as emoji from 'node-emoji'

console.log(emoji.search('honey'))
// [ { name: 'honeybee', emoji: '๐Ÿ' }, { name: 'honey_pot', emoji: '๐Ÿฏ' } ]

emoji.strip(input, options?)

Remove all of the emojis from a string.

Parameters:

  1. input (string): The input string to strip the emojis from.

  2. options (optional):

    • preserveSpaces (boolean): Whether to keep the extra space after a stripped emoji.
import * as emoji from 'node-emoji'

console.log(emoji.strip('๐Ÿฆ„ The unicorn is a fictitious animal.'))
// 'The unicorn is a fictitious animal.'

console.log(
  emoji.strip('๐Ÿฆ„ The unicorn is a fictitious animal.', {
    preserveSpaces: true,
  }),
)
// ' The unicorn is a fictitious animal.'

emoji.unemojify(input)

Convert all emojis in a string to their markdown-encoded counterparts.

Parameters:

  1. input (string): The input string containing the emojis.
import * as emoji from 'node-emoji'

console.log(emoji.unemojify('The ๐Ÿฆ„ is a fictitious animal.'))
// 'The :unicorn: is a fictitious animal.'

emoji.which(emoji, options?)

Get an emoji name from an emoji.

Parameters:

  1. emoji (string): The emoji to get the name of.
  2. options (optional):
    • markdown (boolean; default: false): Whether to return a ":emoji:" string instead of "emoji"
import * as emoji from 'node-emoji'

console.log(emoji.which('๐Ÿฆ„'))
// 'unicorn'

Development

See .github/Development.md.

License

FOSSA Status

Special Thanks

...to Anand Chowdhary (@AnandChowdhary) and his company Pabio for sponsoring this project via GitHub Sponsors!

Contributors

./cยฒ
./cยฒ

๐Ÿ’ป
Adam Skoufis
Adam Skoufis

๐Ÿ’ป
Adrian Carolli
Adrian Carolli

๐Ÿ’ป
Alex Litel
Alex Litel

๐Ÿ’ป
Alex Rudenko
Alex Rudenko

๐Ÿ’ป
Antoine Hanriat
Antoine Hanriat

๐Ÿ’ป
Daniel Bugl
Daniel Bugl

๐Ÿ› ๐Ÿ’ป ๐Ÿ” ๐Ÿค” ๐Ÿš‡ ๐Ÿ”ง ๐Ÿšง
Daniel Hilton
Daniel Hilton

๐Ÿ’ป
Elizabeth
Elizabeth

๐Ÿ’ป ๐Ÿšง
Gabriel Csapo
Gabriel Csapo

๐Ÿ’ป
Greenkeeper
Greenkeeper

๐Ÿ’ป
Josh Goldberg โœจ
Josh Goldberg โœจ

๐Ÿ”ง ๐Ÿ’ป ๐Ÿš‡ ๐Ÿšง
Kevin Cooper
Kevin Cooper

๐Ÿ’ป
Kristoffer K.
Kristoffer K.

๐Ÿ’ป
Ludo Renzetti
Ludo Renzetti

๐Ÿ’ป
Nicolas Charpentier
Nicolas Charpentier

๐Ÿšง
Nicolas Gryman
Nicolas Gryman

๐Ÿ’ป
Paul Barber
Paul Barber

๐Ÿ’ป
Richie Bendall
Richie Bendall

๐Ÿ’ป ๐Ÿšง
Ritik Banger
Ritik Banger

๐Ÿ’ป
Roopak Venkatakrishnan
Roopak Venkatakrishnan

๐Ÿ’ป
Shivkanth Bagavathy
Shivkanth Bagavathy

๐Ÿ’ป
Siddharth Batra
Siddharth Batra

๐Ÿ’ป
Stephan Meijer
Stephan Meijer

๐Ÿ’ป
Thomas Beverley
Thomas Beverley

๐Ÿ›
Tim Ruffles
Tim Ruffles

๐Ÿ’ป
Todd Mazierski
Todd Mazierski

๐Ÿ›
fossabot
fossabot

๐Ÿ’ป
goodjun
goodjun

๐Ÿ›
jackie luo
jackie luo

๐Ÿ’ป
tgbtyty
tgbtyty

๐Ÿ’ป
wtgtybhertgeghgtwtg
wtgtybhertgeghgtwtg

๐Ÿ’ป