Story - add caption

This commit is contained in:
Alvaro 2022-10-04 17:17:15 -06:00 committed by GitHub
parent 8fcd36e30a
commit c52fe3f377
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 688 additions and 163 deletions

View file

@ -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;