@nxmix/emoji-seq-match
v1.0.0
Published
Match Emoji combinations according to unicode emoji specification
Downloads
4,288
Readme
@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.