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](https://bytebucket.org/lsystems/color-path/raw/tip/images/render.png)
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');
{
path: '/cwd/complete/path',
dirname: '/cwd/complete/',
rootpath: '/cwd/',
basepath: 'complete/',
basename: 'path'
}
LICENSE
This package is licensed under the terms of the MIT license.