Skip to content

Instantly share code, notes, and snippets.

@dcarroll
Created May 31, 2017 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcarroll/f106c43c21c36d0411c13bda5c1ec317 to your computer and use it in GitHub Desktop.
Save dcarroll/f106c43c21c36d0411c13bda5c1ec317 to your computer and use it in GitHub Desktop.
let fund = require("./data/dreaminvest-data-fund.json");
let plan = require("./data/dreaminvest-data-plan.json");
let records = fund.records;
let i,j,temparray = [],chunk = 200;
let fname = `data/dreaminvest-data-fund${i}d.json`;
let writeFile = function(name, contents) {
var fs = require('fs');
fs.writeFile(name, contents, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
}
let writeDataFile = function(recordData) {
writeFile("data/" + recordData.fileName, JSON.stringify(recordData.data));
temparray.push(recordData.fileName);
}
for (i=0,j=records.length; i<j; i+=chunk) {
writeDataFile(
{ "data":
{ "records":records.slice(i,i+chunk) },
"fileName": `dreaminvest-data-fund${i}.json`
}
);
}
plan[1].files = temparray;
writeFile("data/dreaminvest-data-plan.json", JSON.stringify(plan));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment