generateChannels.js 760 B

123456789101112131415161718192021222324252627
  1. /* eslint-disable @typescript-eslint/no-var-requires */
  2. const faker = require('faker')
  3. const { saveToFile, randomRange } = require('./utils')
  4. const OUTPUT_FILENAME = 'channels.json'
  5. const CHANNELS_COUNT = 10
  6. let nextChannelId = 0
  7. const generateChannel = () => {
  8. const handleWordsCount = randomRange(1, 4)
  9. const descriptionWordsCount = randomRange(0, 30)
  10. return {
  11. id: (nextChannelId++).toString(),
  12. title: faker.lorem.words(handleWordsCount),
  13. description: faker.lorem.words(descriptionWordsCount),
  14. follows: faker.random.number(150000),
  15. createdAt: faker.date.past(10),
  16. }
  17. }
  18. const main = async () => {
  19. const channels = Array.from({ length: CHANNELS_COUNT }, generateChannel)
  20. await saveToFile(channels, OUTPUT_FILENAME)
  21. }
  22. main()