12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- "use strict";
- const ASCII_REGEX = /^[\u0000-\u007f]*$/u;
- let segmenter;
- function upperCaseFirst(string) {
- if (string.length <= 1) {
- return string.toUpperCase();
- }
- return string[0].toUpperCase() + string.slice(1);
- }
- function getGraphemeCount(value) {
- if (ASCII_REGEX.test(value)) {
- return value.length;
- }
- segmenter ??= new Intl.Segmenter("en-US");
- let graphemeCount = 0;
-
- for (const unused of segmenter.segment(value)) {
- graphemeCount++;
- }
- return graphemeCount;
- }
- module.exports = {
- upperCaseFirst,
- getGraphemeCount
- };
|