Add `getEmojiDataFromNative` util function to get emoji data from native
parent
54f6893c98
commit
1c7a5d6ec6
|
@ -2,6 +2,7 @@ export { default as emojiIndex } from './utils/emoji-index/emoji-index'
|
||||||
export { default as NimbleEmojiIndex } from './utils/emoji-index/nimble-emoji-index'
|
export { default as NimbleEmojiIndex } from './utils/emoji-index/nimble-emoji-index'
|
||||||
export { default as store } from './utils/store'
|
export { default as store } from './utils/store'
|
||||||
export { default as frequently } from './utils/frequently'
|
export { default as frequently } from './utils/frequently'
|
||||||
|
export { getEmojiDataFromNative } from './utils'
|
||||||
|
|
||||||
export { default as Picker } from './components/picker/picker'
|
export { default as Picker } from './components/picker/picker'
|
||||||
export { default as NimblePicker } from './components/picker/nimble-picker'
|
export { default as NimblePicker } from './components/picker/nimble-picker'
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { buildSearch } from './data'
|
import { buildSearch } from './data'
|
||||||
import stringFromCodePoint from '../polyfills/stringFromCodePoint'
|
import stringFromCodePoint from '../polyfills/stringFromCodePoint'
|
||||||
|
import { uncompress } from './data'
|
||||||
|
|
||||||
const _JSON = JSON
|
const _JSON = JSON
|
||||||
|
|
||||||
|
@ -134,6 +135,40 @@ function getData(emoji, skin, set, data) {
|
||||||
return emojiData
|
return emojiData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getEmojiDataFromNative(nativeString, set, data) {
|
||||||
|
if (data.compressed) {
|
||||||
|
uncompress(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
const skinTones = ['', '🏻', '🏼', '🏽', '🏾', '🏿']
|
||||||
|
|
||||||
|
let skin
|
||||||
|
let baseNativeString = nativeString
|
||||||
|
|
||||||
|
skinTones.forEach((skinTone) => {
|
||||||
|
baseNativeString = baseNativeString.replace(skinTone, '')
|
||||||
|
if (nativeString.indexOf(skinTone) > 0) {
|
||||||
|
skin = skinTones.indexOf(skinTone) + 1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const emojiData = Object.values(data.emojis).find((emoji) => {
|
||||||
|
if (emoji.variations && emoji.variations.length) {
|
||||||
|
emoji.unifed = emoji.variations.shift()
|
||||||
|
}
|
||||||
|
|
||||||
|
return unifiedToNative(emoji.unified) === baseNativeString
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!emojiData) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
emojiData.id = emojiData.short_names[0]
|
||||||
|
|
||||||
|
return getSanitizedData(emojiData, skin, set, data)
|
||||||
|
}
|
||||||
|
|
||||||
function uniq(arr) {
|
function uniq(arr) {
|
||||||
return arr.reduce((acc, item) => {
|
return arr.reduce((acc, item) => {
|
||||||
if (acc.indexOf(item) === -1) {
|
if (acc.indexOf(item) === -1) {
|
||||||
|
@ -191,6 +226,7 @@ function measureScrollbar() {
|
||||||
|
|
||||||
export {
|
export {
|
||||||
getData,
|
getData,
|
||||||
|
getEmojiDataFromNative,
|
||||||
getSanitizedData,
|
getSanitizedData,
|
||||||
uniq,
|
uniq,
|
||||||
intersect,
|
intersect,
|
||||||
|
|
Loading…
Reference in New Issue