1.0.9 • Published 3 months ago

dependency-exists v1.0.9

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

Follow me Sponsors MIT License Node Version

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

  • Via yarn:
yarn add -D dependency-exists
  • Via npm:
npm install dependency-exists --save-dev

How to use?

API

MethodUsage
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()
PropertiesDesrciptionType
packageNamenpm package namestring
dependenciesConfig?Search in specific dependencies in package.jsonDependenciesConfig
interface DependenciesConfig {
  dependencies: boolean;
  devDependencies: boolean;
  peerDependencies: boolean;
}
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
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:

    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
    }

  1. dependencyExistsWithText() method
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.
PropertiesDesrciptionType
packageNamenpm package namestring
optionsCustamizable terminal response.DependencyExistsWithTextOptions
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",
    },
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: christiyanweb@gmail.com

linkedin

portfolio

Support my work

If you like my work and want to support me to work hard, please donate via:

RevolutBuy me a coffee
Revolute

Thanks a bunch for supporting me! It means a LOT 😍


Copyright ©️2023. All rights reserved.

1.0.9

3 months ago

1.0.8

3 months ago

1.0.7

3 months ago

1.0.6

3 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.0

1 year ago