@mui/x-charts
Version:
The community edition of MUI X Charts components.
25 lines (22 loc) • 843 B
JavaScript
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;
;