nested_json_to_csv
Advanced tools
Comparing version 2.0.3 to 2.0.4-b
@@ -5,3 +5,3 @@ import { IFactory } from "../../interfaces/IFactory"; | ||
export declare class ParserFactory implements IFactory { | ||
make(className: string, ...args: any[]): JsonParserService | CsvParserService | undefined; | ||
make(className: string, ...args: any[]): CsvParserService | JsonParserService | undefined; | ||
} |
@@ -15,2 +15,3 @@ "use strict"; | ||
} | ||
//TODO: add NULL desgin pattern here | ||
} | ||
@@ -17,0 +18,0 @@ catch (error) { |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -19,35 +10,40 @@ exports.FileSystemService = exports.Csv = exports.ParserFactory = void 0; | ||
Object.defineProperty(exports, "FileSystemService", { enumerable: true, get: function () { return FileSystemService_1.FileSystemService; } }); | ||
function main() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const jsonFile = { | ||
"1": { person: { name: "fuad", id: "1443" }, price: 123 }, | ||
"2": { person: { name: "test", id: "51542" } }, | ||
}; | ||
console.log(jsonFile); | ||
const parserFactory = new ParserFactory_1.ParserFactory(); | ||
const options = { | ||
hasId: true, | ||
single: false, | ||
setDefaultValues: true, | ||
}; | ||
const jsonParser = parserFactory.make("jsonParser", jsonFile, options); | ||
const csv = jsonParser.parse(["person.id", "person.name", "price"]); | ||
const csvData = csv.make(); | ||
console.log(csvData); | ||
const fileSystemService = new FileSystemService_1.FileSystemService("data.csv", "./Data"); | ||
yield fileSystemService.write(csvData); | ||
const csvParser = parserFactory.make("csvParser", csv); | ||
const json = csvParser.parse(); | ||
console.log(json); | ||
const newJsonParser = parserFactory.make("jsonParser", json, options); | ||
const newCsv = newJsonParser.parse([ | ||
"person.id", | ||
"person.name", | ||
"price", | ||
]); | ||
console.log(newCsv.make()); | ||
}); | ||
} | ||
main().then(() => { | ||
console.log("done"); | ||
}); | ||
// 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"); | ||
// }); |
@@ -69,2 +69,27 @@ "use strict"; | ||
}); | ||
test("complex nested json to csv with defualt values", () => { | ||
const json = { | ||
user: { name: "fox", uid: "31245324", address: { city: "nowhere" } }, | ||
child: { name: "fox", uid: "31245324" }, | ||
}; | ||
let parserFactory = new ParserFactory_1.ParserFactory(); | ||
const options = { | ||
hasId: true, | ||
single: false, | ||
setDefaultValues: true, | ||
}; | ||
const parser = parserFactory.make("jsonParser", json, options); | ||
expect(parser).toBeInstanceOf(JsonParserService_1.JsonParserService); | ||
const headers = ["uid", "name", "address.city"]; | ||
const csv = parser.parse(headers); | ||
const data = csv.make(); | ||
const rows = csv.makeRows().getRows(); | ||
console.log(rows); | ||
expect(rows).toEqual([ | ||
["user", "31245324", "fox", "nowhere"], | ||
["child", "31245324", "fox"], | ||
]); | ||
expect(data).toEqual("id,uid,name,address.city\nuser,31245324,fox,nowhere,\nchild,31245324,fox,,\n"); | ||
expect(csv.getHeaders()).toEqual(headers); | ||
}); | ||
}); |
{ | ||
"name": "nested_json_to_csv", | ||
"version": "2.0.3", | ||
"version": "2.0.4b", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "build/src/index.js", |
@@ -14,2 +14,3 @@ import { IFactory } from "../../interfaces/IFactory"; | ||
} | ||
//TODO: add NULL desgin pattern here | ||
} catch (error) { | ||
@@ -16,0 +17,0 @@ console.log(error); |
@@ -14,44 +14,44 @@ import { IFactory } from "../interfaces/IFactory"; | ||
}; | ||
async function main() { | ||
const jsonFile = { | ||
"1": { person: { name: "fuad", id: "1443" }, price: 123 }, | ||
"2": { person: { name: "test", id: "51542" } }, | ||
}; | ||
// 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); | ||
// 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 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()); | ||
} | ||
// 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"); | ||
}); | ||
// main().then(() => { | ||
// console.log("done"); | ||
// }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2694963
57501
2