signal-desktop/ts/util/getTextWithMentions.ts
2020-09-21 15:42:51 -04:00

12 lines
386 B
TypeScript

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);
}