Installations
npm install chalk-template
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
>=14.16
Node Version
14.21.3
NPM Version
9.2.0
Score
99.3
Supply Chain
99.5
Quality
77.7
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (93.9%)
TypeScript (6.1%)
Developer
chalk
Download Statistics
Total Downloads
208,422,676
Last Day
317,782
Last Week
2,431,541
Last Month
11,029,671
Last Year
100,772,329
GitHub Statistics
93 Stars
21 Commits
12 Forks
8 Watching
1 Branches
7 Contributors
Bundle Size
7.57 kB
Minified
3.22 kB
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
1.1.0
Package Id
chalk-template@1.1.0
Unpacked Size
13.42 kB
Size
4.39 kB
File Count
5
NPM Version
9.2.0
Node Version
14.21.3
Publised On
23 May 2023
Total Downloads
Cumulative downloads
Total Downloads
208,422,676
Last day
-33.4%
317,782
Compared to previous day
Last week
-12.5%
2,431,541
Compared to previous week
Last month
6.4%
11,029,671
Compared to previous month
Last year
47.4%
100,772,329
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
chalk-template
Terminal string styling with tagged template literals
Install
1npm install chalk-template
Usage
For printing to standard output (stdout):
1import chalkTemplate from 'chalk-template'; 2import chalk from 'chalk'; 3 4console.log(chalkTemplate` 5CPU: {red ${cpu.totalPercent}%} 6RAM: {green ${ram.used / ram.total * 100}%} 7DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%} 8`); 9 10console.log(chalk.red.bgBlack(chalkTemplate`2 + 3 = {bold ${2 + 3}}`)); 11 12const miles = 18; 13const calculateFeet = miles => miles * 5280; 14 15console.log(chalkTemplate` 16 There are {bold 5280 feet} in a mile. 17 In {bold ${miles} miles}, there are {green.bold ${calculateFeet(miles)} feet}. 18`); 19 20console.log(chalkTemplate` 21 There are also {#FF0000 shorthand hex styles} for 22 both the {#ABCDEF foreground}, {#:123456 background}, 23 or {#ABCDEF:123456 both}. 24`);
For printing to standard error (stderr):
1import {chalkTemplateStderr} from 'chalk-template'; 2 3console.error(chalkTemplateStderr` 4CPU: {red ${cpu.totalPercent}%} 5RAM: {green ${ram.used / ram.total * 100}%} 6DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%} 7`);
API
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:
1import chalk from 'chalk'; 2import chalkTemplate from 'chalk-template'; 3 4console.log(chalk.bold.rgb(10, 100, 200)('Hello!')); 5console.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.
Template function
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.
1import {template} from 'chalk-template'; 2 3console.log(template('Today is {red hot}'));
1import {templateStderr} from 'chalk-template'; 2 3console.error(templateStderr('Today is {red hot}'));
Create template functions using a custom Chalk instance
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.
1import {Chalk} from 'chalk' 2import {makeTemplate, makeTaggedTemplate} from 'chalk-template'; 3 4const template = makeTemplate(new Chalk({level: 3})); 5const chalkTemplate = makeTaggedTemplate(new Chalk({level: 3})); 6 7console.log(template('Today is {red hot}')); 8console.log(chalkTemplate`Today is {red hot}`);
Related
Maintainers
No vulnerabilities found.
Reason
security policy file detected
Details
- Info: security policy file detected: .github/security.md:1
- Info: Found linked content: .github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: .github/security.md:1
- Info: Found text in security policy: .github/security.md:1
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
Found 7/21 approved changesets -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/chalk/chalk-template/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/chalk/chalk-template/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:22
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 7 are checked with a SAST tool
Score
4.3
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More