Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mk-dirs

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mk-dirs - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

dist/index.js

28

package.json
{
"name": "mk-dirs",
"version": "1.0.0",
"description": "Make a directory and its parents, if necessary.",
"version": "2.0.0",
"repository": "lukeed/mk-dirs",
"main": "lib/index.js",
"description": "A tiny (420B) utility to make a directory and its parents, recursively",
"module": "dist/index.mjs",
"main": "dist/index.js",
"types": "mkdirs.d.ts",
"license": "MIT",
"files": [
"lib"
"*.d.ts",
"dist"
],

@@ -17,19 +20,20 @@ "author": {

"engines": {
"node": ">=4"
"node": ">=8"
},
"scripts": {
"build": "bundt",
"bench": "node bench",
"precommit": "prettier --single-quote --use-tabs --print-width=100 --write '{lib,test}/*.js'",
"pretest": "npm run build",
"test": "tape test/*.js | tap-spec"
},
"keywords": [
""
"mkdir",
"mkdirp"
],
"devDependencies": {
"bluebird": "^3.5.0",
"graceful-fs": "^4.1.11",
"tap-spec": "^4.1.1",
"tape": "^4.6.3",
"tempy": "^0.1.0"
"bundt": "^0.4.0",
"premove": "^1.0.0",
"tap-spec": "^5.0.0",
"tape": "^4.10.2"
}
}

@@ -1,10 +0,34 @@

# mk-dirs [![Build Status: OSX & Linux](https://travis-ci.org/lukeed/mk-dirs.svg?branch=master)](https://travis-ci.org/lukeed/mk-dirs) [![Build Status: Windows](https://ci.appveyor.com/api/projects/status/syt3wy6mx7dsia2d/branch/master?svg=true)](https://ci.appveyor.com/project/lukeed/mk-dirs/branch/master)
# mk-dirs [![Build Status](https://badgen.now.sh/travis/lukeed/mk-dirs)](https://travis-ci.org/lukeed/mk-dirs)
> Make a directory and its parents, if necessary.
> A tiny (420B) utility to make a directory and its parents, recursively
This is a fast and lightweight alternative to [`mkdirp`](https://github.com/substack/node-mkdirp). It's also heavily inspired by [`make-dir`](https://github.com/sindresorhus/make-dir).
This is a `Promise`-based utility that recursively creates directories.<br>
It's effectively `mkdir -p` for Node.js
This module is a fast and lightweight alternative to [`mkdirp`](https://github.com/substack/node-mkdirp).<br>
Check out [Comparisons](#comparisons) for more info!
> **Important:** Requires Node 8.x or later – uses `async` functions.
Available in these formats:
* **ES Module**: `dist/index.mjs`
* **CommonJS**: `dist/index.js`
> **Note:**<br>
> Are you using Node.js 10.12 or later?<br>
> If so, You should use the built-in [`fs.mkdir`](https://nodejs.org/api/fs.html#fs_fs_mkdir_path_options_callback) instead!
```js
const { mkdir } = require('fs');
const { promisify } = require('util');
const mkdirp = promisify(mkdir);
function mkdirs(str, opts={}) {
return mkdirp(str, { ...opts, recursive:true });
}
```
## Install

@@ -19,70 +43,73 @@

```js
```sh
$ pwd
/Users/hello/world
# /Users/hello/world
$ tree
.
# .
```
```js
const mkdir = require('mk-dirs');
import mkdirs from 'mk-dirs';
import { resolve } from 'path';
mkdir('foo/bar/baz').then(path => {
console.log(path);
//=> '/Users/hello/world/foo/bar/baz'
// Async/await
try {
let output = await mkdirs('foo/bar/baz');
console.log(output); //=> "/Users/hello/world/foo/bar/baz"
} catch (err) {
//
}
// Promises
mkdirs('foo/bar/baz').then(output => {
console.log(output); //=> "/Users/hello/world/foo/bar/baz"
}).catch(err => {
//
});
// Using `cwd` option
let dir = resolve('foo/bar');
await mkdirs('hola/mundo', { cwd: dir });
//=> "/Users/hello/world/foo/bar/hola/mundo"
```
```
```sh
$ tree
.
└── foo
└── bar
└── baz
# .
# └── foo
# └── bar
# └── baz
# └── hola
# └── mundo
```
#### Multiple Directories
```js
const mkdir = require('mk-dirs');
Promise.all([
mkdir('cat/cow'),
mkdir('foo/bar/baz')
]).then(paths => {
console.log(paths);
//=> [ '/Users/hello/world/cat/cow', '/Users/hello/world/foo/bar/baz' ]
});
```
## API
### mkdir(path, [options])
### mkdir(path, options={})
Returns: `Promise<String>`
Returns a `Promise`, which resolves with the full path of the created directory.
Returns a `Promise`, which resolves with the full path (string) of the created directory.<br>
Any file system errors will be thrown and must be caught manually.
#### path
Type: `String`
Type: `string`
The directory to create.
Directory to create.
#### options.cwd
Type: `String`<br>
Default: `.`
#### options.fs
The directory to resolve your `path` from.<br>
Defaults to the `process.cwd()` – aka, the directory that your command is run within.
Type: `object`<br>
Default: `require('fs')`
Optionally use a custom `fs` implementation. For example [`graceful-fs`](https://github.com/isaacs/node-graceful-fs).
> **Important:** Must include `mkdir` and `stat` methods!
#### options.mode
Type: `integer`<br>
Type: `Number`<br>
Default: `0o777 & (~process.umask())`
Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/).
The directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/) to set.
> **Note:** Must be in octal format!
> **Important:** Must be in octal format!

@@ -92,34 +119,30 @@

#### make-dir
***Versus `make-dir`***
* _Slightly faster_
* Doesn't re-wrap an existing Promise
* Doesn't ship with a `.sync` method
* Zero dependencies
* `mk-dirs` is slightly faster
* ...has zero dependencies
* ...does offer `cwd` option
* ...does not re-wrap an existing Promise
* ...does not ship with a `sync` method
* ...does not allow custom `fs` option
#### mkdirp
***Versus `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)
* CI-tested on macOS, Linux, and Windows
* Doesn't ship with a `.sync` method
* Doesn't bundle a CLI
* `mk-dirs` is _much_ faster
* ...has zero dependencies
* ...is a Promise-based API
* ...is `async`/`await` ready!
* ...is tested on macOS, Linux, and Windows
* ... has fixes for `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)
* ...includes a `cwd` option
* ...does not ship with a `sync` method
* ...does not allow custom `fs` option
* ...does not bundle a CLI runtime
## Related
## Benchmarks
- [`premove`](https://github.com/lukeed/premove) – A tiny (247B) utility to remove items recursively
:bulb: Please consider that these benchmarks are _largely affected_ by System behavior! In other words, the time it takes your OS to create a directory _is never consistent_.
```
mk-dirs
--> 3,768 ops/sec ±1.95% (72 runs sampled)
make-dir
--> 3,527 ops/sec ±4.28% (64 runs sampled)
mkdirp
--> 3,305 ops/sec ±2.56% (67 runs sampled)
```
## License
MIT © [Luke Edwards](https://lukeed.com)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc