https://github.com/kristiyan-velkov/dependency-exists
Best way to check if some dependency exists in your package.json file.
https://github.com/kristiyan-velkov/dependency-exists
Last synced: about 1 month ago
JSON representation
Best way to check if some dependency exists in your package.json file.
- Host: GitHub
- URL: https://github.com/kristiyan-velkov/dependency-exists
- Owner: kristiyan-velkov
- License: mit
- Created: 2023-02-27T10:47:41.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-22T08:56:39.000Z (over 1 year ago)
- Last Synced: 2025-05-07T12:55:25.836Z (about 1 month ago)
- Language: TypeScript
- Size: 188 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
dependency-exists
[](https://github.com/christiyan14) [](https://github.com/christiyan14) [](https://choosealicense.com/licenses/mit/) [](https://nodejs.org/en/)
**Checks if an npm package exists in package.json dependencies. You can also provide a nice terminal message which can be customized as you like.**
You can select where to search the npm package in package.json dependencies (by default is all of them):
- **dependencies**
- **devDependencies**
- **peerDependencies**---
## Table of contents
- [Installation 🦾](#installation)
- [How to Use? 💻](#how-to-use)
- [Developer Support 🔗 ](#developer-support)
- [Support my work ❤️ ](#support-my-work)---
## Installation
- Via yarn:
```code
yarn add -D dependency-exists
```- Via npm:
```code
npm install dependency-exists --save-dev
```## How to use?
#### API
| Method | Usage |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **dependencyExists()** | Еasy to use a method that will return a boolean value if npm package exists in package.json dependecies. Option to select specific dependecies scheck. |
| **dependencyExistsWithText()** | Will return a boolean value if the npm package exists. Also will provide a nice terminal message which can be customized as you like. |---
1. **dependencyExists()**
| Properties | Desrciption | Type |
| ------------------- | ----------------------------------------------- | ------------------ |
| packageName | npm package name | string |
| dependenciesConfig? | Search in specific dependencies in package.json | DependenciesConfig |```js
interface DependenciesConfig {
dependencies: boolean;
devDependencies: boolean;
peerDependencies: boolean;
}
``````js
function dependencyExists(packageName: string, dependenciesConfig: DependenciesConfig = {
dependencies: true,
devDependencies: true,
peerDependencies: true
}): boolean;```
- **Default**:
By default accepts a string and returns a boolean value. Search in all pakage.json file dependencies:
- **dependencies**
- **devDependencies**
- **peerDependencies**```js
import { dependencyExists } from "@kv/dependency-exists";if (dependencyExists("some-npm-package-name")) {
//=> true
} else {
//=> false
}
```- **With dependenciesConfig**
If you want to search for specific npm package in specific dependency, you can provide config:```js
import { dependencyExists } from "@kv/dependency-exists";if (
dependencyExists("some-npm-package-name", {
dependencies: false,
devDependencies: true, // Will search only in devDependencies
peerDependencies: false,
})
) {
//=> true if the package exists in devDependecies
} else {
//=> false if the package NOT exists in devDependecies
}
```---
2. **dependencyExistsWithText() method**
```js
function DependencyExistsWithTextOptions(packageName: string, options: DependencyExistsWithTextOptions): boolean;
```- **Info:** Easy to use fully customizable method for checking if the npm package exists. Coming with default terminal response. The message in the console (color, text ) can be changed to whatever value you want.
| Properties | Desrciption | Type |
| ----------- | ------------------------------- | ------------------------------- |
| packageName | npm package name | string |
| options | Custamizable terminal response. | DependencyExistsWithTextOptions |```js
export enum DefaultColorsEnum {
success = "#008000",
error = "#DC143C",
warn = "#FFD700",
info = "#00FFFF",
}export interface DependencyExistsWithTextOptions {
success: DependencyExistsWithTextOption;
error: DependencyExistsWithTextOption;
}interface DependencyExistsWithTextOption {
color?: string | DefaultColorsEnum.success | DefaultColorsEnum.error | DefaultColorsEnum.info | DefaultColorsEnum.warn,
text: string,
warn?: TextOptionsStructure;
info?: TextOptionsStructure;
}interface TextOptionsStructure {
color?: string | DefaultColorsEnum.success | DefaultColorsEnum.error | DefaultColorsEnum.info | DefaultColorsEnum.warn;
text?: string;
}// Example options types
success: {
text: "string",
color?: "string",
warn?: {
color?: "string",
text?: "string",
},
info?: {
color?: "string",
text?: "string",
},
},
error: {
text: "string",
color?: "string",
warn?: {
color?: "string",
text?: "string",
},
info?: {
color?: "string",
text?: "string",
},
``````js
import { dependencyExistsWithText } from "@kv/dependency-exists";dependencyExistsWithText("some-npm-package-name", {
success: {
color: "#ffffff", // string of terminal emulators supported hex color
text: "npm package exists!", // string
warn: {
color: "#DEADED", // string of terminal emulators supported hex color
text: "Some exists warning text.", // string
},
info: {
color: "#00cafc", // string of terminal emulators supported hex color
text: "Some exists info text!", // string
},
},
error: {
color: "#ffffff", // string of terminal emulators supported hex color
text: "Example text: npm package NOT exist!", // string
warn: {
color: "#DEADED", // string of terminal emulators supported hex color
text: "Some exists warning text.", // string
},
info: {
color: "#00cafc", // string of terminal emulators supported hex color
text: "Some exists info text!", // string
},
},
});
```## Examples:
## Developer Support:
- If you saw some issue/bug 🐛 related to the specific release version.
- If you want some new feature or change to be added/implemented. 😊Please, contact the creator of the **replace-styles**, so he will be able to fix or improve it:
**Kristiyan Velkov**
**Email:** [email protected]
[](https://www.linkedin.com/in/kristiyan-velkov-763130b3/)
[](https://github.com/christiyan14)
## Support my work
If you like my work and want to support me to work hard, please donate via:
| Revolut | Buy me a coffee |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
||
|
Thanks a bunch for supporting me! It means a LOT 😍
---
Copyright ©️2023. All rights reserved.