signal-desktop/ts/util/getTextWithMentions.ts

13 lines
386 B
TypeScript
Raw Normal View History

2020-09-18 21:43:57 +00:00
import { BodyRangesType } from '../types/Util';
export function getTextWithMentions(
bodyRanges: BodyRangesType,
text: string
): string {
return bodyRanges.reduce((str, range) => {
const textBegin = str.substr(0, range.start);
const textEnd = str.substr(range.start + range.length, str.length);
return `${textBegin}@${range.replacementText}${textEnd}`;
}, text);
}