blob: a714f1d3f6fd213526b8d38c3f353c10c0812ac5 [file] [log] [blame]
Peter Marshall0b95ea12020-07-02 16:50:041declare namespace locatePath {
2 interface Options {
3 /**
4 Current working directory.
5
6 @default process.cwd()
7 */
8 readonly cwd?: string;
9
10 /**
11 Type of path to match.
12
13 @default 'file'
14 */
15 readonly type?: 'file' | 'directory';
16
17 /**
18 Allow symbolic links to match if they point to the requested path type.
19
20 @default true
21 */
22 readonly allowSymlinks?: boolean;
23 }
24
25 interface AsyncOptions extends Options {
26 /**
27 Number of concurrently pending promises. Minimum: `1`.
28
29 @default Infinity
30 */
31 readonly concurrency?: number;
32
33 /**
34 Preserve `paths` order when searching.
35
36 Disable this to improve performance if you don't care about the order.
37
38 @default true
39 */
40 readonly preserveOrder?: boolean;
41 }
42}
43
44declare const locatePath: {
45 /**
Nikolay Vitkov924fc2c2025-01-03 09:24:3846 Synchronously get the first path that exists on disk of multiple paths.
47
48 @param paths - Paths to check.
49 @returns The first path that exists or `undefined` if none exists.
50 */
51 sync: (
52 paths: Iterable<string>,
53 options?: locatePath.Options
54 ) => string | undefined;
55
56 /**
Peter Marshall0b95ea12020-07-02 16:50:0457 Get the first path that exists on disk of multiple paths.
58
59 @param paths - Paths to check.
60 @returns The first path that exists or `undefined` if none exists.
61
62 @example
63 ```
64 import locatePath = require('locate-path');
65
66 const files = [
67 'unicorn.png',
68 'rainbow.png', // Only this one actually exists on disk
69 'pony.png'
70 ];
71
72 (async () => {
73 console(await locatePath(files));
74 //=> 'rainbow'
75 })();
76 ```
77 */
78 (paths: Iterable<string>, options?: locatePath.AsyncOptions): Promise<
Nikolay Vitkov924fc2c2025-01-03 09:24:3879 string | undefined
Peter Marshall0b95ea12020-07-02 16:50:0480 >;
Peter Marshall0b95ea12020-07-02 16:50:0481};
82
83export = locatePath;