UNPKG

1.64 kBMarkdownView Raw
1# read-pkg
2
3> Read a package.json file
4
5## Why
6
7- [Throws more helpful JSON errors](https://github.com/sindresorhus/parse-json)
8- [Normalizes the data](https://github.com/npm/normalize-package-data#what-normalization-currently-entails)
9
10## Install
11
12```
13$ npm install read-pkg
14```
15
16## Usage
17
18```js
19import {readPackage} from 'read-pkg';
20
21console.log(await readPackage());
22//=> {name: 'read-pkg', …}
23
24console.log(await readPackage({cwd: 'some-other-directory'}));
25//=> {name: 'unicorn', …}
26```
27
28## API
29
30### readPackage(options?)
31
32Returns a `Promise<object>` with the parsed JSON.
33
34### readPackageSync(options?)
35
36Returns the parsed JSON.
37
38#### options
39
40Type: `object`
41
42##### cwd
43
44Type: `string`\
45Default: `process.cwd()`
46
47Current working directory.
48
49##### normalize
50
51Type: `boolean`\
52Default: `true`
53
54[Normalize](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data.
55
56## Related
57
58- [read-pkg-up](https://github.com/sindresorhus/read-pkg-up) - Read the closest package.json file
59- [write-pkg](https://github.com/sindresorhus/write-pkg) - Write a `package.json` file
60- [load-json-file](https://github.com/sindresorhus/load-json-file) - Read and parse a JSON file
61
62---
63
64<div align="center">
65 <b>
66 <a href="https://tidelift.com/subscription/pkg/npm-read-pkg?utm_source=npm-read-pkg&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
67 </b>
68 <br>
69 <sub>
70 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
71 </sub>
72</div>