-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6f19ff
commit 133f583
Showing
4 changed files
with
98 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
declare namespace locatePath { | ||
interface Options { | ||
/** | ||
Current working directory. | ||
@default process.cwd() | ||
*/ | ||
readonly cwd?: string; | ||
} | ||
|
||
interface AsyncOptions extends Options { | ||
/** | ||
Number of concurrently pending promises. Minimum: `1`. | ||
@default Infinity | ||
*/ | ||
readonly concurrency?: number; | ||
|
||
/** | ||
Preserve `input` order when searching. | ||
Disable this to improve performance if you don't care about the order. | ||
@default true | ||
*/ | ||
readonly preserveOrder?: boolean; | ||
} | ||
} | ||
|
||
declare const locatePath: { | ||
/** | ||
Get the first path that exists on disk of multiple paths. | ||
@param input - Paths to check. | ||
@returns The first path that exists or `undefined` if none exists. | ||
@example | ||
``` | ||
import locatePath = require('locate-path'); | ||
const files = [ | ||
'unicorn.png', | ||
'rainbow.png', // Only this one actually exists on disk | ||
'pony.png' | ||
]; | ||
(async () => { | ||
console(await locatePath(files)); | ||
//=> 'rainbow' | ||
})(); | ||
``` | ||
*/ | ||
(input: Iterable<string>, options?: locatePath.AsyncOptions): Promise< | ||
string | undefined | ||
>; | ||
|
||
/** | ||
Synchronously get the first path that exists on disk of multiple paths. | ||
@param input - Paths to check. | ||
@returns The first path that exists or `undefined` if none exists. | ||
*/ | ||
sync( | ||
input: Iterable<string>, | ||
options?: locatePath.Options | ||
): string | undefined; | ||
}; | ||
|
||
export = locatePath; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {expectType} from 'tsd'; | ||
import locatePath = require('.'); | ||
|
||
const files = [ | ||
'unicorn.png', | ||
'rainbow.png', | ||
'pony.png' | ||
]; | ||
|
||
expectType<Promise<string | undefined>>(locatePath(files)); | ||
expectType<Promise<string | undefined>>(locatePath(files, {concurrency: 2})); | ||
expectType<Promise<string | undefined>>(locatePath(files, {preserveOrder: false})); | ||
expectType<Promise<string | undefined>>(locatePath(files, {cwd: '.'})); | ||
|
||
expectType<string | undefined>(locatePath.sync(files)); | ||
expectType<string | undefined>(locatePath.sync(files, {cwd: '.'})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters