spread-diff-patch
Version:
Diff & patch SpreadSheet files
1 lines • 2.75 kB
Source Map (JSON)
{"version":3,"sources":["../../src/formatter/csv.ts","../../src/formatter/index.ts"],"sourcesContent":["import Papa from \"papaparse\";\r\nimport Formatter from \".\"\r\n\r\ntype DiffAOA = (string | (string | null)[])[][]\r\n\r\n/**\r\n * Represents a CSV formatter that converts a DiffAOA (Array of Arrays) into a CSV string.\r\n */\r\nexport class CSV extends Formatter<string> {\r\n /**\r\n * Formats the given DiffAOA into a CSV string.\r\n * @param diffAOA - The DiffAOA to be formatted.\r\n * @returns The formatted CSV string.\r\n */\r\n format(diffAOA: DiffAOA): string {\r\n const patchedAOA = diffAOA.map((row) => {\r\n return row.map((cell) => Array.isArray(cell) ? this.patch(cell[0],cell[1]) : cell)\r\n })\r\n return Papa.unparse(patchedAOA);\r\n }\r\n}","/* eslint-disable @typescript-eslint/no-unused-vars */\r\n\r\nimport DiffAOA from \"../DiffAOA\"\r\n\r\n/**\r\n * Represents a Formatter class.\r\n * @template T - The type parameter for the Formatter class.\r\n */\r\nexport default class Formatter<T> {\r\n patch: (actual: string | null, expected: string | null) => string\r\n\r\n /**\r\n * Creates an instance of Formatter.\r\n * @param {Function} patcher - The patcher function used to generate the patched string.\r\n */\r\n constructor(\r\n patcher = (actual: string | null, expected: string | null) => {\r\n let patchedString = \"\"\r\n if (actual)\r\n patchedString += `[-][${actual}]`\r\n if (actual && expected)\r\n patchedString += \" \"\r\n if (expected)\r\n patchedString += `[+][${expected}]`\r\n return patchedString\r\n }\r\n ) {\r\n this.patch = patcher\r\n }\r\n\r\n /**\r\n * Formats the diff array of arrays.\r\n * @param diffAOA - The diff array of arrays to be formatted.\r\n * @returns The formatted string.\r\n */\r\n format(diffAOA: DiffAOA<T>): string {\r\n throw new Error(\"Method not implemented.\");\r\n }\r\n}"],"mappings":";AAAA,OAAO,UAAU;;;ACQjB,IAAqB,YAArB,MAAkC;AAAA;AAAA;AAAA;AAAA;AAAA,EAO9B,YACI,UAAU,CAAC,QAAuB,aAA4B;AAC1D,QAAI,gBAAgB;AACpB,QAAI;AACA,uBAAiB,OAAO,MAAM;AAClC,QAAI,UAAU;AACV,uBAAiB;AACrB,QAAI;AACA,uBAAiB,OAAO,QAAQ;AACpC,WAAO;AAAA,EACX,GACF;AACE,SAAK,QAAQ;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,SAA6B;AAChC,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC7C;AACJ;;;AD9BO,IAAM,MAAN,cAAkB,UAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvC,OAAO,SAA0B;AAC7B,UAAM,aAAa,QAAQ,IAAI,CAAC,QAAQ;AACpC,aAAO,IAAI,IAAI,CAAC,SAAS,MAAM,QAAQ,IAAI,IAAI,KAAK,MAAM,KAAK,CAAC,GAAE,KAAK,CAAC,CAAC,IAAI,IAAI;AAAA,IACrF,CAAC;AACD,WAAO,KAAK,QAAQ,UAAU;AAAA,EAClC;AACJ;","names":[]}