Skip to content

Commit

Permalink
Readme tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 25, 2023
1 parent 9b2bb1e commit 57aa7aa
Showing 1 changed file with 26 additions and 41 deletions.
67 changes: 26 additions & 41 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

> Make a directory and its parents if needed - Think `mkdir -p`
## Advantages over [`mkdirp`](https://github.com/substack/node-mkdirp)
**You probably want the built-in [`fsPromises.mkdir('…', {recursive: true})`](https://nodejs.org/api/fs.html#fspromisesmkdirpath-options) instead.**

### Advantages over [`mkdirp`](https://github.com/substack/node-mkdirp)

- Promise API *(Async/await ready!)*
- Fixes many `mkdirp` issues: [#96](https://github.com/substack/node-mkdirp/pull/96) [#70](https://github.com/substack/node-mkdirp/issues/70) [#66](https://github.com/substack/node-mkdirp/issues/66)
- 100% test coverage
- CI-tested on macOS, Linux, and Windows
- Actively maintained
- Doesn't bundle a CLI
- Uses the native `fs.mkdir/mkdirSync` [`recursive` option](https://nodejs.org/dist/latest/docs/api/fs.html#fs_fs_mkdir_path_options_callback) in Node.js >=10.12.0 unless [overridden](#fs)

## Install

```
$ npm install make-dir
```sh
npm install make-dir
```

## Usage
Expand All @@ -28,14 +29,12 @@ $ tree
```

```js
const makeDir = require('make-dir');
import makeDirectory from 'make-dir';

(async () => {
const path = await makeDir('unicorn/rainbow/cake');
const path = await makeDirectory('unicorn/rainbow/cake');

console.log(path);
//=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
})();
console.log(path);
//=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
```

```
Expand All @@ -49,31 +48,29 @@ $ tree
Multiple directories:

```js
const makeDir = require('make-dir');

(async () => {
const paths = await Promise.all([
makeDir('unicorn/rainbow'),
makeDir('foo/bar')
]);

console.log(paths);
/*
[
'/Users/sindresorhus/fun/unicorn/rainbow',
'/Users/sindresorhus/fun/foo/bar'
]
*/
})();
import makeDirectory from 'make-dir';

const paths = await Promise.all([
makeDirectory('unicorn/rainbow'),
makeDirectory('foo/bar')
]);

console.log(paths);
/*
[
'/Users/sindresorhus/fun/unicorn/rainbow',
'/Users/sindresorhus/fun/foo/bar'
]
*/
```

## API

### makeDir(path, options?)
### makeDirectory(path, options?)

Returns a `Promise` for the path to the created directory.

### makeDir.sync(path, options?)
### makeDirectory.sync(path, options?)

Returns the path to the created directory.

Expand All @@ -97,7 +94,7 @@ Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-no
##### fs

Type: `object`\
Default: `require('fs')`
Default: `import fs from 'node:fs'`

Use a custom `fs` implementation. For example [`graceful-fs`](https://github.com/isaacs/node-graceful-fs).

Expand All @@ -111,15 +108,3 @@ Using a custom `fs` implementation will block the use of the native `recursive`
- [cpy](https://github.com/sindresorhus/cpy) - Copy files
- [cpy-cli](https://github.com/sindresorhus/cpy-cli) - Copy files on the command-line
- [move-file](https://github.com/sindresorhus/move-file) - Move a file

---

<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-make-dir?utm_source=npm-make-dir&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>

0 comments on commit 57aa7aa

Please sign in to comment.