chapmankyle / emoji-set

Emoji library that allows for searching by emoji, group or keyword :mag:
https://www.npmjs.com/package/emoji-set
GNU General Public License v3.0
5 stars 0 forks source link
emojis javascript js npm search

emoji-set

Test Status Version Size Standard Code Style

Emoji library that contains only the emojis that work on most of the browsers and operating systems currently available :rocket: :earth_africa:

Finally no more ๏ฟฝ symbols when rendering the emojis :partying_face:

Based off emojis from emojilib and keywords from unicode-emoji-json

Install :hammer:

NB: EmojiSet requires Node version 14 or above.

npm install emoji-set --save

Usage :cd:

To get started, you can import the package using two methods:

// ES6 import
import EmojiSet from 'emoji-set'

// or CommonJS import
const EmojiSet = require('emoji-set')

Methods :card_file_box:

get(filter = {})

Returns the emojis that match the given filter. Leave the filter parameter blank to return all available emojis.

Available fields for the filter parameter include: Field Default Description
only_emoji false true to only return the emojis, false to return the emojis and their information
by_section false true to return the emojis grouped by their section, false to return the emojis without any grouping
by_keyword false true to return the emojis grouped by their keywords, false to return the emojis without any grouping

Some examples can be seen below.

:page_with_curl: Get all available emojis

console.log(EmojiSet.get())
/* Returns */
{
  '๐Ÿ˜€': {
    name: 'grinning face',
    code: 'grinning_face',
    group: 'Smileys & Emotion',
    keywords: [ 'grin', 'face', 'smile', 'happy', 'joy', ':D' ]
  },
  '๐Ÿ˜ƒ': {
    name: 'grinning face with big eyes',
    code: 'grinning_face_with_big_eyes',
    group: 'Smileys & Emotion',
    keywords: [ 'grin', 'face', 'happy', 'joy', 'haha', ':D', ':)', 'smile', 'funny' ]
  },
  '๐Ÿ˜„': {
    name: 'grinning face with smiling eyes',
    code: 'grinning_face_with_smiling_eyes',
    group: 'Smileys & Emotion',
    keywords: [ 'grin', 'face', 'happy', 'joy', 'funny', 'haha', 'laugh', 'like', ':D', ':)' ]
  },
  ...
}

:page_with_curl: Get all available emojis without additional information

console.log(EmojiSet.get({ only_emoji: true }))
/* Returns */
[ '๐Ÿ˜€', '๐Ÿ˜ƒ', '๐Ÿ˜„', ... ]

:page_with_curl: Get emojis grouped by their section name

console.log(EmojiSet.get({ by_section: true }))
/* Returns */
{
  'Smileys & Emotion': [
    {
      emoji: '๐Ÿ˜€',
      name: 'grinning face',
      code: 'grinning_face',
      keywords: [ 'face', 'smile', 'happy', 'joy', ':D', 'grin' ]
    },
    {
      emoji: '๐Ÿ˜ƒ',
      name: 'grinning face with big eyes',
      code: 'grinning_face_with_big_eyes',
      keywords: [ 'face', 'happy', 'joy', 'haha', ':D', ':)', 'smile', 'funny' ]
    },
    ...
  ],
  'People & Body': [
    {
      emoji: '๐Ÿ‘‹',
      name: 'waving hand',
      code: 'waving_hand',
      keywords: [ 'hands', 'gesture', 'goodbye', 'solong', 'farewell', 'hello', 'hi', 'palm' ]
    },
    {
      emoji: '๐Ÿคš',
      name: 'raised back of hand',
      code: 'raised_back_of_hand',
      keywords: [ 'fingers', 'raised', 'backhand' ]
    },
    ...
  ],
  ...
}

:page_with_curl: Get emojis grouped by their section name, without additional information

console.log(EmojiSet.get({ by_section: true, only_emoji: true }))
/* Returns */
{
  'Smileys & Emotion': [ '๐Ÿ˜€', '๐Ÿ˜ƒ', ... ],
  'People & Body': [ '๐Ÿ‘‹', '๐Ÿคš', ... ],
  ...
}

:page_with_curl: Get emojis grouped by their keywords

console.log(EmojiSet.get({ by_keywords: true }))
/* Returns */
{
  ...
  'playful': {
    '๐Ÿ˜›': {
      name: 'face with tongue',
      code: 'face_with_tongue',
      group: 'Smileys & Emotion'
    },
    '๐Ÿ˜œ': {
      name: 'winking face with tongue',
      code: 'winking_face_with_tongue',
      group: 'Smileys & Emotion'
    },
    '๐Ÿ˜': {
      name: 'squinting face with tongue',
      code: 'squinting_face_with_tongue',
      group: 'Smileys & Emotion'
    },
    '๐Ÿ‘…': {
      name: 'tongue',
      code: 'tongue',
      group: 'People & Body'
    }
  },
  'quiet': {
    '๐Ÿคซ': {
      name: 'shushing face',
      code: 'shushing_face',
      group: 'Smileys & Emotion'
    },
    '๐Ÿ”‡': {
      name: 'muted speaker',
      code: 'muted_speaker',
      group: 'Objects'
    },
    '๐Ÿ”•': {
      name: 'bell with slash',
      code: 'bell_with_slash',
      group: 'Objects'
    },
    '๐Ÿ“ด': {
      name: 'mobile phone off',
      code: 'mobile_phone_off',
      group: 'Symbols'
    }
  },
  ...
}

:page_with_curl: Get emojis grouped by their keywords, without additional information

console.log(EmojiSet.get({ by_keywords: true, only_emoji: true }))
/* Returns */
{
  ...
  'playful': [ '๐Ÿ˜›', '๐Ÿ˜œ', '๐Ÿ˜', '๐Ÿ‘…' ],
  'quiet': [ '๐Ÿคซ', '๐Ÿ”‡', '๐Ÿ”•', '๐Ÿ“ด' ],
  ...
}

search(filter = {})

Searches for emojis using the given filter.

Available fields for the filter parameter include: Field Default Description
only_emoji false true to only return the emojis, false to return the emojis and their information
by_section '' Section to return the emojis from. Some examples are: 'Objects', 'Animals & Nature' etc. Value is case-insensitive
by_keyword '' Keyword to use in the emoji search. Some examples are: 'smile', 'tada' etc. Value is case-insensitive
first_match false true to only return the first match (when using by_keyword), false to return all matches

Some examples can be seen below.

:page_with_curl: Search for emojis that match the given section name

console.log(EmojiSet.search({ by_section: 'flags' }))
/* Returns */
[
  {
    emoji: '๐Ÿ',
    code: 'chequered_flag',
    keywords: [ 'chequered', 'flag', 'contest', 'finishline', 'race', 'gokart' ]
  },
  {
    emoji: '๐Ÿšฉ',
    code: 'triangular_flag',
    keywords: [ 'mark', 'milestone', 'place' ]
  },
  {
    emoji: '๐ŸŽŒ',
    code: 'crossed_flags',
    keywords: [ 'cross', 'flag', 'japanese', 'nation', 'country', 'border' ]
  },
  {
    emoji: '๐Ÿด',
    code: 'black_flag',
    keywords: [ 'black', 'flag', 'pirate' ]
  },
  {
    emoji: '๐Ÿณ๏ธ' ,
    code: 'white_flag',
    keywords: [ 'white', 'flag', 'losing', 'loser', 'lost', 'surrender', 'give up', 'fail' ]
  },
  {
    emoji: '๐Ÿณ๏ธโ€๐ŸŒˆ' ,
    code: 'rainbow_flag',
    keywords: [ 'rainbow', 'flag', 'pride', 'gay', 'lgbt', 'glbt', 'queer', 'homosexual', 'lesbian', 'bisexual', 'transgender' ]
  },
  {
    emoji: '๐Ÿดโ€โ˜ ๏ธ',
    code: 'pirate_flag',
    keywords: [ 'pirate', 'flag', 'skull', 'crossbones', 'banner' ]
  }
]

:page_with_curl: Search for emojis that match the given section name, without additional information

console.log(EmojiSet.search({ by_section: 'flags', only_emoji: true }))
/* Returns */
[ '๐Ÿ', '๐Ÿšฉ', '๐ŸŽŒ', '๐Ÿด', '๐Ÿณ๏ธ', '๐Ÿณ๏ธโ€๐ŸŒˆ', '๐Ÿดโ€โ˜ ๏ธ' ]

:page_with_curl: Search for emojis that match the given keyword

console.log(EmojiSet.search({ by_keyword: 'perf' }))
/* Returns */
{
  '๐Ÿ’ฏ': {
    name: 'hundred points',
    code: 'hundred_points',
    group: 'Smileys & Emotion'
  },
  '๐Ÿ‘Œ': {
    name: 'OK hand',
    code: 'ok_hand',
    group: 'People & Body'
  },
  '๐Ÿ‘ฏ': {
    name: 'people with bunny ears',
    code: 'people_with_bunny_ears',
    group: 'People & Body'
  },
  '๐Ÿคน': {
    name: 'person juggling',
    code: 'person_juggling',
    group: 'People & Body'
  }
}

:page_with_curl: Search for emojis that match the given keyword, returning the first match only

console.log(EmojiSet.search({ by_keyword: 'perf', first_match: true }))
/* Returns */
{
  '๐Ÿ’ฏ': {
    name: 'hundred points',
    code: 'hundred_points',
    group: 'Smileys & Emotion'
  }
}

:page_with_curl: Search for emojis that match the given keyword, returning the first match only and without any additional information

console.log(EmojiSet.search({ by_keyword: 'perf', first_match: true, only_emoji: true }))
/* Returns */
[ '๐Ÿ’ฏ' ]