28 lines
806 B
TypeScript
28 lines
806 B
TypeScript
import fs from "node:fs";
|
|
|
|
const base = "3961023";
|
|
|
|
const INPUT_FILE_NAME = `output_${base}.json`;
|
|
const OUTPUT_FILE_NAME = `mapped_output_${base}.json`;
|
|
|
|
const writeToFile = (data: object) => {
|
|
fs.writeFileSync(OUTPUT_FILE_NAME, JSON.stringify(data, undefined, 2));
|
|
};
|
|
|
|
(() => {
|
|
const existingData = fs.readFileSync(INPUT_FILE_NAME);
|
|
const existingDataMapped = JSON.parse(existingData.toString()) as [string, string][];
|
|
|
|
const formatted = existingDataMapped.reduce((acc, [idCode, value]) => ({
|
|
...acc,
|
|
...(value === "INVALID" ? {} : {
|
|
[idCode]: (() => {
|
|
const nameStartIdx = value.indexOf(": ") + 2;
|
|
const lastCommaIdx = value.lastIndexOf(",");
|
|
return value.substring(nameStartIdx, lastCommaIdx);
|
|
})(),
|
|
})
|
|
}), {});
|
|
writeToFile(formatted);
|
|
})();
|