1 | import type * as fs from 'node:fs';
|
2 |
|
3 | export type Options = {
|
4 | /**
|
5 | The directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/).
|
6 |
|
7 | @default 0o777
|
8 | */
|
9 | readonly mode?: number;
|
10 |
|
11 | /**
|
12 | Use a custom `fs` implementation. For example [`graceful-fs`](https://github.com/isaacs/node-graceful-fs).
|
13 |
|
14 | 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.
|
15 |
|
16 | Default: `import fs from 'node:fs'`
|
17 | */
|
18 | readonly fs?: typeof fs;
|
19 | };
|
20 |
|
21 | /**
|
22 | Make a directory and its parents if needed - Think `mkdir -p`.
|
23 |
|
24 | @param path - The directory to create.
|
25 | @returns The path to the created directory.
|
26 |
|
27 | @example
|
28 | ```
|
29 | import {makeDirectory} from 'make-dir';
|
30 |
|
31 | const path = await makeDirectory('unicorn/rainbow/cake');
|
32 |
|
33 | console.log(path);
|
34 | //=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
|
35 |
|
36 | // Multiple directories:
|
37 | const paths = await Promise.all([
|
38 | makeDirectory('unicorn/rainbow'),
|
39 | makeDirectory('foo/bar')
|
40 | ]);
|
41 |
|
42 | console.log(paths);
|
43 | // [
|
44 | // '/Users/sindresorhus/fun/unicorn/rainbow',
|
45 | // '/Users/sindresorhus/fun/foo/bar'
|
46 | // ]
|
47 | ```
|
48 | */
|
49 | export function makeDirectory(path: string, options?: Options): Promise<string>;
|
50 |
|
51 | /**
|
52 | Synchronously make a directory and its parents if needed - Think `mkdir -p`.
|
53 |
|
54 | @param path - The directory to create.
|
55 | @returns The path to the created directory.
|
56 |
|
57 | @example
|
58 | ```
|
59 | import {makeDirectorySync} from 'make-dir';
|
60 |
|
61 | const path = makeDirectorySync('unicorn/rainbow/cake');
|
62 |
|
63 | console.log(path);
|
64 | //=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
|
65 | ```
|
66 | */
|
67 | export function makeDirectorySync(path: string, options?: Options): string;
|