This Node module returns a JSON-compatible object literal containing several pattern strings: all emoji, component emoji, fully-qualified (keyboard/palette) emoji and non-fully-qualified (display/process) emoji, generated using the information extracted from the Emoji 13.0 data file emoji-test.txt:
- Emoji_Test_All
- Emoji_Test_Component
- Emoji_Test_Keyboard
- Emoji_Test_Display
-
Providing patterns as strings instead of regular expressions does require the extra step of using
new RegExp ()to actually make use of them, but it has two main advantages:-
Flags can be set differently depending on how the patterns are used. In any case, though, the regular expressions must include a 'u' flag, since the patterns make use of the new type of Unicode escape sequences:
\u{1F4A9}. -
The patterns can be further modified before being turned into regular expressions; for instance, the pattern can be embedded into a larger one. See examples below.
-
Switch to your project directory (cd) then run:
npm install emoji-test-patternsA basic test can be performed by running the following command line from the package directory:
npm testconst emojiTestPatterns = require ('emoji-test-patterns');
const emojiKeyboardRegex = new RegExp ('^' + emojiTestPatterns["Emoji_Test_Keyboard"] + '$', 'u');
console.log (emojiKeyboardRegex.test ("❤️"));
// -> true
console.log (emojiKeyboardRegex.test ("❤"));
// -> falseconst emojiTestPatterns = require ('emoji-test-patterns');
const emojiAllRegex = new RegExp (emojiTestPatterns["Emoji_Test_All"], 'gu');
console.log (JSON.stringify ("AaĀā#*0❤🇦愛爱❤️애💜 🇨🇦🇫🇷🇬🇧🇯🇵🇺🇸 👪⬌👨👩👦 💑⬌👩❤️👨 💏⬌👩❤️💋👨".match (emojiAllRegex)));
// -> ["❤","❤️","💜","🇨🇦","🇫🇷","🇬🇧","🇯🇵","🇺🇸","👪","👨👩👦","💑","👩❤️👨","💏","👩❤️💋👨"]const emojiTestPatterns = require ('emoji-test-patterns');
const emojiAllRegex = new RegExp (emojiTestPatterns["Emoji_Test_All"], 'gu');
const emojiKeyboardRegex = new RegExp ('^' + emojiTestPatterns["Emoji_Test_Keyboard"] + '$', 'u');
let emojiList = "AaĀā#*0❤🇦愛爱❤️애💜 🇨🇦🇫🇷🇬🇧🇯🇵🇺🇸 👪⬌👨👩👦 💑⬌👩❤️👨 💏⬌👩❤️💋👨".match (emojiAllRegex);
if (emojiList)
{
emojiList = emojiList.filter (emoji => emojiKeyboardRegex.test (emoji));
}
console.log (JSON.stringify (emojiList));
// -> ["❤️","💜","🇨🇦","🇫🇷","🇬🇧","🇯🇵","🇺🇸","👪","👨👩👦","💑","👩❤️👨","💏","👩❤️💋👨"]const emojiTestPatterns = require ('emoji-test-patterns');
const emojiAllRegex = new RegExp (emojiTestPatterns["Emoji_Test_All"], 'gu');
console.log (JSON.stringify ("AaĀā#*0❤🇦愛爱❤️애💜 🇨🇦🇫🇷🇬🇧🇯🇵🇺🇸 👪⬌👨👩👦 💑⬌👩❤️👨 💏⬌👩❤️💋👨".replace (emojiAllRegex, "")));
// -> "AaĀā#*0🇦愛爱애 ⬌ ⬌ ⬌"The MIT License (MIT).
Copyright © 2018-2019 Michel MARIANI.