-
-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix implementation to avoid Object.prototype mutation, + perf improvement #47
Conversation
timruffles
commented
Jul 7, 2017
•
edited
edited
- use a simple function instead
- also bumped the minor version as the public API expanded
…fy"" This reverts commit bfb2e78.
- also bumped the version a minor, as new functionality is added
@omnidan also removed an unnecessary nested loop, as the |
Awesome; I just started a PR, but I'll cancel that one 😁 |
*/ | ||
Emoji.unemojify = function unemojify(str) { | ||
if (!str) return ''; | ||
var words = toArray(str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var words = Array.from(str);
//cc @paulmillr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, this works properly with Emojis:
> const emoji = '😍🌸'
undefined
> require('lodash').toArray(emoji) // lodash version, understands unicode
[ '😍', '🌸' ]
> [].slice.call(emoji) // slice version, doesn't get unicode chars
[ '�', '�', '�', '�' ]
> Array.from(emoji) // yeey! no need for the dependency, understands unicode
[ '😍', '🌸' ]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not work for complex emojis. Try for something like 👩👩👧👧. Thats why I used the lodash library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aah 😢. Lodash maintainers did a good job with their implementation then!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use the native Array.from
, see my inline comment.
*/ | ||
Emoji.unemojify = function unemojify(str) { | ||
if (!str) return ''; | ||
var words = toArray(str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, this works properly with Emojis:
> const emoji = '😍🌸'
undefined
> require('lodash').toArray(emoji) // lodash version, understands unicode
[ '😍', '🌸' ]
> [].slice.call(emoji) // slice version, doesn't get unicode chars
[ '�', '�', '�', '�' ]
> Array.from(emoji) // yeey! no need for the dependency, understands unicode
[ '😍', '🌸' ]
thank you so much for all the effort @timruffles ! this PR looks good and I'll merge it! |
published |