Allow user customization of regex used for matching emojis#146
Open
lionel-rowe wants to merge 2 commits intojdecked:mainfrom
Open
Allow user customization of regex used for matching emojis#146lionel-rowe wants to merge 2 commits intojdecked:mainfrom
lionel-rowe wants to merge 2 commits intojdecked:mainfrom
Conversation
a5fc676 to
6b35c40
Compare
lionel-rowe
commented
Nov 8, 2025
| // just a private shortcut | ||
| fromCharCode = String.fromCharCode; | ||
|
|
||
| Object.defineProperties(twemoji, { |
Author
There was a problem hiding this comment.
Object.defineProperties and Array#map used below are both IE9+. I only mention this as I noticed there's a comment about IE6 support, which I assume (maybe wrongly?) isn't needed any more in AD 2025. I've tried to be scrupulous about avoiding any other overly modern features (method syntax or arrow functions, trailing commas, new regex flags, etc.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #91... I think? Well anyway, it fulfils my use case, maybe @killroy42 can feedback as to whether it fulfils theirs. Notably, it always maps the matched emoji to the relevant icon file name, such that e.g. if "ABC" is matched as an emoji, it always becomes
41-42-43.pngor41-42-43.svg. Supplying custom mappings is not supported, but a future PR could build on this one to enable that if it's desirable.Perf should remain near-identical for cases where the default regex is used, with a small performance hit in cases where a customized regex is supplied. This is due to the XSS-prevention logic, which is assumed unnecessary with the default regex.
Usage: