{"size": 1671, "ext": "js", "max_stars_repo_path": "lib/data.js", "max_stars_repo_name": "camlahoud/react-native-emoji-selector", "max_stars_repo_stars_event_min_datetime": "2017-05-13T14:02:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T17:41:53.000Z", "max_issues_repo_path": "lib/data.js", "max_issues_repo_name": "camlahoud/react-native-emoji-input", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/data.js", "max_forks_repo_name": "camlahoud/react-native-emoji-input", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.3818181818, "max_line_length": 102, "alphanum_fraction": 0.5589467385}
import emojiData from 'emoji-datasource';
const CATEGORIES = ['People', 'Nature', 'Foods', 'Activity', 'Places', 'Objects', 'Symbols', 'Flags'];

function toInteger(it) {
    return isNaN(it = +it) ? 0 : (it > 0 ? Math.floor : Math.ceil)(it);
}
function toIndex(index, length) {
    index = toInteger(index);
    return index < 0 ? Math.max(index + length, 0) : Math.min(index, length);
}
function fromCodePoint (x) {
    var res   = []
    , $$    = arguments
    , $$len = $$.length
    , i     = 0
    , code;
    while($$len > i){
        code = +$$[i++];
        if(toIndex(code, 0x10ffff) !== code)throw RangeError(code + ' is not a valid code point');
        res.push(code < 0x10000
            ? String.fromCharCode(code)
            : String.fromCharCode(((code -= 0x10000) >> 10) + 0xd800, code % 0x400 + 0xdc00)
        );
    } return res.join('');
}

if (!String.fromCodePoint) {
    String.fromCodePoint = fromCodePoint;
}

const charFromCode = utf16 => String.fromCodePoint(...utf16.split('-').map(u => '0x' + u));
var emoji;

export default function getEmojiData() {
    if (emoji) {
        return emoji;
    }
    const _emoji = emojiData.reduce((acc, item) => {
        const { category } = item;
        if (!acc[category]) acc[category] = [];
        acc[category].push({ sortOrder: item.sort_order, char: charFromCode(item.unified) });
        return acc;
    }, {});

    emoji = CATEGORIES.map(category => {
        let items = _emoji[category] || [];
        items = items.sort((a, b) => {
            return (a.sortOrder > b.sortOrder) ? 1 : -1;
        }).map(x => x.char);
        return { category, items };
    });
    
    return emoji;
}
