{"id":13538056,"url":"https://github.com/chalk/chalk-template","last_synced_at":"2025-06-12T17:11:02.972Z","repository":{"id":43374318,"uuid":"360446162","full_name":"chalk/chalk-template","owner":"chalk","description":null,"archived":false,"fork":false,"pushed_at":"2023-06-21T00:23:15.000Z","size":18,"stargazers_count":95,"open_issues_count":2,"forks_count":12,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-06-05T05:33:40.251Z","etag":null,"topics":["ansi-escape-codes","chalk","color","command-line","templating","terminal"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chalk.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-04-22T08:26:05.000Z","updated_at":"2025-04-16T02:52:03.000Z","dependencies_parsed_at":"2024-01-16T15:40:28.843Z","dependency_job_id":"79d84b39-91ef-4c4e-b274-116e9728fa7d","html_url":"https://github.com/chalk/chalk-template","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/chalk/chalk-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalk%2Fchalk-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalk%2Fchalk-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalk%2Fchalk-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalk%2Fchalk-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chalk","download_url":"https://codeload.github.com/chalk/chalk-template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalk%2Fchalk-template/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259509474,"owners_count":22868837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansi-escape-codes","chalk","color","command-line","templating","terminal"],"created_at":"2024-08-01T09:01:06.131Z","updated_at":"2025-06-12T17:11:02.944Z","avatar_url":"https://github.com/chalk.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","terminal"],"sub_categories":[],"readme":"# chalk-template\n\n\u003e Terminal string styling with [tagged template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates)\n\n## Install\n\n```sh\nnpm install chalk-template\n```\n\n## Usage\n\nFor printing to standard output (stdout):\n\n```js\nimport chalkTemplate from 'chalk-template';\nimport chalk from 'chalk';\n\nconsole.log(chalkTemplate`\nCPU: {red ${cpu.totalPercent}%}\nRAM: {green ${ram.used / ram.total * 100}%}\nDISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}\n`);\n\nconsole.log(chalk.red.bgBlack(chalkTemplate`2 + 3 = {bold ${2 + 3}}`));\n\nconst miles = 18;\nconst calculateFeet = miles =\u003e miles * 5280;\n\nconsole.log(chalkTemplate`\n\tThere are {bold 5280 feet} in a mile.\n\tIn {bold ${miles} miles}, there are {green.bold ${calculateFeet(miles)} feet}.\n`);\n\nconsole.log(chalkTemplate`\n\tThere are also {#FF0000 shorthand hex styles} for\n\tboth the {#ABCDEF foreground}, {#:123456 background},\n\tor {#ABCDEF:123456 both}.\n`);\n```\n\nFor printing to standard error (stderr):\n\n```js\nimport {chalkTemplateStderr} from 'chalk-template';\n\nconsole.error(chalkTemplateStderr`\nCPU: {red ${cpu.totalPercent}%}\nRAM: {green ${ram.used / ram.total * 100}%}\nDISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}\n`);\n```\n\n## API\n\nBlocks are delimited by an opening curly brace (`{`), a style, some content, and a closing curly brace (`}`).\n\nTemplate styles are chained exactly like normal [Chalk](https://github.com/chalk/chalk) styles. The following two statements are equivalent:\n\n```js\nimport chalk from 'chalk';\nimport chalkTemplate from 'chalk-template';\n\nconsole.log(chalk.bold.rgb(10, 100, 200)('Hello!'));\nconsole.log(chalkTemplate`{bold.rgb(10,100,200) Hello!}`);\n```\n\nNote that function styles (`rgb()`, etc.) may not contain spaces between parameters.\n\nAll interpolated values (`` chalkTemplate`${foo}` ``) are converted to strings via the `.toString()` method. All curly braces (`{` and `}`) in interpolated value strings are escaped.\n\n## Template function\n\nThis function can be useful if you need to wrap the template function. However, prefer the default export whenever possible.\n\n**Note:** It's up to you to properly escape the input.\n\n```js\nimport {template} from 'chalk-template';\n\nconsole.log(template('Today is {red hot}'));\n```\n\n```js\nimport {templateStderr} from 'chalk-template';\n\nconsole.error(templateStderr('Today is {red hot}'));\n```\n\n## Create template functions using a custom Chalk instance\n\nThe `makeTemplate` and `makeTaggedTemplate` functions are exported so functions can be created using a custom Chalk instance.\n\n**Note:** When using a function created with `makeTemplate`, it's up to you to properly escape the input.\n\n```js\nimport {Chalk} from 'chalk'\nimport {makeTemplate, makeTaggedTemplate} from 'chalk-template';\n\nconst template = makeTemplate(new Chalk({level: 3}));\nconst chalkTemplate = makeTaggedTemplate(new Chalk({level: 3}));\n\nconsole.log(template('Today is {red hot}'));\nconsole.log(chalkTemplate`Today is {red hot}`);\n```\n\n## Related\n\n- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right\n- [chalk-cli](https://github.com/chalk/chalk-cli) - Style text from the terminal\n\n## Maintainers\n\n- [Sindre Sorhus](https://github.com/sindresorhus)\n- [Josh Junon](https://github.com/qix-)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchalk%2Fchalk-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchalk%2Fchalk-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchalk%2Fchalk-template/lists"}