-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.js
36 lines (31 loc) · 1.26 KB
/
users.js
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
import { appendFile } from "node:fs/promises";
import fastLoremIpsum from "fast-lorem-ipsum";
const DEFAULT_USER_COUNT = 1000;
const DEFAULT_ABOUT_HTML_WORD_COUNT = 100;
/**
* Generate a list of synthetic users to be loaded into Postgres
*
* @param {object} args
* @param {number} [args.count] number of users to generate
* @param {number} [args.aboutHTMLWordCount] number of words to generate (lorem ipsum) for about_html (serves to add heft to tuples)
* @param {string} [args.outputFilePath] output file path, if present this functoin returns void
* @returns {any[][]} List of generated synthetic users
*/
export async function generateUsers(args) {
const count = args.count || DEFAULT_USER_COUNT;
const aboutHTMLWordCount = args.aboutHTMLWordCount || DEFAULT_ABOUT_HTML_WORD_COUNT;
const outputFilePath = args.outputFilePath;
if (!outputFilePath) { throw new Error("output file path must be specified"); }
for (var id = 0; id < count; id++) {
const user = {
id,
email: `user${id}@example.com`,
name: `user ${id}`,
about_html: fastLoremIpsum(aboutHTMLWordCount, 'w'),
};
// Write the entries to disk (returning nothing)
if (args.outputFilePath) {
await appendFile(outputFilePath, `${JSON.stringify(user)}\n`);
}
}
}