Skip to content
/ mk-dirs Public

A tiny (381B to 419B) utility to make a directory and its parents, recursively

License

Notifications You must be signed in to change notification settings

lukeed/mk-dirs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mk-dirs Build Status: OSX & Linux Build Status: Windows

Make a directory and its parents, if necessary.

This is a fast and lightweight alternative to mkdirp. It's also heavily inspired by make-dir.

Check out Comparisons for more info!

Install

$ npm install --save mk-dirs

Usage

$ pwd
/Users/hello/world
$ tree
.
const mkdir = require('mk-dirs');

mkdir('foo/bar/baz').then(path => {
  console.log(path);
  //=> '/Users/hello/world/foo/bar/baz'
});
$ tree
.
└── foo
    └── bar
        └── baz

Multiple Directories

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])

Returns a Promise, which resolves with the full path of the created directory.

path

Type: string

Directory to create.

options.fs

Type: object
Default: require('fs')

Optionally use a custom fs implementation. For example graceful-fs.

Important: Must include mkdir and stat methods!

options.mode

Type: integer
Default: 0o777 & (~process.umask())

Directory permissions.

Note: Must be in octal format!

Comparisons

make-dir

  • Slightly faster
  • Doesn't re-wrap an existing Promise
  • Doesn't ship with a .sync method
  • Zero dependencies

mkdirp

  • Promise API (Async/await ready!)
  • Fixes many mkdirp issues: #96 #70 #66
  • CI-tested on macOS, Linux, and Windows
  • Doesn't ship with a .sync method
  • Doesn't bundle a CLI

Benchmarks

💡 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

About

A tiny (381B to 419B) utility to make a directory and its parents, recursively

Resources

License

Stars

Watchers

Forks