mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-28 12:23:31 +01:00
Group member label improvements
This commit is contained in:
25
ts/util/truncateString.std.ts
Normal file
25
ts/util/truncateString.std.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright 2026 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { count, truncateAndSize } from './grapheme.std.js';
|
||||
import { isBodyTooLong, trimBody } from './longAttachment.std.js';
|
||||
|
||||
export function truncateString(
|
||||
target: string,
|
||||
{
|
||||
byteLimit,
|
||||
graphemeLimit,
|
||||
}: { byteLimit?: number; graphemeLimit?: number } = {}
|
||||
): string {
|
||||
let result = target;
|
||||
|
||||
if (byteLimit && isBodyTooLong(result, byteLimit)) {
|
||||
result = trimBody(result, byteLimit);
|
||||
}
|
||||
|
||||
if (graphemeLimit && count(result) > graphemeLimit) {
|
||||
[result] = truncateAndSize(result, graphemeLimit);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user