signal-desktop/ts/util/grapheme.ts

15 lines
410 B
TypeScript
Raw Normal View History

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { map, size } from './iterables';
export function getGraphemes(str: string): Iterable<string> {
const segments = new Intl.Segmenter().segment(str);
return map(segments, s => s.segment);
}
2021-03-31 16:15:49 +00:00
export function count(str: string): number {
const segments = new Intl.Segmenter().segment(str);
2021-03-31 16:15:49 +00:00
return size(segments);
}