Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lucasbento/is-package-dep

Parses the closest package.json file and returns whether it contains the dependency or not.
https://github.com/lucasbento/is-package-dep

dependency nodejs npm package yarn

Last synced: about 1 month ago
JSON representation

Parses the closest package.json file and returns whether it contains the dependency or not.

Awesome Lists containing this project

README

        

is-package-dep



Parse the closest package.json file (upwards and downwards the tree) and returns whether a package is a dependency or not.





## Why
Needed to check whether if a project has [react-native](https://github.com/facebook/react-native) as a dependency or not.

## Install

```bash
yarn add is-package-dep # or npm i is-package-dep --save
```

## Usage

```js
const isPackageDep = require('is-package-dep');

const isRNProject = isPackageDep('react-native'); // value will be either `true` or `false`
```

## API

### isPackageDep(packageName, [options])
Returns a boolean value that holds whether the package is installed or not.

#### packageName
Type: `string`
The name of the package.

#### options

##### baseDir
Type: `string`
Default: `process.cwd()`
Directory to start looking up for the `package.json` file.

## License
MIT © [Lucas Bento](https://twitter.com/lbentosilva)

---

Thanks to [Sindre Sorhus](https://github.com/sindresorhus) for [read-pkg-up](https://github.com/sindresorhus/read-pkg-up) module.