{"id":16682648,"url":"https://github.com/jchip/chalker","last_synced_at":"2026-05-17T18:01:52.556Z","repository":{"id":57196777,"uuid":"164032520","full_name":"jchip/chalker","owner":"jchip","description":"Set ansi colors in strings using \u003c\u003e markers and chalk","archived":false,"fork":false,"pushed_at":"2020-04-05T20:28:07.000Z","size":293,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-27T01:41:02.890Z","etag":null,"topics":["ansi","chalk","colors","terminal","xml"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jchip.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":null,"support":null}},"created_at":"2019-01-03T23:13:13.000Z","updated_at":"2021-02-02T18:15:52.000Z","dependencies_parsed_at":"2022-09-16T05:21:00.571Z","dependency_job_id":null,"html_url":"https://github.com/jchip/chalker","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchip%2Fchalker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchip%2Fchalker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchip%2Fchalker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchip%2Fchalker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jchip","download_url":"https://codeload.github.com/jchip/chalker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243392326,"owners_count":20283565,"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","chalk","colors","terminal","xml"],"created_at":"2024-10-12T14:08:09.740Z","updated_at":"2026-05-17T18:01:52.538Z","avatar_url":"https://github.com/jchip.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]\n[![Dependency Status][daviddm-image]][daviddm-url] [![devDependency Status][daviddm-dev-image]][daviddm-dev-url]\n\n# chalker\n\nSet ansi colors in strings using `\u003c\u003e` markers and [chalk] or [ansi-colors].\n\n# Usage\n\n```js\nconst chalker = require(\"chalker\");\n\nconsole.log(chalker(\"\u003cred.bgGreen\u003eRed on Green Text\u003c/\u003e\"));\n\n// with template string tagging\nconsole.log(chalker`\u003cgreen\u003ehello world\u003c/green\u003e`);\n```\n\nA typical use case is to easily manage colors for logs that could go to console or log servers.\n\n```js\nconst msg = `\u003cred\u003esome error occurred...\u003c/red\u003e`;\n\n// log to console for visual with colors\nif (!production) console.log(chalker(msg));\n\n// log to log server with colors removed\nlogger.log(chalker.remove(msg));\n```\n\n# Install\n\n```\nnpm i --save chalker chalk\n```\n\nor:\n\n```\nnpm i --save chalker ansi-colors\n```\n\n`chalker` expects either [chalk] `\u003e= 4` or [ansi-colors] `\u003e= 4` as a peer dependency.\n\n# Demo\n\n![demo][demo]\n\n# Marker Details\n\n- Color markers has the `\u003cred\u003ered text\u003c/red\u003e` format. You can use any valid methods [chalk] supports.\n\n  - For example, `\u003cblue.bold\u003eblue bold text\u003c/blue.bold\u003e` will colorize `blue bold text` with `chalk.blue.bold`.\n  - Closing marker can be simply `\u003c/\u003e`\n\n- The following HTML entities escapes are supported:\n\n  | Entity   | Character | Entity   | Character          |\n  | -------- | --------- | -------- | ------------------ |\n  | `\u0026lt;`   | \u0026lt;      | `\u0026gt;`   | \u0026gt;               |\n  | `\u0026amp;`  | \u0026amp;     | `\u0026nbsp;` | non-breaking space |\n  | `\u0026apos;` | \u0026apos;    | `\u0026copy;` | \u0026copy;             |\n  | `\u0026quot;` | \u0026quot;    | `\u0026reg;`  | \u0026reg;              |\n\n- HTML escape using code points also works:\n\n  - Hex - `\u0026#xhhhh;` where `hhhh` is the Hex code point.\n  - Decimal - `\u0026#nnnn;` where `nnnn` is the Decimal code point.\n  - ie: `\u0026#xD83D;\u0026#xDC69;` makes 👩\n\n#### Advanced Chalk Colors\n\nSome advanced color markers use `chalker` compatibility wrappers when Chalk does not provide\nthe corresponding API directly.\n\n[Chalk advanced colors] can be applied with:\n\n| [chalk] API     | chalker marker                                | [chalk] API       | chalker marker                                       |\n| --------------- | --------------------------------------------- | ----------------- | ---------------------------------------------------- |\n| `chalk.rgb`     | `\u003c(255, 10, 20)\u003e`, `\u003crgb(255,10,20)\u003e`         | `chalk.bgRgb`     | `\u003cbg(255, 10, 20)\u003e`, `\u003cbgRgb(255,10,20)\u003e`            |\n| `chalk.hex`     | `\u003c#FF0000\u003e`, `\u003chex(#FF0000)\u003e`                 | `chalk.bgHex`     | `\u003cbg#0000FF\u003e`, `\u003cbgHex(#0000FF)\u003e`                    |\n| `chalk.keyword` | `\u003corange\u003e`, `\u003c(orange)\u003e`, `\u003ckeyword(orange)\u003e` | `chalk.bgKeyword` | `\u003cbg-orange\u003e`, `\u003cbg(orange)\u003e`, `\u003cbgKeyword(orange)\u003e` |\n| `chalk.hsl`     | `\u003chsl(32,100,50)\u003e`                            | `chalk.bgHsl`     | `\u003cbgHsl(32,100,50)\u003e`                                 |\n| `chalk.hsv`     | `\u003chsv(32,100,100)\u003e`                           | `chalk.bgHsv`     | `\u003cbgHsv(32,100,100)\u003e`                                |\n| `chalk.hwb`     | `\u003chwb(32,0,50)\u003e`                              | `chalk.bgHwb`     | `\u003cbgHwb(32,0,50)\u003e`                                   |\n\n##### More details\n\n- a marker is tried with `chalk.keyword` if:\n\n  - it's not detected as hex value\n  - it doesn't contain params enclosed in `()`\n  - it's not found as a basic color that `chalk` supports\n  - for example, this is a chalk color keyword: `\u003corange\u003e`\n  - If it's prefixed with `\"bg-\"` then it's tried using `chalk.bgKeyword`\n\n    - ie: `\u003cbg-orange\u003e`\n\n- All markers can be comined with `.` in any order as long as they work with [chalk]\n\n  - ie: `\u003c#FF0000.bg#0000FF.bg-orange.keyword(red)\u003e`\n\n# APIs\n\n### `chalker`\n\n```js\nchalker(str, [chalkInstance]);\n```\n\n- `str` - String with chalker color markers\n- `chalkInstance` - Optional custom instance of [chalk].\n  - ie: created from `new chalk.constructor({level: 2})`\n\n**Returns:** A string with terminal/ansi color codes\n\n\u003e If `chalk.supportsColor` is `false`, then it will simply remove the `\u003c\u003e` markers and decode HTML entities only.\n\n### `chalker.CHALK`\n\n```js\nchalker.CHALK = require(\"ansi-colors\");\n```\n\nSet the default colors library. By default, `chalker` loads `chalk` first and falls back to\n[ansi-colors].\n\n### `chalker.remove`\n\n```js\nchalker.remove(str, keepHtml);\n```\n\n- `str` - String with chalker color markers\n- `keepHtml` - If `true`, then don't decode HTML entity escapes.\n\nSimply remove all chalker markers and return the plain text string, with HTML escapes decoded.\n\n**Returns**: A plain text string without chalker color markers\n\n### `chalker.decodeHtml`\n\n```js\nchalker.decodeHtml(str);\n```\n\n- `str` - String to decode HTML entities\n\n**Returns**: String with HTML entities escapes decoded\n\n# License\n\nCopyright (c) 2019-present, Joel Chen\n\nLicensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).\n\n---\n\n[demo]: ./images/demo.png\n[ansi-colors]: https://www.npmjs.com/package/ansi-colors\n[chalk]: https://www.npmjs.com/package/chalk\n[chalk advanced colors]: https://github.com/chalk/chalk#256-and-truecolor-color-support\n[travis-image]: https://travis-ci.org/jchip/chalker.svg?branch=master\n[travis-url]: https://travis-ci.org/jchip/chalker\n[npm-image]: https://badge.fury.io/js/chalker.svg\n[npm-url]: https://npmjs.org/package/chalker\n[daviddm-image]: https://david-dm.org/jchip/chalker/status.svg\n[daviddm-url]: https://david-dm.org/jchip/chalker\n[daviddm-dev-image]: https://david-dm.org/jchip/chalker/dev-status.svg\n[daviddm-dev-url]: https://david-dm.org/jchip/chalker?type=dev\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjchip%2Fchalker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjchip%2Fchalker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjchip%2Fchalker/lists"}