1
+ /* eslint-disable @typescript-eslint/unified-signatures */
1
2
import { Options as LocatePathOptions } from 'locate-path' ;
2
3
3
4
declare const stop : unique symbol ;
@@ -11,67 +12,30 @@ declare namespace findUp {
11
12
}
12
13
13
14
declare const findUp : {
14
- /**
15
- Find a file or directory by walking up parent directories.
16
-
17
- @param name - Name of the file or directory to find. Can be multiple.
18
- @returns The first path found (by respecting the order of `name`s) or `undefined` if none could be found.
19
-
20
- @example
21
- ```
22
- // /
23
- // └── Users
24
- // └── sindresorhus
25
- // ├── unicorn.png
26
- // └── foo
27
- // └── bar
28
- // ├── baz
29
- // └── example.js
30
-
31
- // example.js
32
- import findUp = require('find-up');
33
-
34
- (async () => {
35
- console.log(await findUp('unicorn.png'));
36
- //=> '/Users/sindresorhus/unicorn.png'
37
-
38
- console.log(await findUp(['rainbow.png', 'unicorn.png']));
39
- //=> '/Users/sindresorhus/unicorn.png'
40
- })();
41
- ```
42
- */
43
- ( name : string | string [ ] , options ?: findUp . Options ) : Promise < string | undefined > ;
44
-
45
- /**
46
- Find a file or directory by walking up parent directories.
15
+ sync : {
16
+ /**
17
+ Synchronously check if a path exists.
47
18
48
- @param matcher - Called for each directory in the search. Return a path or `findUp.stop` to stop the search .
49
- @returns The first path found or `undefined` if none could be found .
19
+ @param path - Path to the file or directory .
20
+ @returns Whether the path exists .
50
21
51
- @example
52
- ```
53
- import path = require('path');
54
- import findUp = require('find-up');
22
+ @example
23
+ ```
24
+ import findUp = require('find-up');
55
25
56
- (async () => {
57
- console.log(await findUp(async directory => {
58
- const hasUnicorns = await findUp.exists(path.join(directory, 'unicorn.png'));
59
- return hasUnicorns && directory;
60
- }, {type: 'directory'}));
61
- //=> '/Users/sindresorhus'
62
- })();
63
- ```
64
- */
65
- ( matcher : ( directory : string ) => ( findUp . Match | Promise < findUp . Match > ) , options ?: findUp . Options ) : Promise < string | undefined > ;
26
+ console.log(findUp.sync.exists('/Users/sindresorhus/unicorn.png'));
27
+ //=> true
28
+ ```
29
+ */
30
+ exists : ( path : string ) => boolean ;
66
31
67
- sync : {
68
32
/**
69
33
Synchronously find a file or directory by walking up parent directories.
70
34
71
35
@param name - Name of the file or directory to find. Can be multiple.
72
36
@returns The first path found (by respecting the order of `name`s) or `undefined` if none could be found.
73
37
*/
74
- ( name : string | string [ ] , options ?: findUp . Options ) : string | undefined ;
38
+ ( name : string | readonly string [ ] , options ?: findUp . Options ) : string | undefined ;
75
39
76
40
/**
77
41
Synchronously find a file or directory by walking up parent directories.
@@ -92,23 +56,7 @@ declare const findUp: {
92
56
```
93
57
*/
94
58
( matcher : ( directory : string ) => findUp . Match , options ?: findUp . Options ) : string | undefined ;
95
-
96
- /**
97
- Synchronously check if a path exists.
98
-
99
- @param path - Path to the file or directory.
100
- @returns Whether the path exists.
101
-
102
- @example
103
- ```
104
- import findUp = require('find-up');
105
-
106
- console.log(findUp.sync.exists('/Users/sindresorhus/unicorn.png'));
107
- //=> true
108
- ```
109
- */
110
- exists ( path : string ) : boolean ;
111
- }
59
+ } ;
112
60
113
61
/**
114
62
Check if a path exists.
@@ -126,12 +74,65 @@ declare const findUp: {
126
74
})();
127
75
```
128
76
*/
129
- exists ( path : string ) : Promise < boolean > ;
77
+ exists : ( path : string ) => Promise < boolean > ;
130
78
131
79
/**
132
80
Return this in a `matcher` function to stop the search and force `findUp` to immediately return `undefined`.
133
81
*/
134
82
readonly stop : findUp . StopSymbol ;
83
+
84
+ /**
85
+ Find a file or directory by walking up parent directories.
86
+
87
+ @param name - Name of the file or directory to find. Can be multiple.
88
+ @returns The first path found (by respecting the order of `name`s) or `undefined` if none could be found.
89
+
90
+ @example
91
+ ```
92
+ // /
93
+ // └── Users
94
+ // └── sindresorhus
95
+ // ├── unicorn.png
96
+ // └── foo
97
+ // └── bar
98
+ // ├── baz
99
+ // └── example.js
100
+
101
+ // example.js
102
+ import findUp = require('find-up');
103
+
104
+ (async () => {
105
+ console.log(await findUp('unicorn.png'));
106
+ //=> '/Users/sindresorhus/unicorn.png'
107
+
108
+ console.log(await findUp(['rainbow.png', 'unicorn.png']));
109
+ //=> '/Users/sindresorhus/unicorn.png'
110
+ })();
111
+ ```
112
+ */
113
+ ( name : string | readonly string [ ] , options ?: findUp . Options ) : Promise < string | undefined > ;
114
+
115
+ /**
116
+ Find a file or directory by walking up parent directories.
117
+
118
+ @param matcher - Called for each directory in the search. Return a path or `findUp.stop` to stop the search.
119
+ @returns The first path found or `undefined` if none could be found.
120
+
121
+ @example
122
+ ```
123
+ import path = require('path');
124
+ import findUp = require('find-up');
125
+
126
+ (async () => {
127
+ console.log(await findUp(async directory => {
128
+ const hasUnicorns = await findUp.exists(path.join(directory, 'unicorn.png'));
129
+ return hasUnicorns && directory;
130
+ }, {type: 'directory'}));
131
+ //=> '/Users/sindresorhus'
132
+ })();
133
+ ```
134
+ */
135
+ ( matcher : ( directory : string ) => ( findUp . Match | Promise < findUp . Match > ) , options ?: findUp . Options ) : Promise < string | undefined > ;
135
136
} ;
136
137
137
138
export = findUp ;
0 commit comments