node-mkp
mkp
(mk path) is a node.js module that recursively creates paths, both directory and file with brace expansion support. It means, you can do stuff like mkdir -p /some/dir/{foo,bar}/baz
, but in node.js!
Install
npm i mkp
Usage
mkp(input[, options], cb)
-
input
{String | Array<String>}
string or an array of strings of normal paths (file and dir) and/or braces patterns. -
options
{Object}
optional (all options arefalse
by default) -
noext
{Boolean}
- the default behavior is if path doesn't have extname, it is created as a directory. If
{noext: true}
then paths without extname will be created as files and not dirs. It is basically used when you want to create file(s) without extname, like/some/filenoext
.
- the default behavior is if path doesn't have extname, it is created as a directory. If
-
return
cb(err)
with possible err or null.
Create files and/or dirs. input
can be file, dir, things like /some/foo-{1..3}/file.js
or an array of each or combination of all of them. It doesn't matter. Just put it there, you most likely get what you want. It couldn't be simpler than this. Please checkout examples down below.
mkp.sync(input[, options])
create files and dirs sync. input
and options
are the same as async version. It throws err if any found.
const mkp = var dir = 'some/nested/dir'try mkp console catch er console
Examples
In all examples, it is assumed
const mkp =
is declared before.
dirs (input is string)
var dir = 'some/nested/dir'
var dirs = 'some/nested/dir-{a,b,c}'
var dirs = 'some/nested/dir-{a..c}'
var dirs = 'some/nested/{foo,bar}/dir-{a..e..2}'
var dirs = 'some/nested/{foo,{1..3},bar}/dir'
files (input is string)
var file = 'some/nested/file.js'
var files = 'some/nested/file-{a,b,c}.js'
var files = 'some/nested/file-{a..c}.js'
var files = 'some/nested/{foo,bar}/file-{a..e..2}.js'
var files = 'some/nested/{foo,{1..3},bar}/file.js'
noext
option (useful when you want to create files with no extname)
var file = 'some/nested/filenoext'// without {noext: true}, it will be created as dir
var file = 'some/nested/filenoext'// now it will be created as file
input is array
var dirs = 'some/nested/dir-{a,b,c}' 'some/other/nested/dir'
var files = 'some/nested/file-{a,b,c}.js' 'some/other/nested/file.md'
var paths = 'some/nested/dir-{a,b,c}' 'some/nested/file-{a,b,c}.js' 'some/other/nested/dir' 'some/other/nested/file.js'
License
Licensed under MIT