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

diffCutLines.ts

18 lines791 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 const content = line.endsWith("\r") ? line.slice(0, -1) : line;
11 if (!content.endsWith("more characters]")) return null;
12 const note = CUT_LINE_NOTE.exec(content);
13 return note === null ? null : note.index + 1;
15​
16export function hasCutLines(patch: string): boolean {
17 return new RegExp(CUT_LINE_NOTE.source, "m").test(patch);