@nxmix/emoji-seq-match v1.0.0
@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('πΆπΌ');
//=> 2
getMatchedLength('πΆπΌ'); // puppy does not have skin tone combination"
//=> 0
getMatchedLength("πΆπ½π©βπ©βπ¦βπ¦", 2); // from a 'start' postion to match
//=> 7, 'start' is counted by character not visual width
getMatchedLength(['πΆ', 'πΌ']); // also accepts an array of strings
// => 2
Using ES2015w Modules:
import getMatchedLength from '@nxmix/emoji-seq-match';
getMatchedLength('πΆπΌ');
//=> 2
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.