How to use emoji-datasource - 10 common examples

To help you get started, we’ve selected a few emoji-datasource examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yonahforst / react-native-emoji-picker / index.js View on Github external
require('string.fromcodepoint');

// i dont understand ANY of this but there's somethign called codepoints and surrogate pairs
// and this converts utf16 to a charachter in javascript. see more here:
//https://mathiasbynens.be/notes/javascript-unicode
//https://mathiasbynens.be/notes/javascript-escapes#unicode-code-point
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint
const charFromUtf16 = utf16 => String.fromCodePoint(...utf16.split('-').map(u => '0x' + u))
const charFromEmojiObj = obj => charFromUtf16(obj.unified)
const blacklistedEmojis = ['white_frowning_face', 'keycap_star', 'eject']

const isAndroid = Platform.OS == 'android'
const letterSpacing = 10
const defaultEmojiSize = 30
const padding = 5
const filteredEmojis = emoji.filter(e => isAndroid ? !!e.google : !includes(blacklistedEmojis, e.short_name))
// sort emojis by 'sort_order' then group them into categories
const groupedAndSorted = groupBy(orderBy(filteredEmojis, 'sort_order'), 'category')
// convert the emoji object to a character
const emojisByCategory = mapValues(groupedAndSorted, group => group.map(charFromEmojiObj))

const CATEGORIES = ['People', 'Nature', 'Foods', 'Activity', 'Places', 'Objects', 'Symbols', 'Flags']


class EmojiPicker extends React.Component {
  state = {
    categories: CATEGORIES.slice(0, 1),
  }

  componentWillUnmount() {
    clearTimeout(this._timeout)
  }
github arronhunt / react-native-emoji-selector / example / EmojiSelector.js View on Github external
if (c !== 'all') return (
                     {}}
                    />
                )                   
            });
        } else {
            let list;
            let hasSearchQuery = this.state.searchQuery !== '';
            if (hasSearchQuery)
                list = emoji.filter(e => {
                    // TODO: Use the short_names array instead of singular short_name
                    return e.short_name.includes(this.state.searchQuery.toLowerCase())
                });
            else 
                list = emojiByCategory(this.state.category.name);
            
            return (
                 {}}
                />
            );
        }
github tunoltd / emoji-mart-native / scripts / local-images / build.js View on Github external
module.exports = (options) => {
  delete require.cache[require.resolve('emoji-datasource')]
  var emojiData = require('emoji-datasource')

  var data = { compressed: true, emojis: {} }

  emojiData.sort((a, b) => {
    var aTest = a.sort_order || a.short_name,
      bTest = b.sort_order || b.short_name

    return aTest - bTest
  })

  emojiData.forEach((datum) => {
    var keywords = []

    var localImageSets = options.sets || sets

    // Local images
    datum.localImages = {}
    localImageSets.forEach((set) => {
      var key = `has_img_${set}`
      if (datum[key]) {
        datum.localImages[set] = [`require('./img-${set}-64/${datum.image}')`]

        // Skin variations
        if (datum.skin_variations) {
          for (let skinKey in datum.skin_variations) {
            var skinVariations = datum.skin_variations[skinKey]
            if (skinVariations[key])
github tunoltd / emoji-mart-native / scripts / local-images / build.js View on Github external
module.exports = (options) => {
  delete require.cache[require.resolve('emoji-datasource')]
  var emojiData = require('emoji-datasource')

  var data = { compressed: true, emojis: {} }

  emojiData.sort((a, b) => {
    var aTest = a.sort_order || a.short_name,
      bTest = b.sort_order || b.short_name

    return aTest - bTest
  })

  emojiData.forEach((datum) => {
    var keywords = []

    var localImageSets = options.sets || sets

    // Local images
    datum.localImages = {}
    localImageSets.forEach((set) => {
      var key = `has_img_${set}`
      if (datum[key]) {
github rainbow-me / rainbow / src / components / EmojiSelector.js View on Github external
name: 'Objects',
  },
  icons: {
    icon: 'emojiSymbols',
    name: 'Symbols',
  },
  flags: {
    icon: 'emojiFlags',
    name: 'Flags',
  },
};

const charFromUtf16 = utf16 =>
  String.fromCodePoint(...utf16.split('-').map(u => '0x' + u));
export const charFromEmojiObject = obj => charFromUtf16(obj.unified);
const filteredEmojis = emoji.filter(e => !e['obsoleted_by']);
const emojiByCategory = category =>
  filteredEmojis.filter(e => e.category === category);
const sortEmoji = list => list.sort((a, b) => a.sort_order - b.sort_order);
const { width } = Dimensions.get('screen');
const categoryKeys = Object.keys(Categories);

const TabBar = ({ theme, activeCategory, onPress }) => {
  return categoryKeys.map(c => {
    const category = Categories[c];
    if (c !== 'all')
      return (
github keybase / client / shared / markdown / generate-emoji-parser.js View on Github external
function genEmojiData() {
  const emojiIndexByChar = {}
  const emojiLiterals = []
  const emojiCharacters = new Set()
  function addEmojiLiteral(unified, name, skinTone) {
    const chars = unified.split('-').map(c => String.fromCodePoint(parseInt(c, 16)))
    const literals = chars.map(c => UTF162JSON(c)).join('')

    emojiIndexByChar[chars.join('')] = `:${name}:` + (skinTone ? `:skin-tone-${skinTone}:` : '')
    emojiLiterals.push(literals)
    chars.forEach(c => emojiCharacters.add(c))
  }

  emojiData.forEach(emoji => {
    if (emoji.skin_variations) {
      Object.keys(emoji.skin_variations).forEach((k, idx) =>
        addEmojiLiteral(emoji.skin_variations[k].unified, emoji.short_name, idx + 1)
      )
    }
    emoji.variations.forEach(v => addEmojiLiteral(v, emoji.short_name))
    addEmojiLiteral(emoji.unified, emoji.short_name)
  })

  emojiLiterals.sort((a, b) => b.length - a.length)

  return {emojiIndexByChar, emojiLiterals, emojiCharacters}
}
github joeattardi / svelte-emoji-selector / scripts / processEmojiData.js View on Github external
const { writeFileSync } = require('fs');

const rawData = require('emoji-datasource');

function getEmoji(unified) {
  const chars = unified.split('-');
  const codePoints = chars.map(char => parseInt(char, 16));
  return String.fromCodePoint(...codePoints);
}

rawData.sort((e1, e2) => e1.sort_order - e2.sort_order);
const newEmojiData = rawData.map(emojiItem => {
  const newData = {
    name: emojiItem.short_name,
    key: emojiItem.short_name,
    names: emojiItem.short_names,
    emoji: getEmoji(emojiItem.unified),
    category: emojiItem.category
  };

  if (emojiItem.skin_variations) {
    newData.variants = {};
    Object.keys(emojiItem.skin_variations).forEach(variation => {
      newData.variants[variation] = {
        name: emojiItem.short_name,
        key: `${emojiItem.short_name}-${variation}`,
        emoji: getEmoji(emojiItem.skin_variations[variation].unified)
github joeattardi / svelte-emoji-selector / scripts / processEmojiData.js View on Github external
const { writeFileSync } = require('fs');

const rawData = require('emoji-datasource');

function getEmoji(unified) {
  const chars = unified.split('-');
  const codePoints = chars.map(char => parseInt(char, 16));
  return String.fromCodePoint(...codePoints);
}

rawData.sort((e1, e2) => e1.sort_order - e2.sort_order);
const newEmojiData = rawData.map(emojiItem => {
  const newData = {
    name: emojiItem.short_name,
    key: emojiItem.short_name,
    names: emojiItem.short_names,
    emoji: getEmoji(emojiItem.unified),
    category: emojiItem.category
  };

  if (emojiItem.skin_variations) {
    newData.variants = {};
    Object.keys(emojiItem.skin_variations).forEach(variation => {
      newData.variants[variation] = {
        name: emojiItem.short_name,
        key: `${emojiItem.short_name}-${variation}`,
        emoji: getEmoji(emojiItem.skin_variations[variation].unified)
      };
github rainbow-me / rainbow / src / components / EmojiSelector.js View on Github external
//TODO: OPTIMIZE THIS
      let largeList = [];
      categoryKeys.forEach(c => {
        const name = Categories[c].name;
        const list =
          name === Categories.history.name ? history : emojiList[name];
        if (c !== 'all' && c !== 'history') largeList = largeList.concat(list);
      });

      return largeList.map(emoji => ({ key: emoji.unified, emoji }));
    } else {
      let list;
      const hasSearchQuery = searchQuery !== '';
      const name = category.name;
      if (hasSearchQuery) {
        const filtered = emoji.filter(e => {
          let display = false;
          e.short_names.forEach(name => {
            if (name.includes(searchQuery.toLowerCase())) display = true;
          });
          return display;
        });
        list = sortEmoji(filtered);
      } else {
        list = emojiList[name];
      }
      return list.map(emoji => ({ key: emoji.unified, emoji }));
    }
  }
github arronhunt / react-native-emoji-selector / example / module.js View on Github external
let largeList =  [];
      categoryKeys.forEach(c => {
        const name = Categories[c].name;
        const list = name === Categories.history.name ? history : emojiList[name]  
        if (c !== 'all' && c !== 'history') 
          largeList = largeList.concat(list);
      });

      return (largeList.map(emoji => ({ key: emoji.unified, emoji })))

    } else {
        let list;
        const hasSearchQuery = searchQuery !== '';
        const name = category.name;
        if (hasSearchQuery) {
          const filtered = emoji.filter(e => {
            let display = false;
            e.short_names.forEach(name => {
              if(name.includes(searchQuery.toLowerCase())) display = true;
            })
            return display;
          });
          list = sortEmoji(filtered);
        } else if (name === Categories.history.name) {
          list = history
        } else {
          list = emojiList[name];
        }
        return (list.map(emoji => ({ key: emoji.unified, emoji })))
    }
  }

emoji-datasource

Emoji data and images

MIT
Latest version published 2 months ago

Package Health Score

73 / 100
Full package analysis