Get the visual width of the string
Because of the combination of Unicode and Emoji characters, it is difficult to calculate the actual display width of a string in Terminal applciation. Strictly speaking there is no universal method to do that.
I try to figure it out in accordance with the following steps:
n\u0303
becomes ñ
.npm i @nxmix/string-visual-width --save
Typescript definition file is already included.
const width = require('@nxmix/string-visual-width').default;
width('中');
//=> 2
width("👩👦");
//=> 2
import getMatchedLength from '@nxmix/string-visual-width';
width('中');
//=> 2