6948f4fff6bc6b387e6bd630b1f2f4cbddcbf475f7c5e735a088e70c92d08cfbcabd1a0029c018b1feda377d1d5dcaa13b9cad0622b0b6caeffeee9ea78305 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.optsArg = void 0;
  4. const fs_1 = require("fs");
  5. const optsArg = (opts) => {
  6. if (!opts) {
  7. opts = { mode: 0o777 };
  8. }
  9. else if (typeof opts === 'object') {
  10. opts = { mode: 0o777, ...opts };
  11. }
  12. else if (typeof opts === 'number') {
  13. opts = { mode: opts };
  14. }
  15. else if (typeof opts === 'string') {
  16. opts = { mode: parseInt(opts, 8) };
  17. }
  18. else {
  19. throw new TypeError('invalid options argument');
  20. }
  21. const resolved = opts;
  22. const optsFs = opts.fs || {};
  23. opts.mkdir = opts.mkdir || optsFs.mkdir || fs_1.mkdir;
  24. opts.mkdirAsync = opts.mkdirAsync
  25. ? opts.mkdirAsync
  26. : async (path, options) => {
  27. return new Promise((res, rej) => resolved.mkdir(path, options, (er, made) => er ? rej(er) : res(made)));
  28. };
  29. opts.stat = opts.stat || optsFs.stat || fs_1.stat;
  30. opts.statAsync = opts.statAsync
  31. ? opts.statAsync
  32. : async (path) => new Promise((res, rej) => resolved.stat(path, (err, stats) => (err ? rej(err) : res(stats))));
  33. opts.statSync = opts.statSync || optsFs.statSync || fs_1.statSync;
  34. opts.mkdirSync = opts.mkdirSync || optsFs.mkdirSync || fs_1.mkdirSync;
  35. return resolved;
  36. };
  37. exports.optsArg = optsArg;
  38. //# sourceMappingURL=opts-arg.js.map