Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

denormalize text before getting character length #25

Open
dwhieb opened this issue May 13, 2021 · 0 comments
Open

denormalize text before getting character length #25

dwhieb opened this issue May 13, 2021 · 0 comments

Comments

@dwhieb
Copy link
Member

dwhieb commented May 13, 2021

Before getting the character length, denormalize the text.

function getCharLength(str) {
// search for non-combining character followed by combining character
const combiningRegExp = /(?<char>\P{Mark})(?<combiner>\p{Mark}+)/gu;
// remove combining characters
str = str.replace(combiningRegExp, `$1`);
// get length, accounting for surrogate pairs
return Array.from(str).length;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant