read-pkg
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@types/normalize-package-data | 2.4.4 | 1.81 kB | MIT | prod | |
normalize-package-data | 6.0.0 | 8.68 kB | BSD-2-Clause | prod | 1 2 |
parse-json | 7.1.1 | 2.82 kB | MIT | prod | |
type-fest | 4.18.1 | 354.63 kB | (MIT OR CC0-1.0) | prod |
The read-pkg module provides a convenient way to read a package.json file in JavaScript. It throws helpful JSON errors and normalizes the data for you. An integral step in almost all npm modules, read-pkg abstracts the process of reading and parsing a package.json file, making your projects cleaner and more efficient.
To use read-pkg, first install it in your project by running npm install read-pkg
in your terminal. After the installation, you can use it in your JavaScript code by importing it and using the readPackage()
method to read a package.json file. The cwd
option can be supplied to specify a different current working directory.
Here's a simple usage example:
import {readPackage} from 'read-pkg';
console.log(await readPackage());
//=> {name: 'read-pkg', β¦}
console.log(await readPackage({cwd: 'some-other-directory'}));
//=> {name: 'unicorn', β¦}
For synchronous version, you can use readPackageSync()
method:
import {readPackageSync} from 'read-pkg';
console.log(readPackageSync());
The read-pkg documentation is primarily located on its GitHub repository. Here you can find information about its API, usage examples, and other related information. Remember to check out the "options" section to understand how you can customize the behavior of read-pkg. Specifically, the normalize
option can be used to normalize the package data.