As usual, you need to install from npm/yarn:
$ npm install cli-badges
This is a simple example, using badges to display test results:
const { badge } = require('cli-badges');
const failedBadge = badge('failed', '2', { messageBg: 'red' });
const skippedBadge = badge('skipped', '1', {
messageBg: 'yellow',
messageColor: 'black',
});
const successBadge = badge('success', '8', {
messageBg: 'green',
messageColor: 'black',
});
console.log(failedBadge, successBadge, skippedBadge);
The above would output something similar to the terminal:
You could also create a donate badge with a link (if supported):
const donateBadge = badge('❤️ donate', 'ko-fi', {
link: 'https://ko-fi.com/logginjs',
});
console.log(donateBadge);
You can also only show the label:
const { badge } = require('../index');
const onlyLabel = badge('❤️ donate', '', { labelColor: 169 });
console.log(onlyLabel);
A badge is conformed of a label and a message <label>:<message>
. Each segment can be customized, by changing bg color, text color and style.
cli-badges
exports a method called badge
.
export function badge(
label?: string,
message?: string,
options?: {
labelBg?: string | number;
messageBg?: string | number;
labelColor?: string | number;
messageColor?: string | number;
labelStyle?: any;
messageStyle?: any;
labelWidth?: any;
messageWidth?: any;
link?: any;
}
): string;
labelBg
- background color for the label- default: blackBright
messageBg
- background color for the message- default: blue
labelColor
- text color for the label- default: white
messageColor
- text color for the message- default: white
labelStyle
- text style for the label - [italic, bold]messageStyle
- text style for the message - [italic, bold]labelWidth
- width of the label- default: label length + 2
messageWidth
- width of the message- default: label length + 2
link
- Add a link when a badge is clicked (only works in some terminals, see this)
cli-badges
uses cli-color
internally for managing colors, you can check the list of available colors there. Take into account that when setting a color you don't need to pass the prefix bg
, it's handled for you. ie: blackBright
instead of bgBlackBright
black
red
green
yellow
blue
magenta
cyan
white
blackBright
redBright
greenBright
yellowBright
blueBright
magentaBright
cyanBright
whiteBright
There are more colors available using xterm colors, see cli-color xterm colors for the complete list of available colors.
Not supported on Windows and some terminals. However if used in not supported environment, the closest color from basic (16 colors) palette is chosen.
You can output badges with a link attached to it, that can be clicked in some terminals.
See this for information on supported terminals
badge('with', 'link', { link: 'https://link.com' });
I tend to open source anything I can, adn love to help people that need help with the project.
However, if you are using this project and happy with it or just want to encourage me to continue creating stuff, there are few ways you can do it :-
- Starring and sharing the project 🚀
- Reporting bugs 🐛
- Sending feedback
- Or even coding :P
Thanks! ❤️
Contributions are very welcomed 🥰