blob: 6729745f8a6c74768011170733f22fe86bb49e56 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# walk-up-path
Given a path string, return a generator that walks up the path, emitting
each dirname.
So, to get a platform-portable walk up, instead of doing something like
this:
```js
for (let p = dirname(path); p;) {
// ... do stuff ...
const pp = dirname(p)
if (p === pp)
p = null
else
p = pp
}
```
Or this:
```js
for (let p = dirname(path); !isRoot(p); p = dirname(p)) {
// ... do stuff ...
}
```
You can do this:
```js
const walkUpPath = require('walk-up-path')
for (const p of walkUpPath(path)) {
// ... do stuff ..
}
```
## API
```js
const walkUpPath = require('walk-up-path')
```
Give the fn a string, it'll yield all the directories walking up to the
root.
|