You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
820 B
JavaScript

#!/usr/bin/env node
"use strict";
const fs = require("fs");
const chalk = require("chalk");
const path = require("path");
if (process.argv[2] == null) {
console.error(chalk.red("You must specify one or more MT940 (.STA) files to fix, like so:\n abn-amro-mt940-fix YOUR-FILE.STA"));
} else {
process.argv.slice(2).forEach((file) => {
let absolutePath = path.resolve(file);
let contents = fs.readFileSync(absolutePath, { encoding: "utf8" });
let parsedPath = path.parse(absolutePath);
delete parsedPath.base;
parsedPath.name += "-fixed";
let fixedContents = contents.replace(/(^|\r\n-\r\n)ABNANL2A\r\n940\r\nABNANL2A\r\n/g, "$1");
let fixedFilename = path.format(parsedPath);
fs.writeFileSync(fixedFilename, fixedContents, { encoding: "utf8" })
console.log(file, "->", fixedFilename);
});
}