directory-tree 3.5.1 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/node.js.yml +2 -3
- package/README.md +68 -9
- package/bin/index.js +2 -2
- package/dark.svg +118 -0
- package/index.d.ts +2 -2
- package/lib/directory-tree.js +11 -7
- package/package.json +1 -1
|
@@ -16,16 +16,15 @@ jobs:
|
|
|
16
16
|
|
|
17
17
|
strategy:
|
|
18
18
|
matrix:
|
|
19
|
-
node-version: [
|
|
19
|
+
node-version: [22.x]
|
|
20
20
|
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
21
21
|
|
|
22
22
|
steps:
|
|
23
23
|
- uses: actions/checkout@v2
|
|
24
24
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
25
|
-
uses: actions/setup-node@
|
|
25
|
+
uses: actions/setup-node@v4
|
|
26
26
|
with:
|
|
27
27
|
node-version: ${{ matrix.node-version }}
|
|
28
|
-
cache: 'npm'
|
|
29
28
|
- run: npm ci
|
|
30
29
|
- run: npm run build --if-present
|
|
31
30
|
- run: npm test
|
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Creates a JavaScript object representing a directory tree.
|
|
4
4
|
|
|
5
|
+
This library gets [~100k downloads per week](http://npm-stats.org/#/directory-tree). If you find it useful, feel free to <a href="https://www.buymeacoffee.com/pxhxnsxsbn"><img height="40" src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" /></a> .
|
|
6
|
+
|
|
5
7
|
## Install
|
|
6
8
|
|
|
7
9
|
```bash
|
|
@@ -79,9 +81,9 @@ const tree = dirTree('./test/test_data', {extensions:/\.txt$/}, null, (item, PAT
|
|
|
79
81
|
|
|
80
82
|
`attributes` : `string[]` - Array of [FS.stats](https://nodejs.org/api/fs.html#fs_class_fs_stats) attributes.
|
|
81
83
|
|
|
82
|
-
`normalizePath` : `Boolean` - If true,
|
|
84
|
+
`normalizePath` : `Boolean` - If true, Windows style paths will be normalized to UNIX style paths (/ instead of \\).
|
|
83
85
|
|
|
84
|
-
`depth` : `number` -
|
|
86
|
+
`depth` : `number` - Limits directory traversal to the specified depth level. When combined with `size`, directories at the depth limit have `size: undefined` (see "Using size with depth" below).
|
|
85
87
|
|
|
86
88
|
## Result
|
|
87
89
|
|
|
@@ -164,6 +166,68 @@ photos
|
|
|
164
166
|
}
|
|
165
167
|
```
|
|
166
168
|
|
|
169
|
+
## Using size with depth
|
|
170
|
+
|
|
171
|
+
The `size` attribute can be used together with the `depth` option, but with an important caveat:
|
|
172
|
+
|
|
173
|
+
**When depth limiting is active:**
|
|
174
|
+
- **Files** always have accurate sizes
|
|
175
|
+
- **Directories at the depth limit** (whose children are not traversed) will have `size: undefined`
|
|
176
|
+
- **Parent directories** containing depth-limited directories will also have `size: undefined`
|
|
177
|
+
|
|
178
|
+
This is because directory sizes are calculated by recursively summing all child sizes. When depth limits prevent full traversal, the size would be incomplete and potentially misleading, so `undefined` is returned instead.
|
|
179
|
+
|
|
180
|
+
**Example:**
|
|
181
|
+
|
|
182
|
+
```js
|
|
183
|
+
const dirTree = require('directory-tree');
|
|
184
|
+
const tree = dirTree('/some/path', {
|
|
185
|
+
depth: 1,
|
|
186
|
+
attributes: ['size', 'type']
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Given this structure:
|
|
191
|
+
```
|
|
192
|
+
folder/
|
|
193
|
+
├── file1.txt (100 bytes)
|
|
194
|
+
├── file2.txt (200 bytes)
|
|
195
|
+
└── subfolder/
|
|
196
|
+
└── file3.txt (300 bytes)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
The result will be:
|
|
200
|
+
```js
|
|
201
|
+
{
|
|
202
|
+
"path": "folder",
|
|
203
|
+
"name": "folder",
|
|
204
|
+
"size": undefined,
|
|
205
|
+
"type": "directory",
|
|
206
|
+
"children": [
|
|
207
|
+
{
|
|
208
|
+
"path": "folder/file1.txt",
|
|
209
|
+
"name": "file1.txt",
|
|
210
|
+
"size": 100,
|
|
211
|
+
"type": "file"
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
"path": "folder/file2.txt",
|
|
215
|
+
"name": "file2.txt",
|
|
216
|
+
"size": 200,
|
|
217
|
+
"type": "file"
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
"path": "folder/subfolder",
|
|
221
|
+
"name": "subfolder",
|
|
222
|
+
"size": undefined,
|
|
223
|
+
"type": "directory"
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**Note:** When serializing to JSON (e.g., `JSON.stringify(tree)`), `undefined` values are omitted. Properties with `undefined` will not appear in the JSON string.
|
|
230
|
+
|
|
167
231
|
## Adding custom fields
|
|
168
232
|
You can easily extend a `DirectoryTree` object with custom fields by adding them to the custom field.
|
|
169
233
|
For example add an `id` based on the path of a `DirectoryTree` object for each directory and file like so:
|
|
@@ -209,11 +273,6 @@ $ npm test
|
|
|
209
273
|
|
|
210
274
|
Make sure you have the dev dependencies installed (e.g. `npm install .`)
|
|
211
275
|
|
|
212
|
-
## Node version
|
|
213
|
-
|
|
214
|
-
This project requires at least Node v4.2.
|
|
215
|
-
Check out version `0.1.1` if you need support for older versions of Node.
|
|
216
|
-
|
|
217
276
|
## CLI usage
|
|
218
277
|
|
|
219
278
|
You can use script directly from command line for generating json data.
|
|
@@ -229,6 +288,6 @@ $ npx directory-tree --path /Users/user/target --attributes type,extension --pre
|
|
|
229
288
|
-p, --path string 🗂 The input folder to process. Required.
|
|
230
289
|
-e, --exclude string 🐒 Exclude some folders from processing by regexp string. Ex -e "test_data/some_dir$|js|.DS_Store"
|
|
231
290
|
-o, --output string 📝 Put result into file provided by this options. Overwrites if exists.
|
|
232
|
-
-d, --depth number ☞
|
|
233
|
-
--attributes string ℹ️ Grab file attributes. Example: --attributes size,type,extension.
|
|
291
|
+
-d, --depth number ☞ Limits directory traversal to specified depth. Combined with size, directories at depth limit have size: undefined.
|
|
292
|
+
--attributes string ℹ️ Grab file attributes. Example: --attributes size,type,extension. With depth, directories at limit have size: undefined.
|
|
234
293
|
--pretty 💎 Json pretty print
|
package/bin/index.js
CHANGED
|
@@ -30,12 +30,12 @@ const optionList = [
|
|
|
30
30
|
name: 'depth',
|
|
31
31
|
alias: 'd',
|
|
32
32
|
type: Number,
|
|
33
|
-
description: '☞
|
|
33
|
+
description: '☞ Limits directory traversal to specified depth. Combined with size, directories at depth limit have size: undefined.'
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
name: 'attributes',
|
|
37
37
|
type: String,
|
|
38
|
-
description: 'ℹ️ Grab file attributes. Example: --attributes size,type,extension.
|
|
38
|
+
description: 'ℹ️ Grab file attributes. Example: --attributes size,type,extension. With depth, directories at limit have size: undefined.'
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
41
|
name: 'pretty',
|
package/dark.svg
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<!-- Generator: Adobe Illustrator 22.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
|
3
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
|
4
|
+
viewBox="0 0 1050 200" style="enable-background:new 0 0 1050 200;" xml:space="preserve">
|
|
5
|
+
<style type="text/css">
|
|
6
|
+
.st0{fill:#121212;}
|
|
7
|
+
.st1{fill:#FFFFFF;}
|
|
8
|
+
.st2{filter:url(#Adobe_OpacityMaskFilter);}
|
|
9
|
+
.st3{opacity:0.678;mask:url(#e_1_);fill:#FFFFFF;enable-background:new ;}
|
|
10
|
+
.st4{filter:url(#Adobe_OpacityMaskFilter_1_);}
|
|
11
|
+
.st5{opacity:0.696;mask:url(#g_1_);fill:#FFFFFF;enable-background:new ;}
|
|
12
|
+
.st6{filter:url(#Adobe_OpacityMaskFilter_2_);}
|
|
13
|
+
.st7{mask:url(#i_1_);fill:#FFFFFF;}
|
|
14
|
+
</style>
|
|
15
|
+
<g id="button">
|
|
16
|
+
<path id="dark" class="st0" d="M1018,200H32c-17.7,0-32-14.3-32-32L0,32C0,14.3,14.3,0,32,0l986,0c17.7,0,32,14.3,32,32v136
|
|
17
|
+
C1050,185.7,1035.7,200,1018,200z"/>
|
|
18
|
+
</g>
|
|
19
|
+
<g id="donate">
|
|
20
|
+
<g>
|
|
21
|
+
<path class="st1" d="M73.3,110.6c0-13.1,6.8-21.4,17.2-21.4c5.9,0,10.6,3.1,12.8,7.7h0.2V79.3c0-3.3,2-5.1,4.8-5.1
|
|
22
|
+
s4.9,1.8,4.9,5.1v47.9c0,3.1-2,4.9-4.8,4.9s-4.9-1.7-4.9-4.9V124h-0.2c-2,4.8-6.4,8-12.9,8C80,132,73.3,123.8,73.3,110.6z
|
|
23
|
+
M103.5,110.6c0-8.1-4-13.4-10.2-13.4c-6.3,0-10.2,5.2-10.2,13.4c0,8.2,3.9,13.4,10.2,13.4C99.5,124,103.5,118.8,103.5,110.6z"/>
|
|
24
|
+
<path class="st1" d="M205.5,131.7c-3.3,0-5.2-2-5.2-5.7v-19.7c0-5.4-2.7-8.5-7.5-8.5c-5.4,0-8.7,3.9-8.7,10.4v17.8
|
|
25
|
+
c0,3.6-1.9,5.7-5.2,5.7s-5.2-2-5.2-5.7V95c0-3.4,2-5.5,5.1-5.5c3.1,0,4.9,1.8,5,5.2v2.5h0.5c1.6-4.9,6.3-8,12.3-8
|
|
26
|
+
c8.8,0,13.8,5.2,13.8,14.3v22.5C210.6,129.7,208.8,131.7,205.5,131.7z"/>
|
|
27
|
+
<path class="st1" d="M232,131.9c-8.1,0-13.6-5.1-13.6-12.6c0-7.7,5.7-12.4,15.1-12.4h9.8v-3.4c0-4.2-2.6-6.4-7.3-6.4
|
|
28
|
+
c-3.1,0-5.4,1.2-7.7,3.2c-1.2,0.9-2.3,1.4-3.9,1.4c-2.3,0-3.7-1.5-3.7-3.6c0-2.4,1.7-4.9,5.3-6.7c2.6-1.4,6.1-2.1,10.6-2.1
|
|
29
|
+
c10.9,0,17,5.2,17,14.3v22.7c0,3.5-1.8,5.5-5,5.5c-2.7,0-4.5-1.5-4.8-4.2v-1.4h-0.5C241.1,129.8,237,131.9,232,131.9z
|
|
30
|
+
M235.4,124.5c4.5,0,7.9-3,7.9-7v-4.3h-8c-4.2,0-6.7,2-6.7,5.4C228.6,122.1,231.4,124.5,235.4,124.5z"/>
|
|
31
|
+
<path class="st1" d="M266.3,98.3h-2.1c-2.8,0-4.4-1.5-4.4-4s1.6-4,4.4-4h2.3v-5.4c0-3.6,1.8-5.5,5-5.5c3.2,0,5,2,5,5.5v5.4h4.1
|
|
32
|
+
c2.8,0,4.4,1.5,4.4,4s-1.6,4-4.4,4h-4v20.9c0,3.8,1,5,4.1,5c1.1,0,1.8-0.2,2.7-0.2c1.8,0,3,1.2,3,3.1c0,1.5-0.7,2.8-2.1,3.7
|
|
33
|
+
c-1.4,0.9-3.6,1.4-6.4,1.4c-8.2,0-11.7-3.4-11.7-11.9V98.3z"/>
|
|
34
|
+
<path class="st1" d="M291.3,108c0-11.3,7.5-19,18.6-19c10.5,0,18,7.5,18,17.7c0,4.6-1.3,6.2-5.2,6.2h-21v1.8
|
|
35
|
+
c0,5.8,3.7,9.5,9.8,9.5c3.2,0,5.5-0.8,7.3-2.3c2-1.5,2.7-2.1,4.3-2.1c2.1,0,3.6,1.5,3.6,3.8c0,1.8-1.1,3.6-3.1,5
|
|
36
|
+
c-2.7,2.3-7.5,3.7-12.8,3.7c-12.1,0-19.6-7.1-19.6-18.9V108z M318.1,106.4L318.1,106.4c0-5.7-3.1-9.4-8-9.4
|
|
37
|
+
c-5.1,0-8.3,3.8-8.3,9.3v0.1H318.1z"/>
|
|
38
|
+
<path class="st1" d="M359.5,97.1c-0.3-1.2-0.4-1.9-0.4-2.5c0-2.9,2.1-5,5.2-5c2.7,0,4.5,1.8,5,5.1l5.2,25.9h0.5l6.2-24.5
|
|
39
|
+
c1.2-4.8,2.9-6.6,6.3-6.6c3.4,0,5.2,1.8,6.4,6.6l6.3,24.5h0.5l5.4-25.9c0.6-3.2,2.4-5.1,5-5.1c3.1,0,5,2,5,4.7
|
|
40
|
+
c0,0.6-0.2,1.5-0.5,2.7l-7.2,26.5c-1.7,6.2-3.7,8.2-7.3,8.2c-3.9,0-5.9-2-7.5-8.2l-6-21.8h-0.4l-5.8,21.8
|
|
41
|
+
c-1.6,6.3-3.4,8.2-7.3,8.2c-3.8,0-5.9-2.1-7.5-8.2L359.5,97.1z"/>
|
|
42
|
+
<path class="st1" d="M426.9,74c3.4,0,5.9,2.3,5.9,5.4s-2.5,5.4-5.9,5.4c-3.3,0-5.8-2.3-5.8-5.4S423.6,74,426.9,74z M426.9,131.7
|
|
43
|
+
c-3.2,0-5.1-2-5.1-5.7V95.2c0-3.8,2-5.7,5.2-5.7c3.2,0,5.1,2,5.1,5.7v30.9C432.1,129.8,430.1,131.7,426.9,131.7z"/>
|
|
44
|
+
<path class="st1" d="M444,98.3h-2.1c-2.8,0-4.4-1.5-4.4-4s1.6-4,4.4-4h2.3v-5.4c0-3.6,1.8-5.5,5-5.5c3.2,0,5,2,5,5.5v5.4h4.1
|
|
45
|
+
c2.8,0,4.4,1.5,4.4,4s-1.6,4-4.4,4h-4v20.9c0,3.8,1,5,4.1,5c1.1,0,1.8-0.2,2.7-0.2c1.8,0,3,1.2,3,3.1c0,1.5-0.7,2.8-2.1,3.7
|
|
46
|
+
c-1.4,0.9-3.6,1.4-6.4,1.4c-8.2,0-11.7-3.4-11.7-11.9V98.3z"/>
|
|
47
|
+
<path class="st1" d="M501.1,131.7c-3.3,0-5.2-2-5.2-5.7v-19.6c0-5.4-2.8-8.5-7.6-8.5c-5.3,0-8.8,4-8.8,10.4v17.8
|
|
48
|
+
c0,3.6-1.9,5.7-5.2,5.7s-5.1-2-5.1-5.7V80.6c0-3.6,1.8-5.7,5.2-5.7c3.3,0,5.1,2.1,5.1,5.7v16.6h0.5c1.4-4.7,6.5-8,12.4-8
|
|
49
|
+
c8.6,0,13.8,5.4,13.8,14.4v22.4C506.3,129.7,504.4,131.7,501.1,131.7z"/>
|
|
50
|
+
</g>
|
|
51
|
+
<path id="heart_2_" class="st1" d="M154.3,89.2c-4.3,0-8.5,2.1-10.8,6.7c-2.3-4.6-6.5-6.7-10.8-6.7c-6.7,0-12.7,4.7-12.7,13.1
|
|
52
|
+
c0,14.2,19.4,21.4,23.5,29.9c4.1-8.5,23.5-15.7,23.5-29.9C167,93.3,160.3,89.2,154.3,89.2z M150.2,99.2c3,0,5.7,2,5.7,6
|
|
53
|
+
c0,6.3-8.3,10.6-12.8,15.2c-4.4-4.6-12.8-8.9-12.8-15.2c0-3.9,2.6-6,5.7-6c4.1,0,6.2,4.6,7,6.8C144,103.8,146.2,99.2,150.2,99.2z"
|
|
54
|
+
/>
|
|
55
|
+
</g>
|
|
56
|
+
<g id="PayPal">
|
|
57
|
+
<path class="st1" d="M888.7,89.7c-1.2,8-7.3,8-13.2,8h-3.4l2.4-14.9c0.1-0.9,0.9-1.6,1.8-1.6h1.5c4,0,7.8,0,9.7,2.3
|
|
58
|
+
C888.8,84.9,889.1,86.9,888.7,89.7 M886.1,68.9h-22.2c-1.5,0-2.8,1.1-3,2.6l-9,56.9c-0.2,1,0.5,2,1.5,2.1c0.1,0,0.2,0,0.3,0h11.4
|
|
59
|
+
c1.1,0,2-0.8,2.1-1.8l2.5-16.1c0.2-1.5,1.5-2.6,3.1-2.6h7c14.6,0,23.1-7.1,25.3-21.1c1-6.1,0-11-2.8-14.3
|
|
60
|
+
C899.2,70.9,893.6,68.9,886.1,68.9 M730.2,89.7c-1.2,8-7.3,8-13.2,8h-3.4l2.4-14.9c0.1-0.9,0.9-1.6,1.8-1.6h1.5c4,0,7.8,0,9.7,2.3
|
|
61
|
+
C730.3,84.9,730.7,86.9,730.2,89.7 M727.7,68.9h-22.2c-1.5,0-2.8,1.1-3.1,2.6l-9,56.9c-0.2,1,0.5,2,1.5,2.1c0.1,0,0.2,0,0.3,0h10.6
|
|
62
|
+
c1.5,0,2.8-1.1,3-2.6l2.4-15.4c0.2-1.5,1.5-2.6,3-2.6h7c14.6,0,23.1-7.1,25.3-21.1c1-6.1,0-11-2.8-14.3
|
|
63
|
+
C740.7,70.9,735.1,68.9,727.7,68.9 M779.3,110.2c-1,6.1-5.9,10.2-12,10.2c-3.1,0-5.6-1-7.1-2.9c-1.6-1.9-2.2-4.5-1.7-7.5
|
|
64
|
+
c1-6,5.9-10.2,11.9-10.2c3,0,5.5,1,7.1,2.9C779.1,104.5,779.7,107.2,779.3,110.2 M794.1,89.5h-10.6c-0.9,0-1.7,0.7-1.8,1.6l-0.5,3
|
|
65
|
+
l-0.7-1.1c-2.3-3.3-7.4-4.5-12.6-4.5c-11.8,0-21.8,8.9-23.7,21.4c-1,6.2,0.4,12.2,4,16.3c3.2,3.8,7.9,5.4,13.4,5.4
|
|
66
|
+
c9.5,0,14.7-6.1,14.7-6.1l-0.5,3c-0.2,1,0.5,2,1.5,2.1c0.1,0,0.2,0,0.3,0h9.6c1.5,0,2.8-1.1,3-2.6l5.8-36.4c0.2-1-0.5-2-1.5-2.1
|
|
67
|
+
C794.3,89.5,794.2,89.5,794.1,89.5 M937.7,110.2c-1,6.1-5.9,10.2-12,10.2c-3.1,0-5.6-1-7.1-2.9c-1.6-1.9-2.2-4.5-1.7-7.5
|
|
68
|
+
c1-6,5.9-10.2,11.9-10.2c3,0,5.5,1,7.1,2.9C937.5,104.5,938.2,107.2,937.7,110.2 M952.5,89.5h-10.6c-0.9,0-1.7,0.7-1.8,1.6l-0.5,3
|
|
69
|
+
l-0.7-1.1c-2.3-3.3-7.4-4.5-12.6-4.5c-11.8,0-21.8,8.9-23.7,21.4c-1,6.2,0.4,12.2,4,16.3c3.2,3.8,7.9,5.4,13.4,5.4
|
|
70
|
+
c9.5,0,14.7-6.1,14.7-6.1l-0.5,3c-0.2,1,0.5,2,1.5,2.1c0.1,0,0.2,0,0.3,0h9.6c1.5,0,2.8-1.1,3-2.6l5.8-36.4c0.2-1-0.5-2-1.5-2.1
|
|
71
|
+
C952.7,89.5,952.6,89.5,952.5,89.5 M850.7,89.5H840c-1,0-2,0.5-2.6,1.4l-14.7,21.7l-6.3-20.9c-0.4-1.3-1.6-2.2-3-2.2H803
|
|
72
|
+
c-1,0-1.9,0.8-1.9,1.9c0,0.2,0,0.4,0.1,0.6l11.8,34.5L802,142.1c-0.9,1.2,0,2.9,1.5,2.9h10.7c1,0,2-0.5,2.5-1.3l35.6-51.3
|
|
73
|
+
C853.1,91.1,852.2,89.5,850.7,89.5 M965.1,70.5l-9.1,58c-0.2,1,0.5,2,1.5,2.1c0.1,0,0.2,0,0.3,0h9.2c1.5,0,2.8-1.1,3-2.6l9-56.9
|
|
74
|
+
c0.2-1-0.5-2-1.5-2.1c-0.1,0-0.2,0-0.3,0h-10.3C966,68.9,965.2,69.6,965.1,70.5"/>
|
|
75
|
+
<g>
|
|
76
|
+
<defs>
|
|
77
|
+
<filter id="Adobe_OpacityMaskFilter" filterUnits="userSpaceOnUse" x="575" y="47" width="83.1" height="98">
|
|
78
|
+
<feColorMatrix type="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0"/>
|
|
79
|
+
</filter>
|
|
80
|
+
</defs>
|
|
81
|
+
<mask maskUnits="userSpaceOnUse" x="575" y="47" width="83.1" height="98" id="e_1_">
|
|
82
|
+
<g class="st2">
|
|
83
|
+
<path id="d_1_" class="st1" d="M575,47h83.1v98H575V47z"/>
|
|
84
|
+
</g>
|
|
85
|
+
</mask>
|
|
86
|
+
<path class="st3" d="M649.9,71.9c1.2-7.6,0-12.8-4.1-17.5c-4.5-5.2-12.7-7.4-23.2-7.4H592c-2.1,0-4,1.6-4.3,3.7L575,131.1
|
|
87
|
+
c-0.2,1.4,0.7,2.8,2.2,3c0.1,0,0.3,0,0.4,0h18.8l-1.3,8.2c-0.2,1.2,0.7,2.4,1.9,2.6c0.1,0,0.2,0,0.4,0h15.9c1.9,0,3.5-1.4,3.8-3.2
|
|
88
|
+
l0.2-0.8l3-18.9l0.2-1c0.3-1.9,1.9-3.2,3.8-3.2h2.4c15.4,0,27.4-6.2,30.9-24.3c1.5-7.5,0.7-13.8-3.2-18.3
|
|
89
|
+
C653,73.9,651.6,72.8,649.9,71.9"/>
|
|
90
|
+
<defs>
|
|
91
|
+
<filter id="Adobe_OpacityMaskFilter_1_" filterUnits="userSpaceOnUse" x="575" y="47" width="75.3" height="87.1">
|
|
92
|
+
<feColorMatrix type="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0"/>
|
|
93
|
+
</filter>
|
|
94
|
+
</defs>
|
|
95
|
+
<mask maskUnits="userSpaceOnUse" x="575" y="47" width="75.3" height="87.1" id="g_1_">
|
|
96
|
+
<g class="st4">
|
|
97
|
+
<path id="f_1_" class="st1" d="M575,47h75.3v87.1H575V47z"/>
|
|
98
|
+
</g>
|
|
99
|
+
</mask>
|
|
100
|
+
<path class="st5" d="M649.9,71.9c1.2-7.6,0-12.8-4.1-17.5c-4.5-5.2-12.7-7.4-23.2-7.4H592c-2.1,0-4,1.6-4.3,3.7L575,131.1
|
|
101
|
+
c-0.2,1.4,0.7,2.8,2.2,3c0.1,0,0.3,0,0.4,0h18.8l4.7-30l-0.1,0.9c0.3-2.1,2.1-3.7,4.3-3.7h8.9c17.6,0,31.3-7.1,35.3-27.8
|
|
102
|
+
C649.7,73.1,649.8,72.5,649.9,71.9"/>
|
|
103
|
+
<defs>
|
|
104
|
+
<filter id="Adobe_OpacityMaskFilter_2_" filterUnits="userSpaceOnUse" x="575" y="47" width="75.3" height="87.1">
|
|
105
|
+
<feColorMatrix type="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0"/>
|
|
106
|
+
</filter>
|
|
107
|
+
</defs>
|
|
108
|
+
<mask maskUnits="userSpaceOnUse" x="575" y="47" width="75.3" height="87.1" id="i_1_">
|
|
109
|
+
<g class="st6">
|
|
110
|
+
<path id="h_1_" class="st1" d="M575,47h75.3v87.1H575V47z"/>
|
|
111
|
+
</g>
|
|
112
|
+
</mask>
|
|
113
|
+
<path class="st7" d="M606.2,72c0.3-1.9,1.9-3.2,3.8-3.2h23.9c2.8,0,5.5,0.2,7.9,0.6c0.7,0.1,1.4,0.2,2,0.4
|
|
114
|
+
c0.9,0.2,1.9,0.5,2.8,0.8c1.1,0.4,2.2,0.8,3.3,1.4c1.2-7.6,0-12.8-4.1-17.5c-4.5-5.2-12.7-7.4-23.2-7.4H592c-2.1,0-4,1.6-4.3,3.7
|
|
115
|
+
L575,131.1c-0.2,1.4,0.7,2.8,2.2,3c0.1,0,0.3,0,0.4,0h18.8l4.7-30L606.2,72L606.2,72z"/>
|
|
116
|
+
</g>
|
|
117
|
+
</g>
|
|
118
|
+
</svg>
|
package/index.d.ts
CHANGED
|
@@ -17,12 +17,12 @@ declare namespace directoryTree {
|
|
|
17
17
|
export interface DirectoryTree<C extends Record<string, any> = Record<string, any>> {
|
|
18
18
|
path: string;
|
|
19
19
|
name: string;
|
|
20
|
-
size
|
|
20
|
+
size?: number;
|
|
21
21
|
type: "directory" | "file";
|
|
22
22
|
children?: DirectoryTree<C>[];
|
|
23
23
|
extension?: string;
|
|
24
24
|
isSymbolicLink?: boolean;
|
|
25
|
-
custom
|
|
25
|
+
custom?: C;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export interface DirectoryTreeOptions {
|
package/lib/directory-tree.js
CHANGED
|
@@ -22,7 +22,7 @@ function safeReadDirSync (path) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* Normalizes
|
|
25
|
+
* Normalizes Windows style paths by replacing double backslashes with single forward slashes (UNIX style).
|
|
26
26
|
* @param {string} path
|
|
27
27
|
* @return {string}
|
|
28
28
|
*/
|
|
@@ -51,10 +51,6 @@ function isRegExp(regExp) {
|
|
|
51
51
|
function directoryTree (path, options, onEachFile, onEachDirectory, currentDepth = 0) {
|
|
52
52
|
options = options || {};
|
|
53
53
|
|
|
54
|
-
if (options.depth !== undefined && options.attributes && options.attributes.indexOf('size') !== -1) {
|
|
55
|
-
throw new Error('usage of size attribute with depth option is prohibited');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
54
|
const name = PATH.basename(path);
|
|
59
55
|
path = options.normalizePath ? normalizePath(path) : path;
|
|
60
56
|
const item = { path, name };
|
|
@@ -134,7 +130,15 @@ function directoryTree (path, options, onEachFile, onEachDirectory, currentDepth
|
|
|
134
130
|
options.attributes.forEach((attribute) => {
|
|
135
131
|
switch (attribute) {
|
|
136
132
|
case 'size':
|
|
137
|
-
|
|
133
|
+
// If children don't exist (depth limit reached), set to undefined
|
|
134
|
+
if (!item.children) {
|
|
135
|
+
item.size = undefined;
|
|
136
|
+
} else {
|
|
137
|
+
// If any child has undefined size, parent size is also undefined
|
|
138
|
+
// Otherwise, calculate recursive size
|
|
139
|
+
const hasUndefinedSize = item.children.some(child => child.size === undefined);
|
|
140
|
+
item.size = hasUndefinedSize ? undefined : item.children.reduce((prev, cur) => prev + cur.size, 0);
|
|
141
|
+
}
|
|
138
142
|
break;
|
|
139
143
|
case 'type':
|
|
140
144
|
item.type = constants.DIRECTORY;
|
|
@@ -145,7 +149,7 @@ function directoryTree (path, options, onEachFile, onEachDirectory, currentDepth
|
|
|
145
149
|
item[attribute] = stats[attribute];
|
|
146
150
|
break;
|
|
147
151
|
}
|
|
148
|
-
|
|
152
|
+
|
|
149
153
|
});
|
|
150
154
|
}
|
|
151
155
|
|