spread-diff-patch
Version:
Diff & patch SpreadSheet files
49 lines (47 loc) • 1.26 kB
JavaScript
// src/formatter/csv.ts
import Papa from "papaparse";
// src/formatter/index.ts
var Formatter = class {
/**
* Creates an instance of Formatter.
* @param {Function} patcher - The patcher function used to generate the patched string.
*/
constructor(patcher = (actual, expected) => {
let patchedString = "";
if (actual)
patchedString += `[-][${actual}]`;
if (actual && expected)
patchedString += " ";
if (expected)
patchedString += `[+][${expected}]`;
return patchedString;
}) {
this.patch = patcher;
}
/**
* Formats the diff array of arrays.
* @param diffAOA - The diff array of arrays to be formatted.
* @returns The formatted string.
*/
format(diffAOA) {
throw new Error("Method not implemented.");
}
};
// src/formatter/csv.ts
var CSV = class extends Formatter {
/**
* Formats the given DiffAOA into a CSV string.
* @param diffAOA - The DiffAOA to be formatted.
* @returns The formatted CSV string.
*/
format(diffAOA) {
const patchedAOA = diffAOA.map((row) => {
return row.map((cell) => Array.isArray(cell) ? this.patch(cell[0], cell[1]) : cell);
});
return Papa.unparse(patchedAOA);
}
};
export {
CSV
};
//# sourceMappingURL=csv.mjs.map