@sap/generator-cap-project
Version:
Creates a new SAP Cloud Application Programming Model project.
84 lines (48 loc) • 2.05 kB
Markdown
> Read a package.json file
- [Throws more helpful JSON errors](https://github.com/sindresorhus/parse-json)
- [Normalizes the data](https://github.com/npm/normalize-package-data#what-normalization-currently-entails)
```sh
npm install read-pkg
```
```js
import {readPackage} from 'read-pkg';
console.log(await readPackage());
//=> {name: 'read-pkg', …}
console.log(await readPackage({cwd: 'some-other-directory'}));
//=> {name: 'unicorn', …}
```
Returns a `Promise<object>` with the parsed JSON.
Returns the parsed JSON.
Type: `object`
Type: `URL | string`\
Default: `process.cwd()`
Current working directory.
Type: `boolean`\
Default: `true`
[](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data.
Parses an object or string into JSON.
Note: `packageFile` is cloned using [`structuredClone`](https://developer.mozilla.org/en-US/docs/Web/API/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.
Type: `object | string`
An object or a stringified object to be parsed as a package.json.
Type: `object`
Type: `boolean`\
Default: `true`
[](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data.
- [read-pkg-up](https://github.com/sindresorhus/read-pkg-up) - Read the closest package.json file
- [write-pkg](https://github.com/sindresorhus/write-pkg) - Write a `package.json` file
- [load-json-file](https://github.com/sindresorhus/load-json-file) - Read and parse a JSON file