Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/read-package-up
Read the closest package.json file
https://github.com/sindresorhus/read-package-up
Last synced: about 1 month ago
JSON representation
Read the closest package.json file
- Host: GitHub
- URL: https://github.com/sindresorhus/read-package-up
- Owner: sindresorhus
- License: mit
- Created: 2015-09-03T04:48:40.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2023-11-04T09:30:06.000Z (about 1 year ago)
- Last Synced: 2024-04-13T17:39:56.782Z (7 months ago)
- Language: TypeScript
- Size: 34.2 KB
- Stars: 255
- Watchers: 8
- Forks: 24
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
- Security: .github/security.md
Awesome Lists containing this project
- awesome-npm - read-pkg-up - Read the closest package.json file. (Packages / Other)
- awesome-npm - read-package-up - Read the closest package.json file. (Packages / Other)
README
# read-package-up
> Read the closest package.json file
## Why
- [Finds the closest package.json](https://github.com/sindresorhus/find-up)
- [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)## Install
```sh
npm install read-package-up
```## Usage
```js
import {readPackageUp} from 'read-package-up';console.log(await readPackageUp());
/*
{
packageJson: {
name: 'awesome-package',
version: '1.0.0',
…
},
path: '/Users/sindresorhus/dev/awesome-package/package.json'
}
*/
```## API
### readPackageUp(options?)
Returns a `Promise`, or `Promise` if no `package.json` was found.
### readPackageUpSync(options?)
Returns the result object, or `undefined` if no `package.json` was found.
#### options
Type: `object`
##### cwd
Type: `URL | string`\
Default: `process.cwd()`The directory to start looking for a package.json file.
##### normalize
Type: `boolean`\
Default: `true`[Normalize](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data.
## Related
- [read-pkg](https://github.com/sindresorhus/read-pkg) - Read a package.json file
- [package-up](https://github.com/sindresorhus/package-up) - Find the closest package.json file
- [find-up](https://github.com/sindresorhus/find-up) - Find a file by walking up parent directories
- [pkg-conf](https://github.com/sindresorhus/pkg-conf) - Get namespaced config from the closest package.json