mroth / emoji-data-js

:sunglasses: Emoji encoding swiss army knife for NodeJS
MIT License
64 stars 29 forks source link

Including New Emoji #3

Open thekevinscott opened 8 years ago

thekevinscott commented 8 years ago

iOS has added a bunch of new emoji, present here:

https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji.json

I was trying to open up a pull request integrating them but can't figure out the cause of a failing test. Looks like the new emoji keycap_star (unified 002A-20E3) is causing the RegExp here to fail:

/www/emoji-data-js/lib/emoji_data.js:205
  FBS_REGEXP = new RegExp("(?:" + (EmojiData.chars({
               ^

SyntaxError: Invalid regular expression: /(?:*⃣)/: Nothing to repeat

(I'm slicing off that particular emoji to try and trace down the problem, originally that error message included the full set of emoji.)

Not sure how to troubleshoot this. Any thoughts?

mroth commented 8 years ago

I believe this exact issue is addressed upstream (in the Ruby version of this library) in mroth/emoji_data.rb#4.

Generally I try to keep exact parity between the libraries and tests (the Ruby version is currently considered the "upstream" version with changes ported down to here and Elixir), so if you'd like to help us figure that one out and get it merged it would be a great start towards moving the changes here too!

mnasyrov commented 8 years ago

Hi guys! I've just faced with the same issue when I tried to manually update to the latest emoji.json file.

How about to fix the issue by patching the regex string like this (escape the asterisk char)?

emoji_data.js

FBS_REGEXP = new RegExp("(?:" + (EmojiData.chars({
  include_variants: true
}).join("|").replace('\u002A', '\\\u002A')) + ")", "g");

I tried a following smoke test and it seems healthy:

const emojiData = require('emoji-data');
console.log(
    emojiData.scan(
        emojiData.from_short_name("grinning").render() +
        emojiData.from_short_name("keycap_star").render() +
        '\u002A\u20E3'
    ).map(char => char.short_name).join()
);

Output:

grinning,keycap_star,keycap_star