enescakir / emoji

A minimalistic emoji package for Go (golang)
MIT License
435 stars 20 forks source link

Support alias back-and-forth #8

Open liemle3893 opened 3 years ago

liemle3893 commented 3 years ago

Hi there, I found this module is quite interesting and easy to catch up.

Currently, I got into situation where I need to implement some kind of searching, but the search engine is not fully support utf8. So, it's may good for user to be able to convert ❤️ => :heart: and back, :heart: => ❤️

I'm also done a prototype for these implementation. My repo: https://github.com/liemle3893/emoji/commit/985fe954b73baf6614a2fd99d03779e49e07212d

It's cool if we can add this feature.

Regards.

quenbyako commented 3 years ago

wait, are these symbols not equal?

for me it looks like this Screen Shot 2021-03-31 at 3 54 51 AM
liemle3893 commented 3 years ago

@quenbyako oops, my bad. I've updated.

Shoud be: :heart: => ❤️ and back, ❤️ => :heart:

quenbyako commented 3 years ago

@liemle3893 why you just don't make reverse map searching? It's really trivial: you just finding key by ranging values 🙃

Also, there is even more simple way: why just not copy emoji.Map() and flip keys and values to your map? I mean, i understand your problem, but it is really simple, and you can can solve it even simpler than you think and without improving current code.

But, even i'm not author or contributor to this project, i appreciate your work, no matter how much there are more solutions of this issue exist

adbenitez commented 1 year ago

@quenbyako for a single emoji, yeah sure, it is easy to convert :heart: => :heart: but if your input is a text like "I :heart: emoji" then you have to parse the text looking for all emoji, another feature that is not supported by this library so if something like emoji.FindAll(text) is added to allow getting all emoji in text maybe it would be easy to implement, but right now user has to parse text looking for emoji themselves

adbenitez commented 1 year ago

another option is to use https://github.com/forPelevin/gomoji which allows to replace emojis with their slug, then use this library for the other direction :facepalm: each library support the conversion only in one direction

func replaceEmojisWithSlug(s string) string {
    return gomoji.ReplaceEmojisWithFunc(s, func(em gomoji.Emoji) string {
        return ":" + em.Slug + ":"
    })
}