

使用lodash;
import toarray from 'lodash.toarray';
toarray(str);
在字符串视觉的基础上判断每个元素的length是否大于1来累积;
Array.from(str).length
export const unicodeLength = (str: string) => {
const strArr = toarray(str);
let unicodeNum = 0;
if (strArr.length) {
strArr .forEach((item) => {
if (item.length > 1) unicodeNum += 1;
});
}
return unicodeNum ;
};
参考文章:https://fehey.com/emoji-length
https://zh.javascript.info/unicode