node-emoji icon indicating copy to clipboard operation
node-emoji copied to clipboard

Feature: allow search to take in a RegExp

Open sloanlance opened this issue 4 years ago • 1 comments

Change emoji.search() to return emoji whose name contains the search string. I can imagine two approaches:

  1. Always treat the argument as a substring. E.g., emoji.search('evil') → [{ key: 'see_no_evil', emoji: '🙈' }, { key: 'see_no_evil', emoji: '🙈' }, { key: 'see_no_evil', emoji: '🙈' }]. (Example results not exhaustive.)
    • This is probably easiest and most lightweight to implement, but is not backwards compatible with old code that uses this library.
  2. Allow standard regular expressions in the argument. E.g., emoji.search('.*evil') → [{ key: 'see_no_evil', emoji: '🙈' }, { key: 'see_no_evil', emoji: '🙈' }, { key: 'see_no_evil', emoji: '🙈' }]. (Example results not exhaustive.)
    • This may be more complicated, but it will be backwards compatible and it won't return unexpected results.

sloanlance avatar Feb 10 '21 20:02 sloanlance

Always treat the argument as a substring

I think that is the current behaviour.

Allow standard regular expressions in the argument

We could allow RegExp objects to be passed that are evaluated for each emoji.

Richienb avatar Feb 11 '21 00:02 Richienb