generateVideos.js 722 B

1234567891011121314151617181920212223242526
  1. /* eslint-disable @typescript-eslint/no-var-requires */
  2. const faker = require('faker')
  3. const { saveToFile, randomRange } = require('./utils')
  4. const OUTPUT_FILENAME = 'videos.json'
  5. const VIDEOS_COUNT = 100
  6. const generateVideo = () => {
  7. const titleWordsCount = randomRange(2, 6)
  8. const descriptionSentenceCount = randomRange(2, 12)
  9. return {
  10. id: faker.random.uuid(),
  11. title: faker.lorem.words(titleWordsCount),
  12. description: faker.lorem.sentences(descriptionSentenceCount),
  13. views: faker.random.number(150000),
  14. createdAt: faker.date.past(10),
  15. }
  16. }
  17. const main = async () => {
  18. const videos = Array.from({ length: VIDEOS_COUNT }, generateVideo)
  19. await saveToFile(videos, OUTPUT_FILENAME)
  20. }
  21. main()