index.d.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /// <reference types="node"/>
  2. import * as fs from 'fs';
  3. declare namespace makeDir {
  4. interface Options {
  5. /**
  6. Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/).
  7. @default 0o777
  8. */
  9. readonly mode?: number;
  10. /**
  11. Use a custom `fs` implementation. For example [`graceful-fs`](https://github.com/isaacs/node-graceful-fs).
  12. Using a custom `fs` implementation will block the use of the native `recursive` option if `fs.mkdir` or `fs.mkdirSync` is not the native function.
  13. @default require('fs')
  14. */
  15. readonly fs?: typeof fs;
  16. }
  17. }
  18. declare const makeDir: {
  19. /**
  20. Make a directory and its parents if needed - Think `mkdir -p`.
  21. @param path - Directory to create.
  22. @returns The path to the created directory.
  23. @example
  24. ```
  25. import makeDir = require('make-dir');
  26. (async () => {
  27. const path = await makeDir('unicorn/rainbow/cake');
  28. console.log(path);
  29. //=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
  30. // Multiple directories:
  31. const paths = await Promise.all([
  32. makeDir('unicorn/rainbow'),
  33. makeDir('foo/bar')
  34. ]);
  35. console.log(paths);
  36. // [
  37. // '/Users/sindresorhus/fun/unicorn/rainbow',
  38. // '/Users/sindresorhus/fun/foo/bar'
  39. // ]
  40. })();
  41. ```
  42. */
  43. (path: string, options?: makeDir.Options): Promise<string>;
  44. /**
  45. Synchronously make a directory and its parents if needed - Think `mkdir -p`.
  46. @param path - Directory to create.
  47. @returns The path to the created directory.
  48. */
  49. sync(path: string, options?: makeDir.Options): string;
  50. };
  51. export = makeDir;