forked from catberry/catberry-todomvc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.js
47 lines (38 loc) · 1.01 KB
/
generate.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
37
38
39
40
41
42
43
44
45
46
47
'use strict';
const SIZE = Number(process.argv[2]);
if (isNaN(SIZE)) {
console.error('You should specify data size by the first parameter'); // eslint-disable-line no-console
process.exit();
return;
}
const POSSIBLE_NAMES = [
'Eric', 'Aaron', 'Dennis', 'Julia',
'John', 'Federic', 'Thomas', 'Pieter'
];
const POSSIBLE_SURNAMES = [
'Newton', 'Smith', 'Johnson', 'Ritchie',
'Ocean', 'Castle', 'Torwalds', 'Einstein'
];
/**
* Gets a random element in an array
* @param {Array<string>} array
* @returns {string}
*/
function random(array) {
return array[Math.floor(Math.random() * array.length)];
}
const result = [];
for (let i = 0; i < SIZE; i++) {
const currentName = random(POSSIBLE_NAMES);
const currentSurname = random(POSSIBLE_SURNAMES);
result.push({
label: `Tell ${currentName} ${currentSurname} about Catberry`,
isCompleted: Math.random() < 0.5
});
}
const fs = require('fs');
const file = fs.createWriteStream('./todos.json');
const json = JSON.stringify({
items: result
}, null, ' ');
file.end(json);