
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
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.
colorize
methodThe 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'
}
This package is licensed under the terms of the MIT license.
FAQs
Add beautiful colors for displaying paths in console
The npm package color-path receives a total of 395 weekly downloads. As such, color-path popularity was classified as not popular.
We found that color-path demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.