
Research
Security News
Malicious npm Packages Target BSC and Ethereum to Drain Crypto Wallets
Socket uncovered four malicious npm packages that exfiltrate up to 85% of a victim’s Ethereum or BSC wallet using obfuscated JavaScript.
chalk-template
Advanced tools
Terminal string styling with tagged template literals
npm install chalk-template
For printing to standard output (stdout):
import chalkTemplate from 'chalk-template';
import chalk from 'chalk';
console.log(chalkTemplate`
CPU: {red ${cpu.totalPercent}%}
RAM: {green ${ram.used / ram.total * 100}%}
DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
`);
console.log(chalk.red.bgBlack(chalkTemplate`2 + 3 = {bold ${2 + 3}}`));
const miles = 18;
const calculateFeet = miles => miles * 5280;
console.log(chalkTemplate`
There are {bold 5280 feet} in a mile.
In {bold ${miles} miles}, there are {green.bold ${calculateFeet(miles)} feet}.
`);
console.log(chalkTemplate`
There are also {#FF0000 shorthand hex styles} for
both the {#ABCDEF foreground}, {#:123456 background},
or {#ABCDEF:123456 both}.
`);
For printing to standard error (stderr):
import {chalkTemplateStderr} from 'chalk-template';
console.error(chalkTemplateStderr`
CPU: {red ${cpu.totalPercent}%}
RAM: {green ${ram.used / ram.total * 100}%}
DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
`);
Blocks are delimited by an opening curly brace ({
), a style, some content, and a closing curly brace (}
).
Template styles are chained exactly like normal Chalk styles. The following two statements are equivalent:
import chalk from 'chalk';
import chalkTemplate from 'chalk-template';
console.log(chalk.bold.rgb(10, 100, 200)('Hello!'));
console.log(chalkTemplate`{bold.rgb(10,100,200) Hello!}`);
Note that function styles (rgb()
, etc.) may not contain spaces between parameters.
All interpolated values (chalkTemplate`${foo}`
) are converted to strings via the .toString()
method. All curly braces ({
and }
) in interpolated value strings are escaped.
This function can be useful if you need to wrap the template function. However, prefer the default export whenever possible.
Note: It's up to you to properly escape the input.
import {template} from 'chalk-template';
console.log(template('Today is {red hot}'));
import {templateStderr} from 'chalk-template';
console.error(templateStderr('Today is {red hot}'));
The makeTemplate
and makeTaggedTemplate
functions are exported so functions can be created using a custom Chalk instance.
Note: When using a function created with makeTemplate
, it's up to you to properly escape the input.
import {Chalk} from 'chalk'
import {makeTemplate, makeTaggedTemplate} from 'chalk-template';
const template = makeTemplate(new Chalk({level: 3}));
const chalkTemplate = makeTaggedTemplate(new Chalk({level: 3}));
console.log(template('Today is {red hot}'));
console.log(chalkTemplate`Today is {red hot}`);
FAQs
Terminal string styling with tagged template literals
The npm package chalk-template receives a total of 3,479,896 weekly downloads. As such, chalk-template popularity was classified as popular.
We found that chalk-template demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
Research
Security News
Socket uncovered four malicious npm packages that exfiltrate up to 85% of a victim’s Ethereum or BSC wallet using obfuscated JavaScript.
Security News
TC39 advances 9 JavaScript proposals, including Array.fromAsync, Error.isError, and Explicit Resource Management, which are now headed into the ECMAScript spec.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.