utils.js 493 B

1234567891011121314151617
  1. 'use strict'
  2. const fs = require('fs-extra')
  3. /**
  4. * Save a search result o to a JSON file
  5. * @param {Object[]} obj Your JavaScript object
  6. * @param {String} path Output path
  7. * @param {Boolean} prettyPrint Should the JSON be pretty-printed
  8. * @returns {Promise<void>} Newly created file path
  9. */
  10. const outputToFile = async (obj, path, prettyPrint) => {
  11. await fs.ensureFile(path)
  12. await fs.outputJson(path, obj, { spaces: prettyPrint ? 2 : undefined })
  13. }
  14. module.exports = { outputToFile }