Repository navigation
Expand file tree
/
Copy pathtestCsv.js
More file actions
57 lines (50 loc) · 1.43 KB
/
Copy pathtestCsv.js
File metadata and controls
57 lines (50 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import fs from "fs";
import path from "path";
import { faker } from "@faker-js/faker";
const OUTPUT_FILE = path.join("./", "large_orders.csv");
const NUM_ROWS = 99000;
const headers = [
"orderID",
"customerID",
"employeeID",
"orderDate",
"requiredDate",
"shippedDate",
"shipVia",
"freight",
"shipName",
"shipAddress",
"shipCity",
"shipRegion",
"shipPostalCode",
"shipCountry",
].join(",");
function generateRow(orderID) {
return [
orderID,
faker.string.alpha(5).toUpperCase(),
faker.number.int({ min: 1, max: 10 }),
faker.date.past().toISOString(),
faker.date.future().toISOString(),
faker.date.past().toISOString(),
faker.number.int({ min: 1, max: 3 }),
faker.number.float({ min: 10, max: 100, fractionDigits: 2 }),
faker.company.name(),
faker.location.streetAddress(),
faker.location.city(),
faker.helpers.maybe(() => faker.location.state(), { probability: 0.8 }),
faker.helpers.maybe(() => faker.location.zipCode(), { probability: 0.9 }),
faker.location.country(),
].join(",");
}
async function generateCSV() {
const stream = fs.createWriteStream(OUTPUT_FILE);
stream.write(headers + "\n");
for (let i = 10248; i < 10248 + NUM_ROWS; i++) {
const row = generateRow(i);
stream.write(row + "\n");
if (i % 10000 === 0) console.log(`Generated ${i} rows...`);
}
stream.end(() => console.log(`CSV file created: ${OUTPUT_FILE}`));
}
generateCSV();