d9d820e72a
Co-authored-by: Alvaro Carrasco <alvaro@signal.org>
22 lines
685 B
TypeScript
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 '';
|
|
});
|
|
}
|