dir
A directory utility module- dir
- ~walk(dir, opts) ⇒ Promise.<FSItem>
- ~walkSync(dir, opts) ⇒ FSItem
- ~flatten(dir, opts) ⇒ Promise.<Array.<FSItem>>
- ~flattenSync(dir, opts) ⇒ Array.<FSItem>
- ~FSItem : Object
- ~RegExpsOrFunction
- ~StringOrBoolean
dir~walk(dir, opts) ⇒ Promise.<FSItem>
Walk a directory recursively and return a json treeParam | Type | Default | Description |
---|---|---|---|
dir | String | directory | |
opts | Object | options | |
opts.includes | RegExpsOrFunction | Apply including regex or function on both directory and file | |
opts.excludes | RegExpsOrFunction | Apply excluding regex or function on both directory and file | |
opts.onStep | function | Callback for every single walking step | |
[opts.ignoreNotAccessible] | Boolean | true |
Whether ignore the none-accessible directory or file |
[opts.normalizePath] | Boolean | true |
Normalize the path, convert the windows style to the linux one |
[opts.maxLevel] | Number | -1 |
The maximum level of the down-walking |
[opts.gitignore] | StringOrBoolean | .gitignore |
Apply the nearest gitignore patterns when walking |
opts.extensions | RegExp | Apply extension regex on file |
Returns: Promise.<FSItem> - A json tree representing the target directory
dir~walkSync(dir, opts) ⇒ FSItem
Walk a directory recursively and return a json treeParam | Type | Default | Description |
---|---|---|---|
dir | String | directory | |
opts | Object | options | |
opts.includes | RegExpsOrFunction | Apply including regex or function on both directory and file | |
opts.excludes | RegExpsOrFunction | Apply excluding regex or function on both directory and file | |
opts.onStep | function | Callback for every single walking step | |
[opts.ignoreNotAccessible] | Boolean | true |
Whether ignore the none-accessible directory or file |
[opts.normalizePath] | Boolean | true |
Normalize the path, convert the windows style to the linux one |
[opts.maxLevel] | Number | -1 |
The maximum level of the down-walking |
[opts.gitignore] | StringOrBoolean | .gitignore |
Apply the nearest gitignore patterns when walking |
opts.extensions | RegExp | Apply extension regex on file |
Returns: FSItem - A json tree representing the target directory
dir~flatten(dir, opts) ⇒ Promise.<Array.<FSItem>>
Walk a directory tree and get its files and sub-directories into a flat arrayParam | Type | Default | Description |
---|---|---|---|
dir | String | directory | |
opts | Object | options | |
opts.includes | RegExpsOrFunction | Apply including regex or function on both directory and file | |
opts.excludes | RegExpsOrFunction | Apply excluding regex or function on both directory and file | |
opts.onStep | function | Callback for every single walking step | |
[opts.ignoreNotAccessible] | Boolean | true |
Whether ignore the none-accessible directory or file |
[opts.normalizePath] | Boolean | true |
Normalize the path, convert the windows style to the linux one |
[opts.maxLevel] | Number | -1 |
The maximum level of the down-walking |
[opts.gitignore] | StringOrBoolean | .gitignore |
Apply the nearest gitignore patterns when walking |
opts.extensions | RegExp | Apply extension regex on file |
Returns: Promise.<Array.<FSItem>> - An Object Array representing the target directory
dir~flattenSync(dir, opts) ⇒ Array.<FSItem>
Walk a directory tree and get its files and sub-directories into a flat arrayParam | Type | Default | Description |
---|---|---|---|
dir | String | directory | |
opts | Object | options | |
opts.includes | RegExpsOrFunction | Apply including regex or function on both directory and file | |
opts.excludes | RegExpsOrFunction | Apply excluding regex or function on both directory and file | |
opts.onStep | function | Callback for every single walking step | |
[opts.ignoreNotAccessible] | Boolean | true |
Whether ignore the none-accessible directory or file |
[opts.normalizePath] | Boolean | true |
Normalize the path, convert the windows style to the linux one |
[opts.maxLevel] | Number | -1 |
The maximum level of the down-walking |
[opts.gitignore] | StringOrBoolean | .gitignore |
Apply the nearest gitignore patterns when walking |
opts.extensions | RegExp | Apply extension regex on file |
Returns: Array.<FSItem> - An Object Array representing the target directory
dir~FSItem : Object
The json object representing a directory or a fileProperties
Name | Type | Description |
---|---|---|
name | String | The name of the directory or file |
path | String | The absolute path of the directory or file |
type | String | The FSItem type, possible values are directory and file |
size | Number | The size of the directory or file |
level | Number | The level of the directory or file, note that the root directory has a level with 0 |
children | Array.<FSItem> | The children of the current directory |
extension | String | The extension of the current file |