https://github.com/cityssm/node-has-package
Tests if a package is available to be imported. Useful for checking if optional dependencies are installed.
https://github.com/cityssm/node-has-package
dependencies dependency import optional-dependencies require
Last synced: 7 months ago
JSON representation
Tests if a package is available to be imported. Useful for checking if optional dependencies are installed.
- Host: GitHub
- URL: https://github.com/cityssm/node-has-package
- Owner: cityssm
- License: mit
- Created: 2024-11-21T14:53:28.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-09-29T13:36:25.000Z (8 months ago)
- Last Synced: 2025-10-03T03:26:05.119Z (8 months ago)
- Topics: dependencies, dependency, import, optional-dependencies, require
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@cityssm/has-package
- Size: 184 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Has Package
[](https://www.npmjs.com/package/@cityssm/has-package)
[](https://app.deepsource.com/gh/cityssm/node-has-package/)
[](https://codecov.io/gh/cityssm/node-has-package)
**Tests if a package is available to be imported. Useful for checking if optional dependencies are installed.**
Unlike other packages that test whether a package is available by importing it,
this package **checks the file system** for the corresponding `package.json` file.
This avoids any package code from running during the check.
## Installation
```sh
npm install @cityssm/has-package
```
## Usage
```javascript
import hasPackage from '@cityssm/has-package'
/*
* Test for an existing package
*/
let packageExists = await hasPackage('eslint')
console.log(packageExists)
// => true
/*
* Test for an nonexisting package
*/
packageExists = await hasPackage('@cityssm/non-existing-package')
console.log(packageExists)
// => false
```