path-treeify 1.1.0-beta.94a5d17 → 1.1.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/README.md +24 -48
- package/dist/index.cjs +159 -1
- package/dist/index.mjs +157 -1
- package/dist/types/index.d.ts +1 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
</div>
|
|
9
9
|
|
|
10
10
|
<div align="left">
|
|
11
|
-
<a href="https://
|
|
12
|
-
<img alt="
|
|
11
|
+
<a href="https://github.com/isaaxite/path-treeify">
|
|
12
|
+
<img alt="GitHub package.json dynamic" src="https://img.shields.io/github/package-json/version/isaaxite/path-treeify?logo=github">
|
|
13
13
|
</a>
|
|
14
14
|
<a href="https://nodejs.org">
|
|
15
15
|
<img alt="node" src="https://img.shields.io/node/v/path-treeify">
|
|
@@ -39,8 +39,7 @@
|
|
|
39
39
|
- 🔗 Each node carries a `parent` circular reference for upward traversal
|
|
40
40
|
- 📍 Each node exposes a `getPath()` method to retrieve its own paths directly
|
|
41
41
|
- 🔍 Optional `filter` callback to include/exclude directories during scanning
|
|
42
|
-
- ⚡ `build()` scans the entire `base` directory with zero configuration
|
|
43
|
-
- 🎛️ `buildBy()` accepts either a directory name array or a filter function
|
|
42
|
+
- ⚡ `build()` method scans the entire `base` directory with zero configuration
|
|
44
43
|
- 📦 Ships as both ESM (`index.mjs`) and CJS (`index.cjs`) with full TypeScript types
|
|
45
44
|
- 🚫 Zero runtime dependencies
|
|
46
45
|
|
|
@@ -71,11 +70,8 @@ import { PathTreeify } from 'path-treeify';
|
|
|
71
70
|
|
|
72
71
|
const treeify = new PathTreeify({ base: '/your/project/root' });
|
|
73
72
|
|
|
74
|
-
// Scan specific directories
|
|
75
|
-
const tree = treeify.
|
|
76
|
-
|
|
77
|
-
// Scan with a filter function over all top-level directories
|
|
78
|
-
const filtered = treeify.buildBy(name => !name.startsWith('.') && name !== 'node_modules');
|
|
73
|
+
// Scan specific directories
|
|
74
|
+
const tree = treeify.buildByDirNames(['src', 'tests']);
|
|
79
75
|
|
|
80
76
|
// Or scan everything under base at once
|
|
81
77
|
const fullTree = treeify.build();
|
|
@@ -92,7 +88,7 @@ Creates a new instance.
|
|
|
92
88
|
| Option | Type | Required | Description |
|
|
93
89
|
|----------|-------------------------------|----------|----------------------------------------------------|
|
|
94
90
|
| `base` | `string` | ✅ | Absolute path to the root directory to scan from |
|
|
95
|
-
| `filter` | `FilterFunction` (see below) | ❌ | Called for every directory found during
|
|
91
|
+
| `filter` | `FilterFunction` (see below) | ❌ | Called for every directory found during traversal |
|
|
96
92
|
|
|
97
93
|
`base` must exist and be a directory, otherwise the constructor throws.
|
|
98
94
|
|
|
@@ -100,8 +96,6 @@ Creates a new instance.
|
|
|
100
96
|
|
|
101
97
|
### `FilterFunction`
|
|
102
98
|
|
|
103
|
-
Used as the `filter` option in the constructor. Applied recursively during deep traversal of the tree.
|
|
104
|
-
|
|
105
99
|
```ts
|
|
106
100
|
type FilterFunction = (params: {
|
|
107
101
|
name: string; // directory name (leaf segment)
|
|
@@ -111,7 +105,7 @@ type FilterFunction = (params: {
|
|
|
111
105
|
|
|
112
106
|
Return `true` to **include** the directory and recurse into it; `false` to **skip** it.
|
|
113
107
|
|
|
114
|
-
**Example — skip hidden directories and `node_modules
|
|
108
|
+
**Example — skip hidden directories and `node_modules`:**
|
|
115
109
|
|
|
116
110
|
```ts
|
|
117
111
|
const treeify = new PathTreeify({
|
|
@@ -124,7 +118,7 @@ const treeify = new PathTreeify({
|
|
|
124
118
|
|
|
125
119
|
### `build(): PathTreeNode`
|
|
126
120
|
|
|
127
|
-
Scans **all** subdirectories directly under `base` and returns a synthetic root `PathTreeNode`. This is the zero-configuration
|
|
121
|
+
Scans **all** subdirectories directly under `base` and returns a synthetic root `PathTreeNode`. This is the zero-configuration alternative to `buildByDirNames`.
|
|
128
122
|
|
|
129
123
|
```ts
|
|
130
124
|
const tree = treeify.build();
|
|
@@ -132,26 +126,17 @@ const tree = treeify.build();
|
|
|
132
126
|
|
|
133
127
|
---
|
|
134
128
|
|
|
135
|
-
### `
|
|
129
|
+
### `buildByDirNames(dirNames: string[]): PathTreeNode`
|
|
136
130
|
|
|
137
|
-
|
|
131
|
+
Scans the given relative directory names (resolved against `base`) and returns a synthetic root `PathTreeNode` whose `children` are the top-level nodes you requested.
|
|
138
132
|
|
|
139
133
|
```ts
|
|
140
|
-
const
|
|
134
|
+
const root = treeify.buildByDirNames(['src', 'docs']);
|
|
141
135
|
```
|
|
142
136
|
|
|
137
|
+
- Each element must be a valid, accessible directory relative to `base`.
|
|
143
138
|
- Leading and trailing slashes are stripped automatically.
|
|
144
|
-
- Throws if any
|
|
145
|
-
|
|
146
|
-
### `buildBy(filter: (dirName: string) => boolean): PathTreeNode`
|
|
147
|
-
|
|
148
|
-
Collects all top-level subdirectories under `base`, applies the given filter function, then builds a tree from the matching names.
|
|
149
|
-
|
|
150
|
-
```ts
|
|
151
|
-
const tree = treeify.buildBy(name => name !== 'node_modules' && !name.startsWith('.'));
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
> Note: this `filter` operates only on the **top-level** directory names under `base`. For filtering at every depth, pass a `filter` to the constructor instead.
|
|
139
|
+
- Throws if any path does not exist or is not a directory.
|
|
155
140
|
|
|
156
141
|
---
|
|
157
142
|
|
|
@@ -160,14 +145,17 @@ const tree = treeify.buildBy(name => name !== 'node_modules' && !name.startsWith
|
|
|
160
145
|
Walks a node's `parent` chain to reconstruct its full path. Equivalent to calling `node.getPath()` directly.
|
|
161
146
|
|
|
162
147
|
```ts
|
|
163
|
-
const
|
|
148
|
+
const srcNode = root.children[0];
|
|
149
|
+
const { relative, absolute } = treeify.getPathBy(srcNode);
|
|
150
|
+
// relative → 'src'
|
|
151
|
+
// absolute → '/your/project/src'
|
|
164
152
|
```
|
|
165
153
|
|
|
166
154
|
---
|
|
167
155
|
|
|
168
156
|
### `PathTreeNode`
|
|
169
157
|
|
|
170
|
-
`PathTreeNode` is a **class** with its own `getPath()` method, so you can retrieve a node's path without passing it back to the `PathTreeify` instance.
|
|
158
|
+
`PathTreeNode` is now a **class** with its own `getPath()` method, so you can retrieve a node's path without passing it back to the `PathTreeify` instance.
|
|
171
159
|
|
|
172
160
|
```ts
|
|
173
161
|
class PathTreeNode {
|
|
@@ -192,30 +180,18 @@ class PathTreeNode {
|
|
|
192
180
|
```ts
|
|
193
181
|
import { PathTreeify } from 'path-treeify';
|
|
194
182
|
|
|
195
|
-
const treeify = new PathTreeify({
|
|
183
|
+
const treeify = new PathTreeify({
|
|
184
|
+
base: '/your/project',
|
|
185
|
+
filter: ({ name }) => name !== 'node_modules' && !name.startsWith('.'),
|
|
186
|
+
});
|
|
187
|
+
|
|
196
188
|
const tree = treeify.build();
|
|
197
189
|
```
|
|
198
190
|
|
|
199
191
|
### Scan specific directories
|
|
200
192
|
|
|
201
193
|
```ts
|
|
202
|
-
const tree = treeify.
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
### Filter top-level directories
|
|
206
|
-
|
|
207
|
-
```ts
|
|
208
|
-
const tree = treeify.buildBy(name => name !== 'node_modules' && !name.startsWith('.'));
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
### Filter at every depth via constructor
|
|
212
|
-
|
|
213
|
-
```ts
|
|
214
|
-
const treeify = new PathTreeify({
|
|
215
|
-
base: '/your/project',
|
|
216
|
-
filter: ({ name }) => name !== 'node_modules' && !name.startsWith('.'),
|
|
217
|
-
});
|
|
218
|
-
const tree = treeify.build();
|
|
194
|
+
const tree = treeify.buildByDirNames(['src', 'tests', 'docs']);
|
|
219
195
|
```
|
|
220
196
|
|
|
221
197
|
### Retrieve paths via `node.getPath()`
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1,159 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
|
|
6
|
+
class PathValidator {
|
|
7
|
+
static isValid(path) {
|
|
8
|
+
try {
|
|
9
|
+
fs.accessSync(path, fs.constants.F_OK);
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
static isDirectory(path) {
|
|
17
|
+
try {
|
|
18
|
+
return fs.statSync(path).isDirectory();
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
class PathTreeNode {
|
|
26
|
+
constructor(base) {
|
|
27
|
+
this.parent = null;
|
|
28
|
+
this.value = '';
|
|
29
|
+
this.children = [];
|
|
30
|
+
this.base = base;
|
|
31
|
+
}
|
|
32
|
+
getPath() {
|
|
33
|
+
let relative = '';
|
|
34
|
+
let current = this;
|
|
35
|
+
while (current.parent) {
|
|
36
|
+
relative = relative
|
|
37
|
+
? `${current.value}${path.sep}${relative}`
|
|
38
|
+
: current.value;
|
|
39
|
+
current = current.parent;
|
|
40
|
+
}
|
|
41
|
+
return { relative, absolute: path.resolve(this.base, relative) };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
class PathTreeify {
|
|
45
|
+
constructor({ filter, base }) {
|
|
46
|
+
if (typeof filter !== 'undefined') {
|
|
47
|
+
this.validateFilter(filter);
|
|
48
|
+
this.filter = filter;
|
|
49
|
+
}
|
|
50
|
+
if (!base || !PathValidator.isValid(base)) {
|
|
51
|
+
throw new Error(`${base} is not a valid path!`);
|
|
52
|
+
}
|
|
53
|
+
if (!PathValidator.isDirectory(base)) {
|
|
54
|
+
throw new Error(`${base} is not a dirPath!`);
|
|
55
|
+
}
|
|
56
|
+
this.base = base;
|
|
57
|
+
}
|
|
58
|
+
validateFilter(filter) {
|
|
59
|
+
if (typeof filter !== 'function') {
|
|
60
|
+
throw new TypeError('filter must be a function');
|
|
61
|
+
}
|
|
62
|
+
if (filter.length !== 1) {
|
|
63
|
+
throw new TypeError('filter must accept exactly one parameter');
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const testResult = filter({ name: 'test', postPath: '/test' });
|
|
67
|
+
if (typeof testResult !== 'boolean') {
|
|
68
|
+
throw new TypeError('filter must return a boolean');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
throw new TypeError('filter function threw an error during test: ' + error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
initNode(parent = null) {
|
|
76
|
+
const node = new PathTreeNode(this.base);
|
|
77
|
+
if (parent) {
|
|
78
|
+
node.parent = parent;
|
|
79
|
+
}
|
|
80
|
+
return node;
|
|
81
|
+
}
|
|
82
|
+
buildChildren(dirPath, parent) {
|
|
83
|
+
const names = fs.readdirSync(dirPath);
|
|
84
|
+
const children = [];
|
|
85
|
+
for (const name of names) {
|
|
86
|
+
const subPath = path.join(dirPath, name);
|
|
87
|
+
if (!fs.statSync(subPath).isDirectory()) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (this.filter && !this.filter({ dirPath, name })) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const node = this.initNode();
|
|
94
|
+
node.value = name;
|
|
95
|
+
node.parent = parent;
|
|
96
|
+
node.children = this.buildChildren(subPath, node);
|
|
97
|
+
children.push(node);
|
|
98
|
+
}
|
|
99
|
+
return children;
|
|
100
|
+
}
|
|
101
|
+
checkRelativePaths(relativeDirNames) {
|
|
102
|
+
if (!Array.isArray(relativeDirNames)) {
|
|
103
|
+
throw new Error(`Expected array, got ${typeof relativeDirNames}`);
|
|
104
|
+
}
|
|
105
|
+
for (let i = 0; i < relativeDirNames.length; i++) {
|
|
106
|
+
const it = relativeDirNames[i];
|
|
107
|
+
if (typeof it !== 'string') {
|
|
108
|
+
throw new Error(`Item at index ${i} is not a string, got ${typeof it}`);
|
|
109
|
+
}
|
|
110
|
+
const absPath = path.resolve(this.base, it);
|
|
111
|
+
if (!PathValidator.isValid(absPath)) {
|
|
112
|
+
throw new Error(`Path does not exist or is not accessible: ${absPath} (from relative path: ${it})`);
|
|
113
|
+
}
|
|
114
|
+
if (!PathValidator.isDirectory(absPath)) {
|
|
115
|
+
throw new Error(`Path is not a directory: ${absPath} (from relative path: ${it})`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
formatDirnames(dirNames) {
|
|
120
|
+
return dirNames.map(dir => {
|
|
121
|
+
// Remove leading and trailing slashes
|
|
122
|
+
return dir.replace(/^\/+|\/+$/g, '');
|
|
123
|
+
}).filter(dir => dir !== ''); // Optional: filter empty strings
|
|
124
|
+
}
|
|
125
|
+
getPathBy(node) {
|
|
126
|
+
let relative = '';
|
|
127
|
+
let current = node;
|
|
128
|
+
while (current.parent) {
|
|
129
|
+
relative = relative
|
|
130
|
+
? `${current.value}${path.sep}${relative}`
|
|
131
|
+
: current.value;
|
|
132
|
+
current = current.parent;
|
|
133
|
+
}
|
|
134
|
+
return { relative, absolute: path.resolve(this.base, relative) };
|
|
135
|
+
}
|
|
136
|
+
buildByDirNames(dirNames) {
|
|
137
|
+
const root = this.initNode();
|
|
138
|
+
this.checkRelativePaths(dirNames);
|
|
139
|
+
const dirNameArr = this.formatDirnames(dirNames);
|
|
140
|
+
for (const dirName of dirNameArr) {
|
|
141
|
+
const node = this.initNode();
|
|
142
|
+
node.value = dirName;
|
|
143
|
+
node.parent = root;
|
|
144
|
+
node.children = this.buildChildren(path.resolve(this.base, dirName), node);
|
|
145
|
+
root.children.push(node);
|
|
146
|
+
}
|
|
147
|
+
return root;
|
|
148
|
+
}
|
|
149
|
+
build() {
|
|
150
|
+
const dirNameArr = fs.readdirSync(this.base).filter(name => {
|
|
151
|
+
const abs = path.resolve(this.base, name);
|
|
152
|
+
return PathValidator.isDirectory(abs);
|
|
153
|
+
});
|
|
154
|
+
return this.buildByDirNames(dirNameArr);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
exports.PathTreeify = PathTreeify;
|
|
159
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,157 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { readdirSync, statSync, accessSync, constants } from 'fs';
|
|
2
|
+
import { join, resolve, sep } from 'path';
|
|
3
|
+
|
|
4
|
+
class PathValidator {
|
|
5
|
+
static isValid(path) {
|
|
6
|
+
try {
|
|
7
|
+
accessSync(path, constants.F_OK);
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
static isDirectory(path) {
|
|
15
|
+
try {
|
|
16
|
+
return statSync(path).isDirectory();
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class PathTreeNode {
|
|
24
|
+
constructor(base) {
|
|
25
|
+
this.parent = null;
|
|
26
|
+
this.value = '';
|
|
27
|
+
this.children = [];
|
|
28
|
+
this.base = base;
|
|
29
|
+
}
|
|
30
|
+
getPath() {
|
|
31
|
+
let relative = '';
|
|
32
|
+
let current = this;
|
|
33
|
+
while (current.parent) {
|
|
34
|
+
relative = relative
|
|
35
|
+
? `${current.value}${sep}${relative}`
|
|
36
|
+
: current.value;
|
|
37
|
+
current = current.parent;
|
|
38
|
+
}
|
|
39
|
+
return { relative, absolute: resolve(this.base, relative) };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
class PathTreeify {
|
|
43
|
+
constructor({ filter, base }) {
|
|
44
|
+
if (typeof filter !== 'undefined') {
|
|
45
|
+
this.validateFilter(filter);
|
|
46
|
+
this.filter = filter;
|
|
47
|
+
}
|
|
48
|
+
if (!base || !PathValidator.isValid(base)) {
|
|
49
|
+
throw new Error(`${base} is not a valid path!`);
|
|
50
|
+
}
|
|
51
|
+
if (!PathValidator.isDirectory(base)) {
|
|
52
|
+
throw new Error(`${base} is not a dirPath!`);
|
|
53
|
+
}
|
|
54
|
+
this.base = base;
|
|
55
|
+
}
|
|
56
|
+
validateFilter(filter) {
|
|
57
|
+
if (typeof filter !== 'function') {
|
|
58
|
+
throw new TypeError('filter must be a function');
|
|
59
|
+
}
|
|
60
|
+
if (filter.length !== 1) {
|
|
61
|
+
throw new TypeError('filter must accept exactly one parameter');
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const testResult = filter({ name: 'test', postPath: '/test' });
|
|
65
|
+
if (typeof testResult !== 'boolean') {
|
|
66
|
+
throw new TypeError('filter must return a boolean');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
throw new TypeError('filter function threw an error during test: ' + error);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
initNode(parent = null) {
|
|
74
|
+
const node = new PathTreeNode(this.base);
|
|
75
|
+
if (parent) {
|
|
76
|
+
node.parent = parent;
|
|
77
|
+
}
|
|
78
|
+
return node;
|
|
79
|
+
}
|
|
80
|
+
buildChildren(dirPath, parent) {
|
|
81
|
+
const names = readdirSync(dirPath);
|
|
82
|
+
const children = [];
|
|
83
|
+
for (const name of names) {
|
|
84
|
+
const subPath = join(dirPath, name);
|
|
85
|
+
if (!statSync(subPath).isDirectory()) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (this.filter && !this.filter({ dirPath, name })) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const node = this.initNode();
|
|
92
|
+
node.value = name;
|
|
93
|
+
node.parent = parent;
|
|
94
|
+
node.children = this.buildChildren(subPath, node);
|
|
95
|
+
children.push(node);
|
|
96
|
+
}
|
|
97
|
+
return children;
|
|
98
|
+
}
|
|
99
|
+
checkRelativePaths(relativeDirNames) {
|
|
100
|
+
if (!Array.isArray(relativeDirNames)) {
|
|
101
|
+
throw new Error(`Expected array, got ${typeof relativeDirNames}`);
|
|
102
|
+
}
|
|
103
|
+
for (let i = 0; i < relativeDirNames.length; i++) {
|
|
104
|
+
const it = relativeDirNames[i];
|
|
105
|
+
if (typeof it !== 'string') {
|
|
106
|
+
throw new Error(`Item at index ${i} is not a string, got ${typeof it}`);
|
|
107
|
+
}
|
|
108
|
+
const absPath = resolve(this.base, it);
|
|
109
|
+
if (!PathValidator.isValid(absPath)) {
|
|
110
|
+
throw new Error(`Path does not exist or is not accessible: ${absPath} (from relative path: ${it})`);
|
|
111
|
+
}
|
|
112
|
+
if (!PathValidator.isDirectory(absPath)) {
|
|
113
|
+
throw new Error(`Path is not a directory: ${absPath} (from relative path: ${it})`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
formatDirnames(dirNames) {
|
|
118
|
+
return dirNames.map(dir => {
|
|
119
|
+
// Remove leading and trailing slashes
|
|
120
|
+
return dir.replace(/^\/+|\/+$/g, '');
|
|
121
|
+
}).filter(dir => dir !== ''); // Optional: filter empty strings
|
|
122
|
+
}
|
|
123
|
+
getPathBy(node) {
|
|
124
|
+
let relative = '';
|
|
125
|
+
let current = node;
|
|
126
|
+
while (current.parent) {
|
|
127
|
+
relative = relative
|
|
128
|
+
? `${current.value}${sep}${relative}`
|
|
129
|
+
: current.value;
|
|
130
|
+
current = current.parent;
|
|
131
|
+
}
|
|
132
|
+
return { relative, absolute: resolve(this.base, relative) };
|
|
133
|
+
}
|
|
134
|
+
buildByDirNames(dirNames) {
|
|
135
|
+
const root = this.initNode();
|
|
136
|
+
this.checkRelativePaths(dirNames);
|
|
137
|
+
const dirNameArr = this.formatDirnames(dirNames);
|
|
138
|
+
for (const dirName of dirNameArr) {
|
|
139
|
+
const node = this.initNode();
|
|
140
|
+
node.value = dirName;
|
|
141
|
+
node.parent = root;
|
|
142
|
+
node.children = this.buildChildren(resolve(this.base, dirName), node);
|
|
143
|
+
root.children.push(node);
|
|
144
|
+
}
|
|
145
|
+
return root;
|
|
146
|
+
}
|
|
147
|
+
build() {
|
|
148
|
+
const dirNameArr = readdirSync(this.base).filter(name => {
|
|
149
|
+
const abs = resolve(this.base, name);
|
|
150
|
+
return PathValidator.isDirectory(abs);
|
|
151
|
+
});
|
|
152
|
+
return this.buildByDirNames(dirNameArr);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { PathTreeify };
|
|
157
|
+
//# sourceMappingURL=index.mjs.map
|
package/dist/types/index.d.ts
CHANGED
|
@@ -26,15 +26,11 @@ export declare class PathTreeify {
|
|
|
26
26
|
private buildChildren;
|
|
27
27
|
private checkRelativePaths;
|
|
28
28
|
private formatDirnames;
|
|
29
|
-
private getAllDirNamesUnderBase;
|
|
30
|
-
private buildByDirNames;
|
|
31
|
-
private buildByFilter;
|
|
32
29
|
getPathBy(node: PathTreeNode): {
|
|
33
30
|
relative: string;
|
|
34
31
|
absolute: string;
|
|
35
32
|
};
|
|
36
|
-
|
|
37
|
-
buildBy(filter: (dirName: string) => boolean): PathTreeNode;
|
|
33
|
+
buildByDirNames(dirNames: string[]): PathTreeNode;
|
|
38
34
|
build(): PathTreeNode;
|
|
39
35
|
}
|
|
40
36
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "path-treeify",
|
|
3
|
-
"version": "1.1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Convert a path or an array of paths into a tree-structured JavaScript object, where each node has a `parent` property that holds a circular reference to its parent node.",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|