UNPKG

1.69 kBTypeScriptView Raw
1export interface Options {
2 /**
3 The current working directory.
4
5 @default process.cwd()
6 */
7 readonly cwd?: string;
8
9 /**
10 The type of path to match.
11
12 @default 'file'
13 */
14 readonly type?: 'file' | 'directory';
15
16 /**
17 Allow symbolic links to match if they point to the requested path type.
18
19 @default true
20 */
21 readonly allowSymlinks?: boolean;
22}
23
24export interface AsyncOptions extends Options {
25 /**
26 The number of concurrently pending promises.
27
28 Minimum: `1`
29
30 @default Infinity
31 */
32 readonly concurrency?: number;
33
34 /**
35 Preserve `paths` order when searching.
36
37 Disable this to improve performance if you don't care about the order.
38
39 @default true
40 */
41 readonly preserveOrder?: boolean;
42}
43
44/**
45Get the first path that exists on disk of multiple paths.
46
47@param paths - The paths to check.
48@returns The first path that exists or `undefined` if none exists.
49
50@example
51```
52import {locatePath} from 'locate-path';
53
54const files = [
55 'unicorn.png',
56 'rainbow.png', // Only this one actually exists on disk
57 'pony.png'
58];
59
60console(await locatePath(files));
61//=> 'rainbow'
62```
63*/
64export function locatePath(
65 paths: Iterable<string>,
66 options?: AsyncOptions
67): Promise<string | undefined>;
68
69/**
70Synchronously get the first path that exists on disk of multiple paths.
71
72@param paths - The paths to check.
73@returns The first path that exists or `undefined` if none exists.
74
75@example
76```
77import {locatePathSync} from 'locate-path';
78
79const files = [
80 'unicorn.png',
81 'rainbow.png', // Only this one actually exists on disk
82 'pony.png'
83];
84
85console(locatePathSync(files));
86//=> 'rainbow'
87```
88*/
89export function locatePathSync(
90 paths: Iterable<string>,
91 options?: Options
92): string | undefined;