Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 18 days 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 (about 1 month ago)
- Default Branch: main
- Last Pushed: 2024-11-21T16:43:27.000Z (about 1 month ago)
- Last Synced: 2024-11-21T17:22:52.356Z (about 1 month ago)
- Topics: dependencies, dependency, import, optional-dependencies, require
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@cityssm/has-package
- Size: 97.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
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
[![NPM Version](https://img.shields.io/npm/v/%40cityssm%2Fhas-package)](https://www.npmjs.com/package/@cityssm/has-package)
[![Maintainability](https://api.codeclimate.com/v1/badges/d5e8bd61c386abe06f27/maintainability)](https://codeclimate.com/github/cityssm/node-has-package/maintainability)
[![DeepSource](https://app.deepsource.com/gh/cityssm/node-has-package.svg/?label=active+issues&show_trend=true&token=DR3479iXPgrcY5n3e5515lA-)](https://app.deepsource.com/gh/cityssm/node-has-package/)
[![codecov](https://codecov.io/gh/cityssm/node-has-package/graph/badge.svg?token=YG1D26SPQF)](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
```