index.js 429 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var fs = require('graceful-fs');
  3. var tempfile = require('tempfile');
  4. module.exports = function (str, ext, cb) {
  5. if (typeof ext === 'function') {
  6. cb = ext;
  7. ext = null;
  8. }
  9. var filePath = tempfile(ext);
  10. fs.writeFile(filePath, str, function (err) {
  11. cb(err, filePath);
  12. });
  13. };
  14. module.exports.sync = function (str, ext) {
  15. var filePath = tempfile(ext);
  16. fs.writeFileSync(filePath, str);
  17. return filePath;
  18. };