
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Set ansi colors in strings using <>
markers and chalk.
const chalker = require("chalker");
console.log(chalker("<red.bgGreen>Red on Green Text</>"));
// with template string tagging
console.log(chalker`<green>hello world</green>`);
A typical use case is to easily manage colors for logs that could go to console or log servers.
const msg = `<red>some error occurred...</red>`;
// log to console for visual with colors
if (!production) console.log(chalker(msg));
// log to log server with colors removed
logger.log(chalker.remove(msg));
npm i --save chalker
Color markers has the <red>red text</red>
format. You can use any valid methods chalk supports.
<blue.bold>blue bold text</blue.bold>
will colorize blue bold text
with chalk.blue.bold
.</>
The following HTML entities escapes are supported:
Entity | Character | Entity | Character |
---|---|---|---|
< | < | > | > |
& | & | | non-breaking space |
' | ' | © | © |
" | " | ® | ® |
HTML escape using code points also works:
&#xhhhh;
where hhhh
is the Hex code point.&#nnnn;
where nnnn
is the Decimal code point.��
makes 👩Chalk advanced colors can be applied with:
chalk API | chalker marker | chalk API | chalker marker |
---|---|---|---|
chalk.rgb | <(255, 10, 20)> , <rgb(255,10,20)> | chalk.bgRgb | <bg(255, 10, 20)> , <bgRgb(255,10,20)> |
chalk.hex | <#FF0000> , <hex(#FF0000)> | chalk.bgHex | <bg#0000FF> , <bgHex(#0000FF)> |
chalk.keyword | <orange> , <(orange)> , <keyword(orange)> | chalk.bgKeyword | <bg-orange> , <bg(orange)> , <bgKeyword(orange)> |
chalk.hsl | <hsl(32,100,50)> | chalk.bgHsl | <bgHsl(32,100,50)> |
chalk.hsv | <hsv(32,100,100)> | chalk.bgHsv | <bgHsv(32,100,100)> |
chalk.hwb | <hwb(32,0,50)> | chalk.bgHwb | <bgHwb(32,0,50)> |
a marker is tried with chalk.keyword
if:
it's not detected as hex value
it doesn't contain params enclosed in ()
it's not found as a basic color that chalk
supports
for example, this is a chalk color keyword: <orange>
If it's prefixed with "bg-"
then it's tried using chalk.bgKeyword
<bg-orange>
All markers can be comined with .
in any order as long as they work with chalk
<#FF0000.bg#0000FF.bg-orange.keyword(red)>
chalker
chalker(str, [chalkInstance]);
str
- String with chalker color markerschalkInstance
- Optional custom instance of chalk.
new chalk.constructor({level: 2})
Returns: A string with terminal/ansi color codes
If
chalk.supportsColor
isfalse
, then it will simply remove the<>
markers and decode HTML entities only.
chalker.remove
chalker.remove(str, keepHtml);
str
- String with chalker color markerskeepHtml
- If true
, then don't decode HTML entity escapes.Simply remove all chalker markers and return the plain text string, with HTML escapes decoded.
Returns: A plain text string without chalker color markers
chalker.decodeHtml
chalker.decodeHtml(str);
str
- String to decode HTML entitiesReturns: String with HTML entities escapes decoded
Copyright (c) 2019-present, Joel Chen
Licensed under the Apache License, Version 2.0.
FAQs
Set ansi colors in strings using XML and chalk
We found that chalker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.