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