npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dependency-exists

v1.0.9

Published

Dependency Exists - Best way to check if some dependency exists in your package.json file.

Downloads

4

Readme

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

| 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 |

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.

| Properties | Desrciption | Type | | ----------- | ------------------------------- | ------------------------------- | | packageName | npm package name | string | | options | Custamizable 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: [email protected]

linkedin

portfolio

Support my work

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

| Revolut | Buy me a coffee | | -------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Revolute | |

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


Copyright ©️2023. All rights reserved.