New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

color-path

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color-path

Add beautiful colors for displaying paths in console

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
356
decreased by-17.02%
Maintainers
3
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 28 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc