initial commit
This commit is contained in:
27
filter.ts
Normal file
27
filter.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
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);
|
||||
})();
|
||||
Reference in New Issue
Block a user