UNPKG

1.38 kBTypeScriptView Raw
1import * as typeFest from 'type-fest';
2import * as normalize from 'normalize-package-data';
3
4export interface Options {
5 /**
6 Current working directory.
7
8 @default process.cwd()
9 */
10 readonly cwd?: string;
11
12 /**
13 [Normalize](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data.
14
15 @default true
16 */
17 readonly normalize?: boolean;
18}
19
20export interface NormalizeOptions extends Options {
21 readonly normalize?: true;
22}
23
24export type NormalizedPackageJson = PackageJson & normalize.Package;
25export type PackageJson = typeFest.PackageJson;
26
27/**
28@returns The parsed JSON.
29
30@example
31```
32import {readPackage} from 'read-pkg';
33
34console.log(await readPackage());
35//=> {name: 'read-pkg', …}
36
37console.log(await readPackage({cwd: 'some-other-directory'});
38//=> {name: 'unicorn', …}
39```
40*/
41export function readPackage(options?: NormalizeOptions): Promise<NormalizedPackageJson>;
42export function readPackage(options: Options): Promise<PackageJson>;
43
44/**
45@returns The parsed JSON.
46
47@example
48```
49import {readPackageSync} from 'read-pkg';
50
51console.log(readPackageSync());
52//=> {name: 'read-pkg', …}
53
54console.log(readPackageSync({cwd: 'some-other-directory'});
55//=> {name: 'unicorn', …}
56```
57*/
58export function readPackageSync(options?: NormalizeOptions): NormalizedPackageJson;
59export function readPackageSync(options: Options): PackageJson;