-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfakeGenerator.js
More file actions
41 lines (37 loc) · 1.15 KB
/
Copy pathfakeGenerator.js
File metadata and controls
41 lines (37 loc) · 1.15 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
/* eslint-disable */
const faker = require('faker')
const converter = require('number-to-words')
const fs = require('fs')
const randomNumber = (num, addOn = 1) =>
Math.floor(Math.random() * num) + addOn
const createBlock = (idx) => {
const imageCategories = Object.keys(faker?.image).filter(
(item) => item !== 'dataUri',
)
const imageCategory = () =>
imageCategories[randomNumber(imageCategories.length - 2)]
const categoryString = `{{image.${imageCategory()}}}`
const imageUrl = () =>
`${faker.fake(categoryString)}?random=${randomNumber(1000)}`
const title = `${converter.toWordsOrdinal(idx + 1)}`
const titleCapitalized = `${
title.charAt(0).toUpperCase() + title.slice(1)
} Block`
return {
title: titleCapitalized,
images: [...Array(randomNumber(4, 1)).keys()].map((_i) => imageUrl()),
}
}
const generateBlocks = (limit) => {
let collection = []
for (let i = 0; i < limit; i++) {
collection = [...collection, createBlock(i)]
}
return collection
}
const limit = randomNumber(16, 5)
const data = generateBlocks(limit)
const json = JSON.stringify({
data,
})
fs.writeFile('./db.json', json, 'utf8', () => null)