omnidan / node-emoji

💖 simple emoji support for node.js projects
MIT License
1.31k stars 241 forks source link

Add a .extend(...) option to expand upon the built-in dictionary #144

Open JoshuaKGoldberg opened 11 months ago

JoshuaKGoldberg commented 11 months ago

Forking @bigpay-ali's https://github.com/omnidan/node-emoji/pull/132#discussion_r1368079440:

Hello beautiful humans, I love what you did with this lib and thank you for providing this library for developer like me to build on top of it, is there a way we can get this fix merged? I desprately need some emojis which are missing from your lib. Maybe we can add a .extend(":emoji-code","✅") function, just in case some emojis are missing, developer can update it and make it searchable across project?

I like this idea. Even after the latest emojilib gets merged in, it's possible folks will want to add their own context/project-specific emoji extensions.

One difficulty with this is that right now, all node-emoji APIs are exported standalone: e.g. import { findByName } from "node-emoji". This new extension API would need to either:

I'd lean towards the latter personally, as modifying global state is a worrisome thing to me.

My starting API proposal:

import { extend } from "node-emoji";

const emojiBank = extend({
  emojis: [
    { code: "yeehaw", emoji: "🤠" }
  ]
});

This differs from the original comment by being more explicit and open to later expansion, at the cost of extra verbosity.

omnidan commented 11 months ago

@JoshuaKGoldberg I really like the idea of making the library more extensible and it would likely solve a lot of issues people are having with the library not supporting certain codes for certain emoji. I also agree that returning a new object with the same APIs as node-emoji is the way to go. That way you could even have multiple instances of node-emoji that all resolve them differently. It is way more flexible and less prone to tricky bugs that can arise from modifying the global state of the library.

JoshuaKGoldberg commented 10 months ago

One month and no additional inputs - marking as accepting PRs! 🚀

Note that this probably isn't a trivial change. It'll require making all sort of stuff in node-emoji per-instance.

lucasvieceli commented 2 weeks ago

I quickly implemented a solution that updates the global state, but I'm wondering if anyone knows a way to create a new instance without having to modify the entire library?