MCPcopy Index your code
hub / github.com/prettydiff/prettydiff / diffview

Function diffview

api/diffview.ts:4–1393  ·  view source on GitHub ↗
(options : any)

Source from the content-addressed store, hash-verified

2(function diffview_init(): void {
3 "use strict";
4 const diffview = function diffview_(options : any): [string, number, number]{
5 const tab: string = (function diffview_tab(): string {
6 let a: number = 0;
7 const output: string[] = [];
8 if (options.indent_char === "" || options.indent_size < 1) {
9 return "";
10 }
11 do {
12 output.push(options.indent_char);
13 a = a + 1;
14 } while (a < options.indent_size);
15 return output.join("");
16 }()),
17 // translates source code from a string to an array by splitting on line breaks
18 stringAsLines = function diffview_stringAsLines(str : string): string[]{
19 const lines = (options.diff_format === "text")
20 ? str
21 : str
22 .replace(/&/g, "&amp;")
23 .replace(/&#lt;/g, "$#lt;")
24 .replace(/&#gt;/g, "$#gt;")
25 .replace(/</g, "$#lt;")
26 .replace(/>/g, "$#gt;");
27 if (options.crlf === true) {
28 return lines.split("\r\n");
29 }
30 return lines.split("\n");
31 },
32 // array representation of base source
33 baseTextArray: string[] = (typeof options.source === "string")
34 ? stringAsLines(options.source)
35 : options.source,
36 // array representation of new source
37 newTextArray: string[] = (typeof options.diff === "string")
38 ? stringAsLines(options.diff)
39 : options.diff,
40 codeBuild = function diffview_opcodes(): opcodes {
41 const table: difftable = {},
42 one: string[] = baseTextArray,
43 two: string[] = newTextArray;
44 let lena: number = one.length,
45 lenb: number = two.length,
46 a: number = 0,
47 b: number = 0,
48 c: number = 0,
49 d: number = 0,
50 codes: opcodes = [],
51 fix = function diffview_opcodes_fix(code:codes): void {
52 let len:number = codes.length - 1,
53 prior:[string, number, number, number, number] = codes[len];
54 if (prior !== undefined) {
55 if (prior[0] === code[0]) {
56 if (code[0] === "replace" || code[0] === "equal") {
57 prior[2] = code[2];
58 prior[4] = code[4];
59 } else if (code[0] === "delete") {
60 prior[2] = code[2];
61 } else if (code[0] === "insert") {

Callers

nothing calls this directly

Calls 5

stringAsLinesFunction · 0.85
codeBuildFunction · 0.85
noTabFunction · 0.85
htmlfixFunction · 0.85
charcompFunction · 0.85

Tested by

no test coverage detected