25 lines
843 B
JavaScript
25 lines
843 B
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.getGraphemeCount = void 0;
|
|
const segmenter = typeof window !== 'undefined' && 'Intl' in window && 'Segmenter' in Intl ? new Intl.Segmenter(undefined, {
|
|
granularity: 'grapheme'
|
|
}) : null;
|
|
function getGraphemeCountFallback(text) {
|
|
return text.length;
|
|
}
|
|
function getGraphemeCountModern(text) {
|
|
const segments = segmenter.segment(text);
|
|
let count = 0;
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/naming-convention,no-underscore-dangle
|
|
for (const _unused of segments) {
|
|
count += 1;
|
|
}
|
|
return count;
|
|
}
|
|
|
|
/** Returns the number of graphemes (basically characters) present in {@link text}. */
|
|
const getGraphemeCount = exports.getGraphemeCount = segmenter ? getGraphemeCountModern : getGraphemeCountFallback; |