Story - add caption
This commit is contained in:
parent
8fcd36e30a
commit
c52fe3f377
22 changed files with 688 additions and 163 deletions
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2021-2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { map, size } from './iterables';
|
||||
import { map, size, take, join } from './iterables';
|
||||
|
||||
export function getGraphemes(str: string): Iterable<string> {
|
||||
const segments = new Intl.Segmenter().segment(str);
|
||||
|
@ -13,6 +13,25 @@ export function count(str: string): number {
|
|||
return size(segments);
|
||||
}
|
||||
|
||||
/** @return truncated string and size (after any truncation) */
|
||||
export function truncateAndSize(
|
||||
str: string,
|
||||
toSize?: number
|
||||
): [string, number] {
|
||||
const segments = new Intl.Segmenter().segment(str);
|
||||
const originalSize = size(segments);
|
||||
if (toSize === undefined || originalSize <= toSize) {
|
||||
return [str, originalSize];
|
||||
}
|
||||
return [
|
||||
join(
|
||||
map(take(segments, toSize), s => s.segment),
|
||||
''
|
||||
),
|
||||
toSize,
|
||||
];
|
||||
}
|
||||
|
||||
export function isSingleGrapheme(str: string): boolean {
|
||||
if (str === '') {
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue