UNPKG

1.87 kBTypeScriptView Raw
1import type {PackageJson as typeFestPackageJson} from 'type-fest';
2import type {Package as normalizePackage} from 'normalize-package-data';
3
4export type Options = {
5 /**
6 Current working directory.
7
8 @default process.cwd()
9 */
10 readonly cwd?: URL | 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
20// eslint-disable-next-line @typescript-eslint/naming-convention
21type _NormalizeOptions = {
22 readonly normalize?: true;
23};
24
25export type NormalizeOptions = _NormalizeOptions & Options;
26
27export type ParseOptions = Omit<Options, 'cwd'>;
28export type NormalizeParseOptions = _NormalizeOptions & ParseOptions;
29
30export type NormalizedPackageJson = PackageJson & normalizePackage;
31export type PackageJson = typeFestPackageJson;
32
33/**
34@returns The parsed JSON.
35
36@example
37```
38import {readPackage} from 'read-pkg';
39
40console.log(await readPackage());
41//=> {name: 'read-pkg', …}
42
43console.log(await readPackage({cwd: 'some-other-directory'});
44//=> {name: 'unicorn', …}
45```
46*/
47export function readPackage(options?: NormalizeOptions): Promise<NormalizedPackageJson>;
48export function readPackage(options: Options): Promise<PackageJson>;
49
50/**
51@returns The parsed JSON.
52
53@example
54```
55import {readPackageSync} from 'read-pkg';
56
57console.log(readPackageSync());
58//=> {name: 'read-pkg', …}
59
60console.log(readPackageSync({cwd: 'some-other-directory'});
61//=> {name: 'unicorn', …}
62```
63*/
64export function readPackageSync(options?: NormalizeOptions): NormalizedPackageJson;
65export function readPackageSync(options: Options): PackageJson;
66
67export function parsePackage(packageFile: PackageJson | string, options?: NormalizeParseOptions): NormalizedPackageJson;
68export function parsePackage(packageFile: PackageJson | string, options: ParseOptions): PackageJson;