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

color-path

v2.0.0

Published

Add beautiful colors for displaying paths in console

Downloads

1,473

Readme

Color-path

Color path is a little helper to allow for easy great rendering file paths in the console. It uses chalk to handle the actual coloring.

color path rendering

colorize method

The colorize method is the main method exposed by color-path. Its prototype is: colorPath(path, options).

Here in an usage example:

console.log(colorPath.colorize(__dirname + '/' + __filename));

path

String or pathinfo (Object)

path can be either a String containing a path to a file or a pathinfo object (see pathinfo below). It is more performant to use a pathinfo object so if you render multiple times the same path it might be a good idea to use this version.

options

Optional / Object

Options allow to easily tweak the output of colorize. All options below that describe colors can take a function instead of a string. If you provide one it will be called with the pathinfo object representing your path & the option object with the default values populated. They can return a string or another function (coming from the option object for example).

options.colors

Defaults to true. Deactivate colorization if false.

options.file

String or Function

Defaults to:

function(info, options) {
  return info.dirname && !info.dirname.match('node_modules/') ?
    options.basename :
    options.basepath
  ;
}

This means that the color will be defined by options.basename if the path has a directory in it that does not contain a node_modules/ part. Otherwise it will use the options.basepath color.

options.basename

String or Function

Defaults to cyan. Color to use for printing the basename of the path (see options.path above to know when this color will be picked).

options.rootpath

String or Function

Defaults to grey. Color used for the process.cwd() part of the path if the file is in a subfolder of the current working directory.

options.basepath

String or Function

Defaults to reset. Color used for the folders between process.cwd() and the basename.

pathinfo

This method parses a path and return a preprocessed pathinfo object useful to optimize the colorize method. It can also be used to extract infos on the path easily. Looks like:

colorPath.pathinfo('/cwd/complete/path');
// returns
{
  // this is a copy/paste of the path argument of pathinfo
  path: '/cwd/complete/path',
  // dirname of the path, '/' terminated ('' if no dirname)
  dirname: '/cwd/complete/',
  // rootpath === cwd if file is in cwd ('/' terminated)
  rootpath: '/cwd/',
  // basepath = dirname - cwd
  basepath: 'complete/',
  // basename = basename of the file
  basename: 'path'
}

LICENSE

This package is licensed under the terms of the MIT license.