@nxmix/emoji-seq-match

Match Emoji combinations according to unicode emoji specification
Why
Different Emoji character combinations may visually produce different widths, for examples:
👶 + 🏼 => 👶🏼 // Base emoji with skin-tone modifier
👨 + 👩 + 👧 + 👦 => 👨👩👧👦 // Emoji characters joined with zero-witdh joiner (\u0200d)
Emoji Sequences, v11.0 defines these combinations.
The reason for creating this module is that I need to get the visual width of a string in terminal application to calculate the cursor's movement distance. To achieve this, I have to first create a method to find out if a string insludes a specification-defined Emoji combination.
Please noe that different terminal apps have different levels of implementation of the specification, including even the latest macOS Terminal.
Usage
Install
npm i @nxmix/emoji-seq-match --save
Typescript definition file is already included.
EXAMPLES
const getMatchedLength = require('@nxmix/emoji-seq-match').default;
getMatchedLength('👶🏼');
getMatchedLength('🐶🏼');
getMatchedLength("👶🏽👩👩👦👦", 2);
getMatchedLength(['👶', '🏼']);
Using ES2015w Modules:
import getMatchedLength from '@nxmix/emoji-seq-match';
getMatchedLength('👶🏼');
Tool
Running npm run parse-spec
will download the specification files from
http://unicode.org/Public/emoji/11.0/ and place the converted json files in the ./emoji-sequences
directory.