UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

19 lines (17 loc) 708 B
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}. */ export const getGraphemeCount = segmenter ? getGraphemeCountModern : getGraphemeCountFallback;