Created
September 16, 2021 23:51
-
-
Save jiyuujin/5d75edcb57b233e6e04918c399aecdfe to your computer and use it in GitHub Desktop.
絵文字を考慮して数える
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 絵文字を含む場合の文字数 (サロゲートペアと呼ばれる領域を間引く) | |
* @param val 対象文字列 | |
*/ | |
export const countCharactersIncludedEmoji = (val: string): number => { | |
return val?.toString().length - (val?.toString().split(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g).length - 1); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment