Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

diffCutLines.ts

17 lines719 Bytes

1// A withheld file's diff line the server cut short ends in this note, which clients style apart.
2const CUT_LINE_NOTE = / …\[[\d,]+ more characters\]$/;
3​
4export function cutLineNote(omittedCharacters: number): string {
5 return ` …[${omittedCharacters.toLocaleString("en-US")} more characters]`;
6}
7​
8/** Where a cut line's note starts, past its leading space, or null for a whole line. */
9export function cutLineNoteStart(line: string): number | null {
10 if (!line.endsWith("more characters]")) return null;
11 const note = CUT_LINE_NOTE.exec(line);
12 return note === null ? null : note.index + 1;
14​
15export function hasCutLines(patch: string): boolean {
16 return new RegExp(CUT_LINE_NOTE.source, "m").test(patch);