UNPKG

1.64 kBTypeScriptView Raw
1import type * as fs from 'node:fs';
2
3export 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/**
22Make 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```
29import {makeDirectory} from 'make-dir';
30
31const path = await makeDirectory('unicorn/rainbow/cake');
32
33console.log(path);
34//=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
35
36// Multiple directories:
37const paths = await Promise.all([
38 makeDirectory('unicorn/rainbow'),
39 makeDirectory('foo/bar')
40]);
41
42console.log(paths);
43// [
44// '/Users/sindresorhus/fun/unicorn/rainbow',
45// '/Users/sindresorhus/fun/foo/bar'
46// ]
47```
48*/
49export function makeDirectory(path: string, options?: Options): Promise<string>;
50
51/**
52Synchronously 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```
59import {makeDirectorySync} from 'make-dir';
60
61const path = makeDirectorySync('unicorn/rainbow/cake');
62
63console.log(path);
64//=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
65```
66*/
67export function makeDirectorySync(path: string, options?: Options): string;