utils.js 617 B

123456789101112131415161718192021222324
  1. /* eslint-disable @typescript-eslint/no-var-requires */
  2. const path = require('path')
  3. const fs = require('fs')
  4. const { promisify } = require('util')
  5. const writeFile = promisify(fs.writeFile)
  6. const OUTPUT_DIR = path.join(__dirname, '..', '..', 'src', 'mocking', 'data', 'raw')
  7. const randomRange = (min, max) => {
  8. return Math.random() * (max - min) + min
  9. }
  10. const saveToFile = async (object, filename) => {
  11. const jsonified = JSON.stringify(object, null, 2)
  12. const fileOutputPath = path.join(OUTPUT_DIR, filename)
  13. await writeFile(fileOutputPath, jsonified)
  14. }
  15. module.exports = {
  16. randomRange,
  17. saveToFile,
  18. }