Peter Marshall | 0b95ea1 | 2020-07-02 16:50:04 | [diff] [blame] | 1 | declare 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 | |
| 44 | declare const locatePath: { |
| 45 | /** |
Nikolay Vitkov | 924fc2c | 2025-01-03 09:24:38 | [diff] [blame^] | 46 | 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 Marshall | 0b95ea1 | 2020-07-02 16:50:04 | [diff] [blame] | 57 | 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 Vitkov | 924fc2c | 2025-01-03 09:24:38 | [diff] [blame^] | 79 | string | undefined |
Peter Marshall | 0b95ea1 | 2020-07-02 16:50:04 | [diff] [blame] | 80 | >; |
Peter Marshall | 0b95ea1 | 2020-07-02 16:50:04 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | export = locatePath; |