2.1.3 • Published 4 months ago

node-emoji v2.1.3

Weekly downloads
2,470,825
License
MIT
Repository
github
Last release
4 months ago

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

@alexghi/reiconsff-antd-vue@ilya7u/bitbucket@zkmpc/phase2cliarchetype-library@hi-matbub/build@balena/jellyfish-ui-components@tomas.brambora/git-trigger-buildkanzhucai-nest-clidcxt-design-xue-xannmpackagethatiamtestinganditishardant-mstant-master@bejoistic/gitfeedkilli8n-react-native-fast-imagegenerator-fullstackzfedkmada-cli@cherryblossom/discord-dynamic-messagesnode-menu-list@tenjo/wappultra-parsertm-childgdax-reportsgdax-balancemakefile-for-js-examplepi-config-clibdd-initializer@dune-network/corezendocssymantecpkicertsdummy-sub-talos-toolsgenerator-imperohassan-akaou@tomcarman/ravenauto-too-cligitfeedsamurai-clireact-native-country-picker-modal-with-testidxhn-design-vuezyd-design-vuediodark-cliant-design-vue-xuexueant-design-vue-xxxue-dev-new-xant-design-vue-xxxxue-dev-new2growth-antd-web@ihikmawan/tailwindcss-multi-theme-l2@patterujs/patteru-clivue-ant-patterns-cicdjrabbitnimble-boiler@dqyfp/dl-cli-spareact-native-language-picker-modalmio-design-vue@beatjs/create-react-native-moduleghata@open-tech-world/create-node-libclmlrabbit-boilertail-react@penguinproject/ts-messenger-apiostarionbot@foodism/cliii@foodism/cli2@hi-docs/init@dalitaavanesian/reiconsclean-scaffoldcdn-bundler@zeroneorg/cliotto-cli@totvslabs/carolgithub-build-hookpri-cli@rari-capital/solidity-coveragehzero-cliant-design-vue-ysb@askme-inc/ant-design-vue07-yml@kanzhucai/nest-cli@hamahmi/react-native-country-picker-modalinterview-game@olivervorasai/sliderleng-cli@fh0/cli@titandeveos/uxwallet-cli@titandeveos/wallet-plugin-eosio@titandeveos/wallet-plugin-minerbch-js-joeyfirenpm.clisteps-coreportman-lambda@jeeiii/phase2clitest-ant-design-vue@cloudhub-ux/core@mink-opn/build-tokensrun-design-vue2zerw-cliunblock-block-save-variables
2.1.2

4 months ago

2.1.1

4 months ago

2.1.3

4 months ago

2.0.2

11 months ago

2.1.0

9 months ago

2.0.1

11 months ago

2.0.0

11 months ago

1.11.0

3 years ago

1.10.0

5 years ago

1.9.0

5 years ago

1.8.1

7 years ago

1.8.0

7 years ago

1.7.0

7 years ago

1.6.1

7 years ago

1.6.0

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.4.3

7 years ago

1.4.2

7 years ago

1.4.1

8 years ago

1.4.0

8 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.1

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.4

8 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.1.0

10 years ago