index.d.ts
 1  import {Except} from 'type-fest';
 2  import readPkg = require('read-pkg');
 3  
 4  declare namespace readPkgUp {
 5  	type Options = {
 6  		/**
 7  		Directory to start looking for a package.json file.
 8  
 9  		@default process.cwd()
10  		*/
11  		cwd?: string;
12  	} & Except<readPkg.Options, 'cwd'>;
13  
14  	type NormalizeOptions = {
15  		/**
16  		Directory to start looking for a package.json file.
17  
18  		@default process.cwd()
19  		*/
20  		cwd?: string;
21  	} & Except<readPkg.NormalizeOptions, 'cwd'>;
22  
23  	type PackageJson = readPkg.PackageJson;
24  	type NormalizedPackageJson = readPkg.NormalizedPackageJson;
25  
26  	interface ReadResult {
27  		packageJson: PackageJson;
28  		path: string;
29  	}
30  
31  	interface NormalizedReadResult {
32  		packageJson: NormalizedPackageJson;
33  		path: string;
34  	}
35  }
36  
37  declare const readPkgUp: {
38  	/**
39  	Read the closest `package.json` file.
40  
41  	@example
42  	```
43  	import readPkgUp = require('read-pkg-up');
44  
45  	(async () => {
46  		console.log(await readPkgUp());
47  		// {
48  		// 	packageJson: {
49  		// 		name: 'awesome-package',
50  		// 		version: '1.0.0',
51  		// 		…
52  		// 	},
53  		// 	path: '/Users/sindresorhus/dev/awesome-package/package.json'
54  		// }
55  	})();
56  	```
57  	*/
58  	(options?: readPkgUp.NormalizeOptions): Promise<
59  		readPkgUp.NormalizedReadResult | undefined
60  	>;
61  	(options: readPkgUp.Options): Promise<readPkgUp.ReadResult | undefined>;
62  
63  	/**
64  	Synchronously read the closest `package.json` file.
65  
66  	@example
67  	```
68  	import readPkgUp = require('read-pkg-up');
69  
70  	console.log(readPkgUp.sync());
71  	// {
72  	// 	packageJson: {
73  	// 		name: 'awesome-package',
74  	// 		version: '1.0.0',
75  	// 		…
76  	// 	},
77  	// 	path: '/Users/sindresorhus/dev/awesome-package/package.json'
78  	// }
79  	```
80  	*/
81  	sync(
82  		options?: readPkgUp.NormalizeOptions
83  	): readPkgUp.NormalizedReadResult | undefined;
84  	sync(options: readPkgUp.Options): readPkgUp.ReadResult | undefined;
85  };
86  
87  export = readPkgUp;