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

@anolilab/package-json-utils

v3.0.9

Published

Shared utilities for parsing information from a package.json.

Downloads

2,650

Readme

Shared utilities for parsing information from a package.json file.

typescript-image npm-image license-image



Install

npm install @anolilab/package-json-utils
yarn add @anolilab/package-json-utils
pnpm add @anolilab/package-json-utils

Usage

const { pkg } = require('@anolilab/package-json-utils');

console.log(pkg.name); // will print the name of the "process.cwd()" package.json

List of available helpers:

  • hasPackageProperties

    This function takes an array of property names as input and checks if the "process.cwd()" package.json object has any of those properties.

  • hasPackageSubProperties

    This function takes a package property name as input and returns a new function that checks if the "process.cwd()" package.json object has sub-properties under the specified package property.

  • environmentIsSet

    This function takes an environment variable name as input and checks if the environment variable is set and not equal to "undefined".

  • parseEnvironment

    This function takes an environment variable name and a default value as input. It attempts to parse the value of the environment variable as JSON and returns the parsed value. If parsing fails, it returns the original value as a string.

  • appDirectory

    This variable is assigned the value of the directory name of the package path or an empty string if the package path is undefined.

  • fromRoot

    This function takes a variable number of path segments as input and joins them with the appDirectory to create a complete path from the root directory.

  • hasFile

    This function takes a variable number of path segments as input and checks if a file exists at the specified path relative to the appDirectory.

  • hasScripts

    This variable is assigned the result of calling hasPackageSubProperties with the argument "scripts". It checks if the "process.cwd()" package.json object has any scripts defined.

  • hasPeerDep

    This variable is assigned the result of calling hasPackageSubProperties with the argument "peerDependencies". It checks if the "process.cwd()" package.json object has any peer dependencies defined.

  • hasDep

    This variable is assigned the result of calling hasPackageSubProperties with the argument "dependencies". It checks if the "process.cwd()" package.json object has any regular dependencies defined.

  • hasDevelopmentDep

    This variable is assigned the result of calling hasPackageSubProperties with the argument "devDependencies". It checks if the "process.cwd()" package.json object has any development dependencies defined.

  • hasAnyDep

    This function takes an array of dependency names as input and checks if any of the dependency checks (hasDep, hasDevelopmentDep, hasPeerDep) return true for any of the dependencies.

  • hasTypescript

    This variable is assigned the result of checking if "typescript" is a dependency and if "tsconfig.json" file exists using hasAnyDep and hasFile functions.

  • packageIsTypeModule

    This variable is assigned the result of checking if the "process.cwd()" package.json object has a property "type" and its value is "module".

  • isPackageAvailable

    This function takes a module name as input and checks if the module is available for import. It uses different methods depending on the environment and package type (module or commonjs).

  • showMissingPackages

    This function takes a package name and an array of missing package names as input and logs a warning message with instructions on how to install the missing packages using npm, yarn, or pnpm.

  • unique

    This function takes an array as input and returns a new array with only unique values.

  • pkg

    This variable returns the "process.cwd()" package.json object or undefined.

  • getPackageProperty

    This function takes a package property name as input and returns the value of the property from the "process.cwd()" package.json object or undefined.

  • getPackageSubProperty

    This function takes a package property name and a sub-property name as input and returns the value of the sub-property from the "process.cwd()" package.json object or undefined.

Note: The process.cwd() method is an inbuilt application programming interface of the process module which is used to get the current working directory of the node.js process.

Supported Node.js Versions

Libraries in this ecosystem make the best effort to track Node.js’ release schedule. Here’s a post on why we think this is important.

Contributing

If you would like to help take a look at the list of issues and check our Contributing guild.

Note: please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Credits

License

The anolilab javascript-style-guide is open-sourced software licensed under the MIT license