signal-desktop/ts/util/stripNewlinesForLeftPane.ts
Scott Nonnenberg d9d820e72a
Support for receiving formatted messages
Co-authored-by: Alvaro Carrasco <alvaro@signal.org>
2023-04-10 09:31:45 -07:00

22 lines
685 B
TypeScript

// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
// This takes `unknown` because, sometimes, values from the database don't match our
// types. In the long term, we should fix that. In the short term, this smoothes over
// the problem.
// Note: we really need to keep the string length the same for proper bodyRange handling
export function stripNewlinesForLeftPane(text: unknown): string {
if (typeof text !== 'string') {
return '';
}
return text.replace(/(\r?\n)/g, substring => {
const { length } = substring;
if (length === 2) {
return ' ';
}
if (length === 1) {
return ' ';
}
return '';
});
}