Read a package.json file
npm install @esmkit/read-pkg> Read a package.json file
- Throws more helpful JSON errors
- Normalizes the data
``sh`
npm install @esmkit/read-pkg
`js
import { readPackage } from "@esmkit/read-pkg";
console.log(await readPackage());
//=> {name: 'read-pkg', …}
console.log(await readPackage({ cwd: "some-other-directory" }));
//=> {name: 'unicorn', …}
`
Returns a Promise
Returns the parsed JSON.
#### options
Type: object
##### cwd
Type: URL | stringprocess.cwd()
Default:
Current working directory.
##### normalize
Type: booleantrue
Default:
Normalize the package data.
Parses an object or string into JSON.
Note: packageFile is cloned using structuredClone to prevent modification to the input object. This function is available from Node.js 18 on. In environments without structuredClone (such as Node.js 16), a shallow spread is used instead, which can cause deep properties of the object to be modified. Consider cloning the object before using parsePackage if that's the case.
#### packageFile
Type: object | string
An object or a stringified object to be parsed as a package.json.
#### options
Type: object
##### normalize
Type: booleantrue
Default:
Normalize the package data.
- read-pkg-up - Read the closest package.json file
- write-pkg - Write a package.json` file
- load-json-file - Read and parse a JSON file