UNPKG

1.29 kBTypeScriptView Raw
1export interface Options {
2 /**
3 The directory to start searching from.
4
5 @default process.cwd()
6 */
7 readonly cwd?: string;
8}
9
10/**
11Find the root directory of a Node.js project or npm package.
12
13@returns The project root path or `undefined` if it could not be found.
14
15@example
16```
17// /
18// └── Users
19// └── sindresorhus
20// └── foo
21// ├── package.json
22// └── bar
23// ├── baz
24// └── example.js
25
26// example.js
27import {packageDirectory} from 'pkg-dir';
28
29console.log(await packageDirectory());
30//=> '/Users/sindresorhus/foo'
31```
32*/
33export function packageDirectory(options?: Options): Promise<string>;
34
35/**
36Synchronously find the root directory of a Node.js project or npm package.
37
38@returns The project root path or `undefined` if it could not be found.
39
40@example
41```
42// /
43// └── Users
44// └── sindresorhus
45// └── foo
46// ├── package.json
47// └── bar
48// ├── baz
49// └── example.js
50
51// example.js
52import {packageDirectorySync} from 'pkg-dir';
53
54console.log(packageDirectorySync());
55//=> '/Users/sindresorhus/foo'
56```
57*/
58export function packageDirectorySync(options?: Options): string;