nested_json_to_csv
Version:
57 lines (52 loc) • 1.62 kB
text/typescript
import { IFactory } from "../interfaces/IFactory";
import { IParser, ParserOptions } from "../interfaces/IParser";
import { Csv } from "../models/Csv";
import { ParserFactory } from "../providers/factories/ParserFactory";
import { FileSystemService } from "../providers/services/FileSystemService";
export {
ParserFactory,
Csv,
IParser,
IFactory,
FileSystemService,
ParserOptions,
};
// async function main() {
// const jsonFile = {
// "1": { person: { name: "fuad", id: "1443" }, price: 123 },
// "2": { person: { name: "test", id: "51542" } },
// };
// console.log(jsonFile);
// const parserFactory: IFactory = new ParserFactory();
// const options: ParserOptions = {
// hasId: true,
// single: false,
// setDefaultValues: true,
// };
// const jsonParser: IParser = parserFactory.make(
// "jsonParser",
// jsonFile,
// options
// );
// const csv: Csv = jsonParser.parse(["person.id", "person.name", "price"]);
// const csvData: string = csv.make();
// console.log(csvData);
// const fileSystemService: FileSystemService = new FileSystemService(
// "data.csv",
// "./Data"
// );
// await fileSystemService.write(csvData);
// const csvParser: IParser = parserFactory.make("csvParser", csv);
// const json = csvParser.parse();
// console.log(json);
// const newJsonParser = parserFactory.make("jsonParser", json, options);
// const newCsv: Csv = newJsonParser.parse([
// "person.id",
// "person.name",
// "price",
// ]);
// console.log(newCsv.make());
// }
// main().then(() => {
// console.log("done");
// });