-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
ce26654
commit 905e612
Showing
5 changed files
with
180 additions
and
104 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,55 @@ | ||
declare namespace findUp { | ||
interface Options { | ||
/** | ||
Directory to start from. | ||
@default process.cwd() | ||
*/ | ||
readonly cwd?: string; | ||
} | ||
} | ||
|
||
declare const findUp: { | ||
/** | ||
Find a file or directory by walking up parent directories. | ||
@param filename - Filename of the file or an array of files to find. | ||
@returns Either the first filepath found (by respecting the order of `filename`s) or `null`. | ||
@example | ||
``` | ||
// / | ||
// └── Users | ||
// └── sindresorhus | ||
// ├── unicorn.png | ||
// └── foo | ||
// └── bar | ||
// ├── baz | ||
// └── example.js | ||
// example.js | ||
import findUp = require('find-up'); | ||
(async () => { | ||
console.log(await findUp('unicorn.png')); | ||
//=> '/Users/sindresorhus/unicorn.png' | ||
console.log(await findUp(['rainbow.png', 'unicorn.png'])); | ||
//=> '/Users/sindresorhus/unicorn.png' | ||
})(); | ||
``` | ||
*/ | ||
(filename: string | string[], options?: findUp.Options): Promise< | ||
string | null | ||
>; | ||
|
||
/** | ||
Synchronously find a file or directory by walking up parent directories. | ||
@param filename - Filename of the file or an array of files to find. | ||
@returns Either the first filepath found (by respecting the order of `filename`s) or `null`. | ||
*/ | ||
sync(filename: string | string[], options?: findUp.Options): string | null; | ||
}; | ||
|
||
export = findUp; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {expectType} from 'tsd'; | ||
import findUp = require('.'); | ||
|
||
expectType<Promise<string | null>>(findUp('unicorn.png')); | ||
expectType<Promise<string | null>>(findUp('unicorn.png', {cwd: ''})); | ||
expectType<Promise<string | null>>(findUp(['rainbow.png', 'unicorn.png'])); | ||
expectType<Promise<string | null>>( | ||
findUp(['rainbow.png', 'unicorn.png'], {cwd: ''}) | ||
); | ||
|
||
expectType<string | null>(findUp.sync('unicorn.png')); | ||
expectType<string | null>(findUp.sync('unicorn.png', {cwd: ''})); | ||
expectType<string | null>(findUp.sync(['rainbow.png', 'unicorn.png'])); | ||
expectType<string | null>( | ||
findUp.sync(['rainbow.png', 'unicorn.png'], {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
Oops, something went wrong.