{"id":13576212,"url":"https://github.com/webdiscus/ansis","last_synced_at":"2025-04-06T01:07:42.349Z","repository":{"id":57180472,"uuid":"441530154","full_name":"webdiscus/ansis","owner":"webdiscus","description":"Small and fast Node.js lib to colorize terminal output. Lightweight but powerful alternative to Chalk. Supports Bun, Deno, Next.JS.","archived":false,"fork":false,"pushed_at":"2024-04-24T13:37:16.000Z","size":663,"stargazers_count":65,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-01T16:52:12.501Z","etag":null,"topics":["ansi","bun","chalk","cli","colorette","colors","console","deno","escape","javascript","kleur","log","nextjs","nodejs","picocolors","styles","terminal"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webdiscus.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":"biodiscus","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2021-12-24T18:16:58.000Z","updated_at":"2024-06-06T10:09:49.669Z","dependencies_parsed_at":"2023-12-22T10:03:24.195Z","dependency_job_id":"08bc2987-9f22-42b3-b1a9-b1068c41d3a7","html_url":"https://github.com/webdiscus/ansis","commit_stats":{"total_commits":34,"total_committers":6,"mean_commits":5.666666666666667,"dds":0.1470588235294118,"last_synced_commit":"008a358733379ab2f071dfd5d255f1358192d4bd"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webdiscus%2Fansis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webdiscus%2Fansis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webdiscus%2Fansis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webdiscus%2Fansis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webdiscus","download_url":"https://codeload.github.com/webdiscus/ansis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419860,"owners_count":20936012,"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","bun","chalk","cli","colorette","colors","console","deno","escape","javascript","kleur","log","nextjs","nodejs","picocolors","styles","terminal"],"created_at":"2024-08-01T15:01:08.030Z","updated_at":"2025-04-06T01:07:42.328Z","avatar_url":"https://github.com/webdiscus.png","language":"JavaScript","readme":"\u003ca id=\"top\" name=\"top\"\u003e\u003c/a\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/ansis\"\u003e\n    \u003cimg width=\"323\" src=\"https://github.com/webdiscus/ansis/raw/master/docs/img/logo.png\" alt=\"ansis\"\u003e\n  \u003c/a\u003e\n  \u003ch1 align=\"center\"\u003e[ANSI S]tyles\u003c/h1\u003e\n\u003c/div\u003e\n\n[![npm](https://img.shields.io/npm/v/ansis?logo=npm\u0026color=brightgreen \"npm package\")](https://www.npmjs.com/package/ansis \"download npm package\")\n[![node](https://img.shields.io/node/v/ansis)](https://nodejs.org)\n[![Test](https://github.com/webdiscus/ansis/actions/workflows/test.yml/badge.svg)](https://github.com/webdiscus/ansis/actions/workflows/test.yml)\n[![codecov](https://codecov.io/gh/webdiscus/ansis/branch/master/graph/badge.svg?token=H7SFJONX1X)](https://codecov.io/gh/webdiscus/ansis)\n[![downloads](https://img.shields.io/npm/dm/ansis)](https://www.npmjs.com/package/ansis)\n[![install size](https://packagephobia.com/badge?p=ansis)](https://packagephobia.com/result?p=ansis)\n\nANSI color library with support for CI, terminals, and Chromium-based browser consoles.\\\nAnsis is focused on [small size](#compare-size) and [speed](#benchmark) while providing rich [functionality](#compare) and handling [edge cases](#handling-input-arguments).\n\n\n### 🚀 [Install and Quick Start](#install) ⚖️ [Alternatives](#alternatives) ✨[Why Ansis](#why-ansis)  🔧[Compatibility Check](#compatibility)\n\n![Ansis demo](docs/img/ansis-demo.png)\n\n[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/stackblitz-starters-gs2gve?file=index.js)\n\n\u003ca id=\"features\" name=\"features\"\u003e\u003c/a\u003e\n\n## 💡 Highlights\n\n- Supports **ESM**, **CommonJS**, **TypeScript** across **Node.js**, **Bun**, **Deno**, **Next.JS** runtimes\n- Works in [Chromium-based](#browsers-compatibility) browsers such as **Chrome**, **Edge**, **Opera**, **Brave**, **Vivaldi**\n- Default and [named import](#import): `import ansis, { red, green, bold, dim } from 'ansis'`\n- [Chained syntax](#chained-syntax): `red.bold.underline('text')`\n- Nested [**tagged template strings**](#nested-syntax): ``` red`Error: ${blue`file.js`} not found!` ```\n- [ANSI styles](#base-colors): `dim` **`bold`** _`italic`_ \u003cu\u003e`underline`\u003c/u\u003e \u003cs\u003e`strikethrough`\u003c/s\u003e\n- [ANSI 16 colors](#base-colors): ``` red`Error!` ``` ``` redBright`Error!` ``` ``` bgRed`Error!` ``` ``` bgRedBright`Error!` ```\n- [ANSI 256 colors](#256-colors): ``` fg(56)`violet` ``` ``` bg(208)`orange` ```\n- [Truecolor](#truecolor) (**RGB \u0026 HEX**): ``` rgb(224, 17, 95)`Ruby` ``` ``` hex('#96C')`Amethyst` ```\n- Automatic [fallback](#fallback): Truecolor → 256 colors → 16 colors → no colors\n- [Extend base colors](#extend-colors) with named Truecolor\n- Raw ANSI escape codes: ``` `foo ${red.open}red{red.close} bar` ```\n- Strip ANSI escape codes with `ansis.strip()`\n- Auto-detects [color support](#color-support) across a wide range of [environments](#color-support)\n- Supports [ENV variables](#cli-vars) and [flags](#cli-flags): [`NO_COLOR`](using-env-no-color), [`FORCE_COLOR`](#using-env-force-color), [`COLORTERM`](#using-env-colorterm), `--no-color`, `--color`\n- [Drop-in replacement](#why-ansis) for [`chalk`](#replacing-chalk) [`ansi-colors`](#replacing-ansi-colors) [`colorette`](#replacing-colorette) [`picocolors`](#replacing-picocolors)\n\n\u003c!--  - Chromium-based browsers can display truecolor text in console.\n  - Browsers that do not support ANSI codes will display black/white text in console. --\u003e\n\n## 🛠️ Usage\n\n```js\nimport ansis, { red, cyan, fg, hex } from 'ansis';\n\nansis.blueBright('file.txt')\nred`Error: ${cyan(file)} not found!`\nred.bgWhite`ERROR`\nfg(215)`ANSI 256 colors`\nhex('#E0115F').bold.underline('Truecolor')\n```\n\n\u003c!--\n## 🌍 Used by\n\n[NestJS](https://github.com/nestjs/nest), [Sequelize](https://github.com/sequelize/sequelize), [TypeORM](https://github.com/typeorm/typeorm), [Salesforce](https://github.com/salesforcecli/cli), [Oclif](https://github.com/oclif/core)\n--\u003e\n\n\u003ca id=\"alternatives\" name=\"alternatives\"\u003e\u003c/a\u003e\n\n## ⚖️ Alternatives\n\nThe most popular ANSI libraries, similar to Ansis:\n\n[chalk][chalk], [picocolors][picocolors], [colorette][colorette], [kleur][kleur], [ansi-colors][ansi-colors], [kolorist][kolorist], [cli-color][cli-color], [colors-cli][colors-cli], [colors.js][colors.js], [tinyrainbow][tinyrainbow]\n\n\n✅ [Compare features](#compare) 🧩 [Handling edge cases](#handling-input-arguments) 📦 [Compare package sizes](#compare-size) 📊 [Benchmarks](#benchmark)\n\n\n\u003ca id=\"why-ansis\" name=\"why-ansis\"\u003e\u003c/a\u003e\n\n## ✨ [Why use Ansis](#switch-to-ansis)\n\nAs of 2025, two of the [smallest](#compare-size) and [fastest](#benchmark) ANSI libraries are **Ansis** and **Picocolors**.\nBoth are [recommended](https://github.com/es-tooling/module-replacements/blob/main/docs/modules/chalk.md) by the [ES Tooling](https://github.com/es-tooling) community as modern replacements for older, larger libraries.\n\n\n### 📦 Unpacked size\n\nThe package size in `node_modules` directory:\n\n- `picocolors`: [6.4 kB][npm-picocolors] (not minimized) - A micro library with basic features.\n- `аnsis`: [6.8 kB][npm-ansis] (minimized) - A powerful library containing all the features you need.\n- `chalk`:  [44.2 kB][npm-chalk] (not minimized) - Provides similar functionality to Ansis.\n\n### ⚡ Performance\n\n- `picocolors`: The [fastest](#bench-simple) when applying a single style (e.g., `red`) only.\n- `аnsis`: The [fastest](#bench-2-styles) when applying two or more styles (e.g., `red` + `bgWhite`).\n- `chalk`: Slower than both **Ansis** and **Picocolors** in all use cases.\n\n\u003e [!CAUTION]\n\u003e **Picocolors** doesn't handle important **edge cases**, so it is the fastest and smallest.\n\u003e\n\u003e **Picocolors** is faster only in a [simple](#bench-simple) micro-benchmark, which does not reflect real world usage.\\\n\u003e In a more complex benchmark, **Ansis** is much [closer](#bench-picocolors-complex) to **Picocolors** results or even [faster](#bench-3-styles).\n\n\u003ca id=\"edge-cases\" name=\"edge-cases\"\u003e\u003c/a\u003e\n### 🧩 Edge cases\n\n#### Absent, `undefined` or `null` arguments\n\n**Ansis** handles these cases correctly.\n\n```js\nansis.red()          // ✅ ''\nchalk.red()          // ✅ ''\npico.red()           // ❌ \\e[31mundefined\\e[39m\n\nansis.red(undefined) // ✅ ''\nchalk.red(undefined) // ❌ \\e[31mundefined\\e[39m\npico.red(undefined)  // ❌ \\e[31mundefined\\e[39m\n\nansis.red(null)      // ✅ ''\nchalk.red(null)      // ❌ \\e[31mnull\\e[39m\npico.red(null)       // ❌ \\e[31mnull\\e[39m\n\nansis.reset()        // ✅ \\e[0m\nchalk.reset()        // ❌ ''\npico.reset()         // ❌ \\e[0mundefined\\e[0m\n```\n\nSee more details about [handling input arguments](#handling-input-arguments) in various libraries.\n\n#### Empty string\n\n**Ansis** and **Chalk** handle this case and return an empty string without ANSI codes as expected.\\\nHowever, **Picocolors** doesn't handle this case.\n\n```js\nansis.red('')          // ✅ ''\nchalk.red('')          // ✅ ''\npico.red('')           // ❌ \\e[31m\\e[39m\n```\n\n#### Break style at New Line\n\n**Ansis** and **Chalk** add a style break at each `new line` to correctly display multi-line text.\\\nHowever, **Picocolors** doesn't handle this case.\n\n```js\nansis.bgRed('\\n ERROR \\n') + ansis.cyan('The file not found!') // ✅\nchalk.bgRed('\\n ERROR \\n') + chalk.cyan('The file not found!') // ✅\npico.bgRed('\\n ERROR \\n') + pico.cyan('The file not found!')   // ❌\n```\n\n![Break style at New Line](docs/img/break-line-compare.png)\n\n\n#### Nested template strings\n\nOnly **Ansis** handles this very useful use case.\n\n```js\nansis.red`R ${ansis.green`G ${ansis.blue`B`} G`} R` // ✅\nchalk.red`R ${chalk.green`G ${chalk.blue`B`} G`} R` // ❌\npico.red`R ${pico.green`G ${pico.blue`B`} G`} R`    // ❌\n```\n\n![Nested template strings](docs/img/nested-template-strings-compare.png)\n\n\n### 🔧 Maintenance\n\nAs of 2025, only **Ansis**, **Chalk**, and **Picocolors** are actively maintained, unlike many other libraries:\n\n- `colorette`: Last updated [2 years ago][npm-colorette]\n- `ansi-colors`: Last updated [3 years ago][npm-ansi-colors]\n- `kleur`: Last updated [3 years ago][npm-kleur]\n- `colors.js`: Last updated [2 years ago][npm-colors.js]\n- `cli-color`: Last updated [1 year ago][npm-cli-color]\n- `colors-cli`: Last updated [1 year ago][npm-colors-cli]\n\n\n\u003ca id=\"checklist-lib-choice\" name=\"checklist-lib-choice\"\u003e\u003c/a\u003e\n### 🤔 Which One Should You Use?\n\n- If you only use a single style, e.g., `red('foo')`, **Picocolors** is the best solution.\n\n- However, if you need more, like combining multiple styles (e.g., `red` + `bold` + `bgWhite`),\\\n  [256 colors](#256-colors), [Truecolor](#truecolor),\n  or support for a wide range of [environments](#color-support),\n  then **Ansis** is the better choice.\n\n#### Checklist:\n\n- Does support for ESM or CJS matter?\n  - ✅ Ansis: `ESM` and `CJS`\n  - ☑️ Picocolors: `CJS` only\n- Does it matter if a library performs [~60 million](#bench-simple) or [~100 million](#bench-simple) **ops/sec** when outputting to the terminal?\n  Spoiler: Both Ansis and Picocolors are more than [fast enough](#bench-picocolors-complex).\n  - ✅ Picocolors\n  - ❌ Ansis\n- Does it matter if the unpacked size is [6.4 kB][npm-picocolors] or [6.8 kB][npm-ansis], a difference of **0.4 kB**?\n  - ✅ Picocolors\n  - ❌ Ansis\n- Does support for [ANSI 256 colors](#256-colors) or [Truecolor](#truecolor) with [fallback](#fallback) matter?\n  - ✅ Ansis\n  - ❌ Picocolors\n- Does handling [edge cases](#handling-input-arguments) matter?\n  - ✅ Ansis\n  - ❌ Picocolors\n- Does supporting a wide range of [environments](#color-support) matter?\n  - ✅ Ansis\n  - ❌ Picocolors\n- Does keeping your code clean and readable matter?\n  - ✅ Ansis ([default and named import](#import), [chained syntax](#chained-syntax), [nested **template strings**](#nested-syntax))\n  - ☑️ Picocolors (default import, nested calls)\n\n\nExplore the list of [features](#compare), [package sizes](#compare-size), and [benchmarks](#benchmark) compared to similar libraries.\n\n\u003e [!TIP]\n\u003e\n\u003e **To keep your code clean and readable:**\n\u003e - Use the chained syntax provided by libraries like `ansis` and `chalk\n\u003e - Avoid nested calls, as they are [much slower](#bench-3-styles) and less readable than the chained syntax.\n\n#### Usage examples\n```js\nimport ansis, { red, green, cyan } from 'ansis' // ✅✅ supports both default and named imports\nimport chalk from 'chalk'                       // ✅❌ doesn't support named import\nimport pico from 'picocolors'                   // ✅❌ doesn't support named import\n\nansis.red('Error')                         //      ansis ❌ slower than picocolors\nchalk.red('Error')                         //      chalk ❌ slower than ansis\npico.red('Error')                          // picocolors ✅ fastest\n\nred.bold.bgWhite`Error`                    //      ansis ✅✅✅ fastest, short, readable\nchalk.red.bold.bgWhite('Error')            //      chalk ❌☑️✅ slower, short, readable\npico.red(pico.bold(pico.bgWhite('Error'))) // picocolors ❌❌❌ slowest, long, unreadable\n\ngreen`Create ${blue.bold`React`} app.`                     //      ansis ✅ usability 😊\nchalk.green(`Create ${chalk.blue.bold('React')} app.`)     //      chalk ☑️ usability 🙂\npico.green(`Create ${pico.blue(pico.bold('React'))} app.`) // picocolors ❌ usability 🥴\n```\n\n\u003e [!TIP]\n\u003e Ansis supports **nested template strings**, so you can colorize text without using parentheses.\n\n## [How to switch to Ansis](#switch-to-ansis)\n\n- [Replacing `chalk`](#replacing-chalk)\n- [Replacing `colorette`](#replacing-colorette)\n- [Replacing `picocolors`](#replacing-picocolors)\n- [Replacing `ansi-colors`](#replacing-ansi-colors)\n- [Replacing `kleur`](#replacing-kleur)\n- [Replacing `cli-color`](#replacing-cli-color)\n\n---\n\n#### [↑ top](#top)\n\n\u003ca id=\"install\" name=\"install\"\u003e\u003c/a\u003e\n\n## Install\n\n```bash\nnpm install ansis\n```\n\n\u003ca id=\"import\" name=\"import\"\u003e\u003c/a\u003e\n## Default and named import\n\n**ESM**\n```js\n// Default import\nimport ansis from 'ansis';\n// Named imports\nimport { red, green, bold, dim } from 'ansis';\n```\n\n**CommonJS**\n```js\n// Default import\nconst ansis = require('ansis');\n// Named imports\nconst { red, green, bold, dim } = require('ansis');\n```\n\n\u003ca id=\"template-literals\" name=\"template-literals\"\u003e\u003c/a\u003e\n\n## Tagged template literals\n\n\u003e [!TIP]\n\u003e Using [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) you can omit parentheses ``` red(`error`) ``` → ``` red`error` ``` to keep your code clean and readable.\n\n```js\nimport { cyan, red } from 'ansis';\n\nlet file = '/path/to/file.txt';\n\nred`Error: File ${cyan(file)} not found!`;\n```\n\n\u003ca id=\"nested-syntax\" name=\"nested-syntax\"\u003e\u003c/a\u003e\n\n## Nested template literals\n\nAnsis correctly renders nested tagged template strings.\n\n```js\nimport { green, red, yellow } from 'ansis';\n\nred`Red ${yellow`Yellow ${green`Green`} Yellow`} Red`;\n\nred`Error: ${yellow`Module ${green`ansis`} is missing!`} Installation required.`;\n```\n\n\u003ca id=\"chained-syntax\" name=\"chained-syntax\"\u003e\u003c/a\u003e\n\n## Chained syntax\n\nAll colors, styles and functions are chainable. Each color or style can be combined in any order.\n\n```js\nimport { red, bold, italic, hex } from 'ansis';\n\nred.bold`text`;\nhex('#FF75D1').bgCyan.bold`text`;\nbold.bgHex('#FF75D1').cyan`text`;\nitalic.bold.yellow.bgMagentaBright`text`;\n```\n\n#### [↑ top](#top)\n\n\u003ca id=\"base-colors\" name=\"base-colors\"\u003e\u003c/a\u003e\n\n## ANSI Styles\n\n`dim` **`bold`** _`italic`_ \u003cu\u003e`underline`\u003c/u\u003e \u003cs\u003e`strikethrough`\u003c/s\u003e `inverse` `visible` `hidden` `reset`\n\n\n## ANSI 16 colors\n\n| Standard Colors  | Bright Colors                                             | Standard Backgrounds | Bright Backgrounds                                              |\n|:-----------------|:----------------------------------------------------------|:---------------------|:----------------------------------------------------------------|\n| `black`          | `blackBright`\u003cbr\u003e_aliases:_\u003cbr\u003e`grey` (UK)\u003cbr\u003e`gray` (US) | `bgBlack`            | `bgBlackBright`\u003cbr\u003e_aliases:_\u003cbr\u003e`bgGrey` (UK)\u003cbr\u003e`bgGray` (US) |\n| `red`            | `redBright`                                               | `bgRed`              | `bgRedBright`                                                   |\n| `green`          | `greenBright`                                             | `bgGreen`            | `bgGreenBright`                                                 |\n| `yellow`         | `yellowBright`                                            | `bgYellow`           | `bgYellowBright`                                                |\n| `blue`           | `blueBright`                                              | `bgBlue`             | `bgBlueBright`                                                  |\n| `magenta`        | `magentaBright`                                           | `bgMagenta`          | `bgMagentaBright`                                               |\n| `cyan`           | `cyanBright`                                              | `bgCyan`             | `bgCyanBright`                                                  |\n| `white`          | `whiteBright`                                             | `bgWhite`            | `bgWhiteBright`                                                 |\n\n\n\u003ca id=\"256-colors\" name=\"256-colors\"\u003e\u003c/a\u003e\n\n## ANSI 256 colors\n\n256 color functions:\n\n- **Foreground:** `ansi256(code)`, _alias_ `fg(code)`\n- **Background:** `bgAnsi256(code)`, _alias_ `bg(code)`\n\n\u003e [!NOTE]\n\u003e The function names `fg(code)` and `bg(code)` are designed for brevity,\n\u003e while `ansi256(code)` and `bgAnsi256(code)` ensure compatibility with Chalk.\n\n256 colors codes:\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/ansis\"\u003e\n    \u003cimg width=\"830\" src=\"https://github.com/webdiscus/ansis/raw/master/docs/img/ansi256.png\" alt=\"ANSI 256 colors\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\nSee [ANSI color codes](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit).\n\n#### Fallback\n\nIf a terminal supports only 16 colors then ANSI 256 colors will be interpolated into base 16 colors.\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/ansis\"\u003e\n    \u003cimg width=\"830\" src=\"https://github.com/webdiscus/ansis/raw/master/docs/img/ansi256-fallback.png\" alt=\"Fallback ANSI 256 colors to 16 colors\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n#### Usage example\n\n```js\nimport { bold, ansi256, fg, bgAnsi256, bg } from 'ansis';\n\n// foreground color\nansi256(96)`Bright Cyan`;\nfg(96)`Bright Cyan`; // alias for ansi256\n\n// background color\nbgAnsi256(105)`Bright Magenta`;\nbg(105)`Bright Magenta`; // alias for bgAnsi256\n\n// function is chainable\nfg(96).bold`bold Bright Cyan`;\n\n// function is avaliable in each style\nbold.fg(96).underline`bold underline Bright Cyan`;\n\n// you can combine the functions and styles in any order\nbg(105).fg(96)`cyan text on magenta background`\n```\n\n\u003ca id=\"truecolor\" name=\"truecolor\"\u003e\u003c/a\u003e\n\n## Truecolor\n\nYou can use the `hex` or `rgb` format.\n\nForeground function: `hex()` `rgb()`\\\nBackground function: `bgHex()` `bgRgb()`\n\n```js\nimport { bold, hex, rgb, bgHex, bgRgb } from 'ansis';\n\n// foreground color\nhex('#E0115F').bold`bold Ruby`;\nhex('#96C')`Amethyst`;\nrgb(224, 17, 95).italic`italic Ruby`;\n\n// background color\nbgHex('#E0115F')`Ruby`;\nbgHex('#96C')`Amethyst`;\nbgRgb(224, 17, 95)`Ruby`;\n\n// you can combine the functions and styles in any order\nbold.hex('#E0115F').bgHex('#96C')`ruby bold text on amethyst background`\n```\n\n#### [↑ top](#top)\n\n\u003ca id=\"fallback\" name=\"fallback\"\u003e\u003c/a\u003e\n\n## Fallback\n\nThe `ansis` supports fallback to supported color space.\n\n```\nTruecolor —\u003e 256 colors —\u003e 16 colors —\u003e no colors (black \u0026 white)\n```\n\nIf you use the `hex()`, `rgb()` or `ansis256()` functions in a terminal not supported Truecolor or 256 colors, then colors will be interpolated.\n\n![output](https://github.com/webdiscus/ansis/raw/master/docs/img/ansis-fallback.png?raw=true \"Fallback to ANSI colors\")\n\n#### [↑ top](#top)\n\n\u003ca id=\"extend-colors\" name=\"extend-colors\"\u003e\u003c/a\u003e\n\n## Extend base colors\n\nDefaults, the imported `ansis` instance contains [base styles and colors](#base-colors).\nTo extend base colors with custom color names for Truecolor use the `ansis.extend()` method.\n\n\u003e [!TIP]\n\u003e You can find a color name by the hex code on the [Name that Color](https://chir.ag/projects/name-that-color/#FF681F) website.\n\nDefine a theme with your custom colors and extends the `ansis` object:\n\n```js\nimport ansis from 'ansis';\n\nconst myTheme = {\n  orange: '#FFAB40',\n  pink: '#FF75D1',\n};\n\n// extend ansis this custom colors\nansis.extend(myTheme);\n\n// you can destruct extended colors\nconst { orange, pink, red } = ansis;\n\n// access to extended colors\nconsole.log(ansis.orange.bold('orange bold'));\nconsole.log(orange.italic`orange italic`);\nconsole.log(pink`pink color`);\n```\n\nUsage example with TypeScript:\n\n```ts\nimport ansis, { AnsiColorsExtend } from 'ansis';\n\nconst myTheme = {\n  orange: '#FFAB40',\n  pink: '#FF75D1',\n};\n\n// extend base colors with your custom theme\nansis.extend(myTheme);\n\n// your custom logger with the support for extended colors\nconst log = (style: AnsiColorsExtend\u003ckeyof typeof myTheme\u003e, message: string) =\u003e {\n  console.log(ansis[style](message));\n}\n\nlog('red', 'message'); // base color OK\nlog('orange', 'message'); // extended color OK\nlog('unknown', 'message'); // TypeScript Error\n```\n\n\u003e [!WARNING]\n\u003e\n\u003e The extended color must be used as a first chain item.\n\u003e\n\u003e ```js\n\u003e ansis.orange.bold('orange bold'); // ✅ works fine\n\u003e ansis.bold.orange('bold orange'); // ❌ extended color as a subchain item doesn't work\n\u003e ```\n\n---\n\n#### [↑ top](#top)\n\n\u003ca id=\"cli-vars\" name=\"cli-vars\"\u003e\u003c/a\u003e\n\n## CLI environment variables\n\nDefaults, the output in terminal console is colored and output in a file is uncolored.\n\nTo force disable or enable colored output you can use environment variables `NO_COLOR` and `FORCE_COLOR`.\n\n\u003ca id=\"using-env-no-color\" name=\"using-env-no-color\"\u003e\u003c/a\u003e\n#### `NO_COLOR`\n\nThe `NO_COLOR` variable should be presents with any not empty value.\nThe value is not important, e.g., `NO_COLOR=1` `NO_COLOR=true` disable colors.\n\nSee the [`NO_COLOR` standard](https://no-color.org/).\n\n\u003ca id=\"using-env-force-color\" name=\"using-env-force-color\"\u003e\u003c/a\u003e\n#### `FORCE_COLOR`\n\nThe `FORCE_COLOR` environment variable is used to enable ANSI colors in the terminal output.\n\nThe proposed [`FORCE_COLOR` standard](https://force-color.org/):\n\n\u003e When `FORCE_COLOR` is present and not an empty string (regardless of its value), it should force enable colors.\n\nBut Node.js supports the `FORCE_COLOR` variable in a different way, see [here](https://nodejs.org/api/cli.html#force_color1-2-3) and [here](https://nodejs.org/api/tty.html#writestreamhascolorscount-env).\n\nAnsis interprets `FORCE_COLOR` in accordance with its support in Node.js, with slight adaptations:\n\n```\nFORCE_COLOR=false   // Disables colors\nFORCE_COLOR=0       // Disables colors\nFORCE_COLOR=true    // Auto detects the supported colors (if no color detected, enforce truecolor)\nFORCE_COLOR=(unset) // Auto detects the supported colors (if no color detected, enforce truecolor)\nFORCE_COLOR=1       // Enables 16 colors\nFORCE_COLOR=2       // Enables 256 colors\nFORCE_COLOR=3       // Enables truecolor\n```\n\n\u003e [!IMPORTANT]\n\u003e Node.js [interprets](https://nodejs.org/api/cli.html#force_color1-2-3) the values `1`, `true` and an empty string `''` (unset value) as enabling 16 colors.\n\u003e\n\u003e Ansis interprets the value `1` as enabling exactly 16 colors.\\\n\u003e The values `true` and an empty string indicate automatic detection of supported colors (16, 256, truecolor).\n\u003e If no color is detected, enforce using truecolor.\n\n\nSee:\n- [`FORCE_COLOR` standard](https://force-color.org/)\n- [Node.js getColorDepth](https://nodejs.org/api/tty.html#writestreamhascolorscount-env)\n- [Node.js FORCE_COLOR=[1, 2, 3]](https://nodejs.org/api/cli.html#force_color1-2-3)\n\nFor example, _app.js_:\n\n```js\nimport { red } from 'ansis';\n\nconsole.log(red`red color`);\n```\n\nExecute the script in a terminal:\n\n```\nnode app.js           # colored output in terminal\nnode app.js \u003e log.txt # output in file without ANSI codes\n\nNO_COLOR=1 node app.js              # force disable colors\nFORCE_COLOR=0 node app.js           # force disable colors\nFORCE_COLOR=1 node app.js \u003e log.txt # force enable 16 colors\nFORCE_COLOR=2 node app.js \u003e log.txt # force enable 256 colors\nFORCE_COLOR=3 node app.js \u003e log.txt # force enable truecolor\n```\n\n\u003ca id=\"using-env-colorterm\" name=\"using-env-colorterm\"\u003e\u003c/a\u003e\n\n#### `COLORTERM`\n\nThe `COLORTERM` environment variable is used by terminal emulators to indicate support for colors.\nIts value can vary depending on the terminal emulator and the level of color support provided.\n\nThe commonly used values supported by `ansis`:\n\n- `truecolor` or `24bit` - 16 million colors\n- `ansi256` - ANSI 256 colors\n- `ansi` - basic ANSI 16 colors\n\nYou can set the variable in cmd before running the Node script:\n\n```\nCOLORTERM=ansi node script.js      # force enable 16 olors\nCOLORTERM=ansi256 node script.js   # force enable 256 colors\nCOLORTERM=truecolor node script.js # force enable truecolor\n```\n\nTo set the color level in a script, create a JS file in which you define the `COLORTERM` environment variable with the needed value,\nand import this file before `ansis`.\n\nThis can be useful, for example, for testing your cli application to ensure that the test results will be the same\nregardless of the supported color level in different environments and terminals.\n\n#### Force use truecolor\n\n_enable-truecolor.js_\n\n```js\nprocess.env.COLORTERM = 'truecolor';\n```\nyour script file:\n```js\nimport './level-truecolor'; // \u003c= force use truecolor\nimport { red, fg, hex } from 'ansis';\n\nconsole.log(hex('#FFAB40')('orange')); // native ANSI RGB color value\nconsole.log(fg(200)('pink'));          // native ANSI 256 color value\nconsole.log(red('red'));               // native ANSI 16 color value\n```\n\n#### Force use 256 colors\n\n_enable-256colors.js_\n\n```js\nprocess.env.COLORTERM = 'ansi256';\n```\nyour script file:\n```js\nimport './level-256colors'; // \u003c= force use 256 colors\nimport { red, fg, hex } from 'ansis';\n\nconsole.log(hex('#FFAB40')('orange')); // fallback to ANSI 256 color value\nconsole.log(fg(200)('pink'));          // native ANSI 256 color value\nconsole.log(red('red'));               // native ANSI 16 color value\n```\n\n#### Force use base 16 colors\n\n_enable-16colors.js_\n\n```js\nprocess.env.COLORTERM = 'ansi';\n```\nyour script file:\n```js\nimport './level-16colors'; // \u003c= force use 16 olors\nimport { red, fg, hex } from 'ansis';\n\nconsole.log(hex('#FFAB40')('orange')); // fallback to ANSI 16 color value - `bright red`\nconsole.log(fg(200)('pink'));          // fallback to ANSI 16 color value - `bright magenta`\nconsole.log(red('red'));               // native ANSI 16 color value\n```\n\n#### [↑ top](#top)\n\n\u003ca id=\"cli-flags\" name=\"cli-flags\"\u003e\u003c/a\u003e\n\n### CLI arguments\n\nUse cmd arguments `--no-color` to disable colors and `--color` to enable ones.\n\nFor example, an executable script _app.js_:\n\n```js\n#!/usr/bin/env node\nimport { red } from 'ansis';\n\nconsole.log(red`text`);\n```\n\nExecute the script in a terminal:\n\n```\n./app.js                        # colored output in terminal\n./app.js --no-color             # non colored output in terminal\n\n./app.js \u003e log.txt              # output in file without ANSI codes\n./app.js --color \u003e log.txt      # output in file with ANSI codes\n```\n\n\u003e [!NOTE]\n\u003e\n\u003e Command-line arguments take precedence over environment variables.\n\n---\n\n#### [↑ top](#top)\n\n\u003ca id=\"color-support\" name=\"color-support\"\u003e\u003c/a\u003e\n\n## Color support\n\nAnsis automatically detects the supported color space:\n\n- Truecolor\n- ANSI 256 colors\n- ANSI 16 colors\n- black \u0026 white (no colors)\n\nAnsis has the method `isSupported()` that returns a `boolean` value whether the output supports ANSI color and styles.\n\n```js\nimport ansis from 'ansis';\n\nconsole.log('Color output: ', ansis.isSupported());\n```\n\nThere is no standard way to detect which color space is supported.\nThe most common way to detect color support is to check the `TERM` and `COLORTERM` environment variables.\nCI systems can be detected by checking for the existence of the `CI` and other specifically environment variables.\nCombine that with the knowledge about which operating system the program is running on, and we have a decent enough way to detect colors.\n\n| Terminal                         | ANSI 16\u003cbr\u003ecolors | ANSI 256\u003cbr\u003ecolors | True\u003cbr\u003eColor |  env.\u003cbr\u003eTERM   | env.\u003cbr\u003eCOLORTERM | Specifically ENV variables             |\n|:---------------------------------|-------------------|:-------------------|:--------------|:---------------:|:-----------------:|:---------------------------------------|\n| Azure CI                         | ✅                 | ❌                  | ❌             |      dumb       |                   | TF_BUILD\u003cbr\u003eAGENT_NAME                 |\n| GitHub CI                        | ✅                 | ✅                  | ✅             |      dumb       |                   | CI, GITHUB_ACTIONS                     |\n| GitTea CI                        | ✅                 | ✅                  | ✅             |      dumb       |                   | CI, GITEA_ACTIONS                      |\n| GitLab CI                        | ✅                 | ❌                  | ❌             |      dumb       |                   | CI, GITLAB_CI                          |\n| Travis CI                        | ✅                 | ❌                  | ❌             |      dumb       |                   | TRAVIS                                 |\n| PM2\u003cbr\u003enot isTTY                 | ✅[^1]             | ✅[^1]              | ✅[^1]         |      dumb       |                   | PM2_HOME\u003cbr\u003epm_id                      |\n| JetBrains TeamCity\u003cbr\u003e\u003e=2020.1.1 | ✅                 | ✅                  | ❌             |                 |                   | TEAMCITY_VERSION                       |\n| JetBrains IDEA                   | ✅                 | ✅                  | ✅             | xterm-256color  |                   | TERMINAL_EMULATOR='JetBrains-JediTerm' |\n| VS Code                          | ✅                 | ✅                  | ✅             | xterm-256color  |     truecolor     |                                        |\n| Windows\u003cbr\u003eTerminal              | ✅                 | ✅                  | ✅[^2]         |                 |                   |                                        |\n| Windows\u003cbr\u003ePowerShell            | ✅                 | ✅                  | ✅[^2]         |                 |                   |                                        |\n| macOS Terminal                   | ✅                 | ✅                  | ❌             | xterm-256color  |                   |                                        |\n| iTerm                            | ✅                 | ✅                  | ✅             | xterm-256color  |     truecolor     |                                        |\n| Kitty                            | ✅                 | ✅                  | ✅             |   xterm-kitty   |     truecolor     |                                        |\n| KDE Konsole                      | ✅                 | ✅                  | ✅             | xterm-256color  |     truecolor     |                                        |\n\n[^1]: Colors supported depends on actual terminal.\\\n[^2]: The Windows terminal supports true color since Windows 10 revision 14931 (2016-09-21).\n\nSee also:\n\n- [Truecolor Support in Output Devices](https://github.com/termstandard/colors#truecolor-support-in-output-devices).\n- [So you want to render colors in your terminal](https://marvinh.dev/blog/terminal-colors/).\n\n---\n\n#### [↑ top](#top)\n\n\u003ca id=\"compare\" name=\"compare\"\u003e\u003c/a\u003e\n\n## Compare the features of most popular libraries\n\nRun the command to see the support of some features by various libraries:\n\n```\nnpm run compare\n```\n\n[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/compare-colorize-libraries?file=index.js)\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003eLibrary\u003c/th\u003e\n    \u003cth colspan=\"2\"\u003eColors support\u003c/th\u003e\n    \u003cth colspan=\"4\"\u003eFeatures\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003cth style='text-align:left'\u003e\n      \u003cnobr\u003e- \u003ccode\u003eESM\u003c/code\u003e | \u003ccode\u003eCJS\u003c/code\u003e\u003c/nobr\u003e\u003cbr\u003e\n      \u003cnobr\u003e - named import\u003c/nobr\u003e\u003cbr\u003e\n      \u003cnobr\u003e- naming colors\u003c/nobr\u003e\n    \u003c/th\u003e\n    \u003cth\u003e\u003cnobr\u003e16 | 256 | 16m | 🌐\u003c/nobr\u003e\u003c/th\u003e\n    \u003cth\u003eFallback\u003c/th\u003e\n    \u003cth\u003eChained\u003cbr\u003esyntax\u003c/th\u003e\n    \u003cth\u003eNested\u003cbr\u003etemplate\u003cbr\u003estrings\u003cbr\u003e\u003ccode\u003e`${}`\u003c/code\u003e\u003cbr\u003e\u003c/th\u003e\n    \u003cth\u003eLF\u003cbr\u003e\u003ccode\u003e\\n\u003c/code\u003e\u003c/th\u003e\n    \u003cth\u003eSupports\u003cbr\u003eENV vars\u003cbr\u003eCLI flags\u003c/th\u003e\n  \u003c/tr\u003e\n\n  \u003ctr\u003e\n    \u003ctd style='text-align:left'\u003e\n      \u003ca href=\"https://github.com/webdiscus/ansis\"\u003e\u003ccode\u003eansis\u003c/code\u003e\u003c/a\u003e\u003cbr\u003e\n      \u003ccode\u003eESM\u003c/code\u003e \u003ccode\u003eCJS\u003c/code\u003e\u003cbr\u003e\n      \u003cnobr\u003e\u003ccode\u003e✅ named import\u003c/code\u003e\u003c/nobr\u003e\u003cbr\u003e\u003ccode\u003e✅ standard\u003c/code\u003e\n    \u003c/td\u003e\n    \u003ctd style='text-align:center'\u003e✅ ✅ ✅ ✅\u003c/td\u003e\n    \u003ctd style='text-align:left'\u003e→256\u003cbr\u003e→16\u003cbr\u003e→b\u0026amp;w\u003c/td\u003e\n    \u003ctd style='text-align:center'\u003e✅\u003c/td\u003e\n    \u003ctd style='text-align:center'\u003e✅\u003c/td\u003e\n    \u003ctd style='text-align:center'\u003e✅\u003c/td\u003e\n    \u003ctd style=\"text-align:left\"\u003e\u003ccode\u003eNO_COLOR\u003c/code\u003e\u003cbr\u003e\u003ccode\u003eFORCE_COLOR\u003c/code\u003e\u003cbr\u003e\u003ccode\u003eCOLORTERM\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e--no-color\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e--color\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\n  \u003ctr\u003e\n    \u003ctd style=\"text-align:left\"\u003e\u003ca href=\"https://github.com/chalk/chalk\"\u003e\u003ccode\u003echalk v5\u003c/code\u003e\u003c/a\u003e\u003cbr\u003e\u003ccode\u003eESM\u003c/code\u003e\u003cbr\u003e\u003cnobr\u003e\u003ccode\u003e❌ named import\u003c/code\u003e\u003c/nobr\u003e\u003cbr\u003e\u003ccode\u003e✅ standard\u003c/code\u003e\u003c/td\u003e\n    \u003ctd style=\"text-align:center\"\u003e✅ ✅ ✅ ✅\u003c/td\u003e\n    \u003ctd\u003e→256\u003cbr\u003e→16\u003cbr\u003e→b\u0026amp;w\u003c/td\u003e\n    \u003ctd style=\"text-align:center\"\u003e✅\u003c/td\u003e\n    \u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n    \u003ctd style=\"text-align:center\"\u003e✅\u003c/td\u003e\n    \u003ctd style=\"text-align:left\"\u003e\u003ccode\u003eNO_COLOR\u003c/code\u003e\u003cbr\u003e\u003ccode\u003eFORCE_COLOR\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e--no-color\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e--color\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ca href=\"https://github.com/marvinhagemeister/kolorist\"\u003e\u003ccode\u003ekolorist\u003c/code\u003e\u003c/a\u003e\u003cbr\u003e\u003ccode\u003eESM\u003c/code\u003e \u003ccode\u003eCJS\u003c/code\u003e\u003cbr\u003e\u003cnobr\u003e\u003ccode\u003e✅ named import\u003c/code\u003e\u003c/nobr\u003e\u003cbr\u003e\u003ccode\u003e❌ standard\u003c/code\u003e\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e✅ ✅ ✅ ❌\u003c/td\u003e\n\u003ctd\u003e→256\u003cbr\u003e→b\u0026amp;w\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ccode\u003eNO_COLOR\u003c/code\u003e\u003cbr\u003e\u003ccode\u003eFORCE_COLOR\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ca href=\"https://github.com/medikoo/cli-color\"\u003e\u003ccode\u003ecli-color\u003c/code\u003e\u003c/a\u003e\u003cbr\u003e\u003ccode\u003eCJS\u003c/code\u003e\u003cbr\u003e\u003cnobr\u003e\u003ccode\u003e❌ named import\u003c/code\u003e\u003c/nobr\u003e\u003cbr\u003e\u003ccode\u003e✅ standard\u003c/code\u003e\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e✅ ✅ ❌ 🛑\u003c/td\u003e\n\u003ctd\u003e→16\u003cbr\u003e→b\u0026amp;w\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e✅\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ccode\u003eNO_COLOR\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ca href=\"https://github.com/jaywcjlove/colors-cli\"\u003e\u003ccode\u003ecolors-cli\u003c/code\u003e\u003c/a\u003e\u003cbr\u003e\u003ccode\u003eCJS\u003c/code\u003e\u003cbr\u003e\u003cnobr\u003e\u003ccode\u003e❌ named import\u003c/code\u003e\u003c/nobr\u003e\u003cbr\u003e\u003ccode\u003e❌ standard\u003c/code\u003e\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e✅ ✅ ❌ 🛑\u003c/td\u003e\n\u003ctd\u003e→b\u0026amp;w\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e✅\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e✅\u003c/td\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ccode\u003e--no-color\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e--color\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ca href=\"https://github.com/DABH/colors.js\"\u003e\u003ccode\u003ecolors.js\u003c/code\u003e\u003c/a\u003e\u003cbr\u003e\u003ccode\u003eCJS\u003c/code\u003e\u003cbr\u003e\u003cnobr\u003e\u003ccode\u003e❌ named import\u003c/code\u003e\u003c/nobr\u003e\u003cbr\u003e\u003ccode\u003e❌ standard\u003c/code\u003e\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e✅ ❌ ❌ 🛑\u003c/td\u003e\n\u003ctd\u003e→b\u0026amp;w\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e✅\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e✅\u003c/td\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ccode\u003eFORCE_COLOR\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e--no-color\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e--color\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ca href=\"https://github.com/doowb/ansi-colors\"\u003e\u003ccode\u003eansi-colors\u003c/code\u003e\u003c/a\u003e\u003cbr\u003e\u003ccode\u003eCJS\u003c/code\u003e\u003cbr\u003e\u003cnobr\u003e\u003ccode\u003e❌ named import\u003c/code\u003e\u003c/nobr\u003e\u003cbr\u003e\u003ccode\u003e✅ standard\u003c/code\u003e\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e✅ ❌ ❌ ❌\u003c/td\u003e\n\u003ctd\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e✅\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e✅\u003c/td\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ccode\u003eFORCE_COLOR\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ca href=\"https://github.com/jorgebucaran/colorette\"\u003e\u003ccode\u003ecolorette\u003c/code\u003e\u003c/a\u003e\u003cbr\u003e\u003ccode\u003eESM\u003c/code\u003e \u003ccode\u003eCJS\u003c/code\u003e\u003cbr\u003e\u003cnobr\u003e\u003ccode\u003e✅ named import\u003c/code\u003e\u003c/nobr\u003e\u003cbr\u003e\u003ccode\u003e✅ standard\u003c/code\u003e\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e✅ ❌ ❌ 🛑\u003c/td\u003e\n\u003ctd\u003e→b\u0026amp;w\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ccode\u003eNO_COLOR\u003c/code\u003e\u003cbr\u003e\u003ccode\u003eFORCE_COLOR\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e--no-color\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e--color\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ca href=\"https://github.com/alexeyraspopov/picocolors\"\u003e\u003ccode\u003epicocolors\u003c/code\u003e\u003c/a\u003e\u003cbr\u003e\u003ccode\u003eCJS\u003c/code\u003e\u003cbr\u003e\u003cnobr\u003e\u003ccode\u003e❌ named import\u003c/code\u003e\u003c/nobr\u003e\u003cbr\u003e\u003ccode\u003e✅ standard\u003c/code\u003e\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e✅ ❌ ❌ ❌\u003c/td\u003e\n\u003ctd\u003e→b\u0026amp;w\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ccode\u003eNO_COLOR\u003c/code\u003e\u003cbr\u003e\u003ccode\u003eFORCE_COLOR\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e--no-color\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e--color\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ca href=\"https://github.com/tinylibs/tinyrainbow\"\u003e\u003ccode\u003etinyrainbow\u003c/code\u003e\u003c/a\u003e\u003cbr\u003e\u003ccode\u003eESM\u003c/code\u003e\u003cbr\u003e\u003cnobr\u003e\u003ccode\u003e❌ named import\u003c/code\u003e\u003c/nobr\u003e\u003cbr\u003e\u003ccode\u003e✅ standard\u003c/code\u003e\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e✅ ❌ ❌ ✅\u003c/td\u003e\n\u003ctd\u003e→b\u0026amp;w\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ccode\u003eNO_COLOR\u003c/code\u003e\u003cbr\u003e\u003ccode\u003eFORCE_COLOR\u003c/code\u003e\u003cbr\u003e\u003ccode\u003eFORCE_TTY\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e--no-color\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e--color\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ca href=\"https://github.com/lukeed/kleur\"\u003e\u003ccode\u003ekleur\u003c/code\u003e\u003c/a\u003e\u003cbr\u003e\u003ccode\u003eESM\u003c/code\u003e \u003ccode\u003eCJS\u003c/code\u003e\u003cbr\u003e\u003cnobr\u003e\u003ccode\u003e✅ named import\u003c/code\u003e\u003c/nobr\u003e\u003cbr\u003e\u003ccode\u003e✅ standard\u003c/code\u003e\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌ ❌ ❌ ✅\u003cbr\u003e\u003ccode\u003e8\u003c/code\u003e colors\u003c/td\u003e\n\u003ctd\u003e→b\u0026amp;w\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e✅\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:center\"\u003e❌\u003c/td\u003e\n\u003ctd style=\"text-align:left\"\u003e\u003ccode\u003eNO_COLOR\u003c/code\u003e\u003cbr\u003e\u003ccode\u003eFORCE_COLOR\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003c/table\u003e\n\n\n### Notes\n\n**Named import**\\\nESM\\\n`import { red, green, blue } from 'lib';`\\\nCJS\\\n`const { red, green, blue } = require('lib');`\n\n**Naming colors**\n - standard: colors have [standard names](#base-colors-and-styles), e.g.: `red`, `redBright`, `bgRed`, `bgRedBright`\n - _non-standard_: colors have lib-specific names, e.g.: `brightRed`, `bgBrightRed`, `red_b`, `red_btt`\n\n#### Colors support\n\n- `16` - [ANSI 16 colors](#base-colors) like `red`, `redBright`, `bgRed`, `bgRedBright`\n\n- `256` - [ANSI 256 colors](#256-colors) methods, e.g.:\n  - [`ansis`][ansis]: `ansi256(n)`, `bgAnsi256(n)`, aliases - `fg(n)`, `bg(n)`\n  - [`chalk`][chalk]: `ansi256(n)`, `bgAnsi256(n)`\n  - [`cli-color`][cli-color]: `xterm(n)`\n  - [`colors-cli`][colors-cli]: `x\u003cn\u003e`\n\n- `16m` - [Truecolor](#truecolor) methods, e.g.: `hex()`, `bgHex()`, `rgb()`, `bgRgb()`\n\n- 🌐 - Colored output in [Chromium-based](#browsers-compatibility) browser console:\n  - ✅ - colored output\n  - ❌ - b\u0026w output\n  - 🛑 - **fatal error** by compilation or in runtime\n\n- [Fallback](#fallback) - Truecolor → 256 colors → 16 colors → no colors\n\n#### Features\n\n- **Chained syntax**\\\n  `lib.red.bold('text')`\n\n- **Nested template strings**\\\n  ``` lib.red`text ${lib.cyan`nested`} text` ```\n\n- `LF` - **Correct break styles** at `end-of-line` (`\\n`).\n  ```js\n  console.log(bgGreen('\\nAnsis\\nNew Line\\nNext New Line\\n'))\n  ```\n  Outputs:\\\n  ![output](docs/img/break-style-nl.png?raw=true \"break styles at EOL\")\n\n\u003ca id=\"handling-input-arguments\" name=\"handling-input-arguments\"\u003e\u003c/a\u003e\n\n### Edge cases: input arguments\n\nCompare how different libraries handle various input arguments in their functions.\n\n| Library                        | `c.reset()`  | `c.red()`      | `c.red(undefined)` | `c.red(null)` | `c.red('')` |\n|--------------------------------|--------------|----------------|--------------------|---------------|-------------|\n| [`ansis`][ansis]               | ✅`\\e[0m`     | ✅`''`          | ✅`''`              | ✅`''`         | ✅`''`       |\n| [`chalk`][chalk]               | ❌`''`        | ✅`''`          | ❌`'undefined'`     | ❌`'null'`     | ✅`''`       |\n| [`picocolors`][picocolors]     | ❌`undefined` | ❌`'undefined'` | ❌`'undefined'`     | ❌`'null'`     | ❌`'ESC'`    |\n| [`tinyrainbow`][tinyrainbow]   | ❌`undefined` | ❌`'undefined'` | ❌`'undefined'`     | ❌`'null'`     | ❌`'ESC'`    |\n| [`colorette`][colorette]       | ❌`''`        | ✅`''`          | ✅`''`              | ❌`'null'`     | ✅`''`       |\n| [`kleur`][kleur]               | ❌`[object]`  | ❌`[object]`    | ❌`[object]`        | ❌`'null'`     | ❌`'ESC'`    |\n| [`ansi-colors`][ansi-colors]   | ❌`''`        | ✅`''`          | ✅`''`              | ✅`''`         | ✅`''`       |\n| [`kolorist`][kolorist]         | ❌`undefined` | ❌`'undefined'` | ❌`'undefined'`     | ❌`'null'`     | ❌`'ESC'`    |\n| [`colors.js`][colors.js]       | ❌`''`        | ✅`''`          | ❌`'undefined'`     | ❌`'null'`     | ✅`''`       |\n| [`cli-color`][cli-color]       | ❌`-`         | ❌`'ESC'`       | ❌`'ESC'`           | ❌`'ESC'`      | ❌`'ESC'`    |\n| [`colors-cli`][colors-cli]     | ❌`-`         | ❌ `Error`      | ❌`'undefined'`     | ❌`'null'`     | ❌`'ESC'`    |\n\n#### Legend:\n\n- ✅`''` - Returns an _empty string_ without ANSI escape codes. This is the correct and expected behavior.\n- ✅`\\e[0m` - Returns the reset escape code.\n- ❌`'ESC'` - Returns an _empty string_ **containing** ANSI escape codes, e.g., `\\e[31m\\e[39m`.\n- ❌`'undefined'` - Returns the styled string `undefined`.\n- ❌`'null'` - Returns the styled string `null`.\n- ❌`[object]` - Returns an object of the library instance.\n- ❌`-` - The feature is not supported.\n- ❌`Error` - Causes a fatal error.\n\nOther arguments are correctly handled by all libraries:\n```js\nc.red(0)       // '0' in red\nc.red(false)   // 'false' in red\nc.red(true)    // 'true' in red\nc.red(5/'1px') // 'NaN' in red\nc.red(1/0)     // 'Infinity' in red\n```\n\n**Ansis** ensures consistent and predictable behavior for edge-case inputs, making it a reliable choice for usage.\n\n\n#### [↑ top](#top)\n\n\u003ca id=\"compare-size\" name=\"compare-size\"\u003e\u003c/a\u003e\n\n## Compare the size of most popular packages\n\n| Npm package                    |          Dependencies          | Is Minified         |                                            Unpacked Size |                                                              Tarball size |\n| :----------------------------- |:------------------------------:|---------------------|---------------------------------------------------------:|--------------------------------------------------------------------------:|\n| [`picocolors`][picocolors]     |      [0][npm-picocolors]       | no                  |                                 [6.4 kB][npm-picocolors] |           [2.6 kB](https://arve0.github.io/npm-download-size/#picocolors) |\n| [`ansis`][ansis]               |         [0][npm-ansis]         | uglified \u0026 minified |                                      [6.8 kB][npm-ansis] |                [3.6 kB](https://arve0.github.io/npm-download-size/#ansis) |\n| [`tinyrainbow`][tinyrainbow]   |   [0][npm-tinyrainbow]         | uglified            |                                [8.1 kB][npm-tinyrainbow] |          [3.2 kB](https://arve0.github.io/npm-download-size/#tinyrainbow) |\n| [`colorette`][colorette]       |       [0][npm-colorette]       | no                  |                                 [17.0 kB][npm-colorette] |            [4.9 kB](https://arve0.github.io/npm-download-size/#colorette) |\n| [`kleur`][kleur]               |         [0][npm-kleur]         | no                  |                                     [20.3 kB][npm-kleur] |                [6.0 kB](https://arve0.github.io/npm-download-size/#kleur) |\n| [`ansi-colors`][ansi-colors]   |      [0][npm-ansi-colors]      | no                  |                               [26.1 kB][npm-ansi-colors] |          [8.5 kB](https://arve0.github.io/npm-download-size/#ansi-colors) |\n| [`kolorist`][kolorist]         |       [0][npm-kolorist]        | no                  |                                  [51.0 kB][npm-kolorist] |             [8.7 kB](https://arve0.github.io/npm-download-size/#kolorist) |\n| [`colors.js`][colors.js]       |       [0][npm-colors.js]       | no                  |                                 [41.5 kB][npm-colors.js] |    [11.1 kB](https://arve0.github.io/npm-download-size/#@colors%2fcolors) |\n| [`chalk`][chalk]               |         [0][npm-chalk]         | no                  |                                     [43.7 kB][npm-chalk] |               [13.4 kB](https://arve0.github.io/npm-download-size/#chalk) |\n| [`cli-color`][cli-color]       |      [`5`][npm-cli-color]      | no                  | [754.0 kB](https://packagephobia.com/result?p=cli-color) |          [216.8 kB](https://arve0.github.io/npm-download-size/#cli-color) |\n| [`colors-cli`][colors-cli]     |      [0][npm-colors-cli]       | no                  |                               [511.0 kB][npm-colors-cli] |         [361.7 kB](https://arve0.github.io/npm-download-size/#colors-cli) |\n\n**Legend**\n\n- **Dependencies:** Number of dependencies in the package.\n- **Is Minified:** Indicates whether the distributed npm package is minified.\n- **Unpacked Size:** The size of the npm package in the `node_modules/` directory, (incl. dependencies).\n- **Tarball size:** The size of the downloaded `*.tgz` package file.\\\n  You can check the package size with the following command:\n  ```bash\n  curl -s -o package.tgz $(npm view \u003cpackage-name\u003e dist.tarball) \u0026\u0026 echo \"Tarball size: $(stat -f%z package.tgz | awk '{printf \"%.2f\", $1/1024}') kB\"\n  ```\n  just replace the `\u003cpackage-name\u003e` with your package name.\n\n**See also:**\n\n- [npmjs](https://www.npmjs.com/package) - show install size of the published package, w/o dependencies\n- [packagephobia](https://packagephobia.com) - show total install size, incl. dependencies\n- [npm download size](https://arve0.github.io/npm-download-size) - show download size\n- [pkg-size](https://pkg-size.dev) - find the true size of an npm package\n- [bundlephobia](https://bundlephobia.com) - useless, doesn't show real tarball size of the downloaded npm package\n\n---\n\n\n## Show ANSI demo\n\n```bash\ngit clone https://github.com/webdiscus/ansis.git\ncd ./ansis\nnpm i\nnpm run demo\n```\n\n#### [↑ top](#top)\n\u003ca id=\"compatibility\" name=\"compatibility\"\u003e\u003c/a\u003e\n\n## Compatibility Check\n\nCheck the minimum version of your tool required for compatibility with the latest Ansis.\n\n| Tool              | Version   | Compatibility | Supports |\n|-------------------|-----------|---------------|----------|\n| **Node.js**       | **v14+**  | ✅ Full support | CJS, ESM |\n| **TypeScript/tsc**| **v5.0+** | ✅ Full support | CJS, ESM |\n| **esbuild**       | **v0.8+** | ✅ Full support | CJS, ESM |\n| **swc**           | **v1.2+** | ✅ Full support | CJS, ESM, FAUX |\n| **tsup**          | **v4.0+** | ✅ Full support | CJS, ESM, FAUX |\n| **tsx**           | **v3.0+** | ✅ Full support | CJS, ESM |\n| **Rollup**        | **v2.0+** | ✅ Full support | CJS, ESM |\n| **Vite**          | **v2.5+** | ✅ Full support | ESM |\n| **Turbo**         | **v1.0+** | ✅ Full support | CJS, ESM |\n| **Webpack**       | **v5.0+** | ✅ Full support | CJS, ESM |\n\n**Supports:**\n- **CJS**: CommonJS module support.\n- **ESM**: ECMAScript module support.\n- **FAUX**: Fake or non-standard approach to module resolution (seen in **swc**).\n\n\u003ca id=\"browsers-compatibility\" name=\"browsers-compatibility\"\u003e\u003c/a\u003e\n\n### Browser Compatibility for ANSI Codes\n\n| Browser           | Version       | Colors Supported   |\n|-------------------|---------------|--------------------|\n| **Chrome**        | **v20+**      | TrueColor (16M)    |\n| **Safari**        | **v10+**      | TrueColor (16M)    |\n| **Edge**          | **v12+**      | TrueColor (16M)    |\n| **Opera**         | **v12+**      | TrueColor (16M)    |\n| **Brave**         | **v1.0+**     | TrueColor (16M)    |\n| **Vivaldi**       | **v1.0+**     | TrueColor (16M)    |\n\n\u003e [!WARNING]\n\u003e **Firefox** doesn't natively support ANSI codes in the developer console.\n\n#### [↑ top](#top)\n\u003ca id=\"benchmark\" name=\"benchmark\"\u003e\u003c/a\u003e\n\n## Benchmarks\n\n\u003e [!CAUTION]\n\u003e The benchmark results are meaningless numbers intended purely to promote the library and increase its popularity.\n\u003e All libraries are more than fast enough.\n\u003e These results only to show the effectiveness of micro-optimizations in the code, which does not impact on real-world usage.\n\u003e\n\u003e Of course **Picocolors** will be a little bit faster in a micro-benchmark since it has less code and doesn't handles [edge cases](#.handling-input-arguments).\n\u003e\n\u003e _Taken from the [comment](https://github.com/babel/babel/pull/13783#issuecomment-927317201) by the creator of Chalk._\n\nTo measure performance is used [benchmark.js](https://github.com/bestiejs/benchmark.js).\n\n\u003e [!WARNING]\n\u003e\n\u003e Results of [vitest benchmark](https://vitest.dev/config/#benchmark) are incorrect.\n\u003e\n\u003e The `vitest benchmark` generate **unreal** results.\\\n\u003e For example, the results of the simple bench:\n\u003e ```\n\u003e chalk.red('foo') -  7.000.000 ops/sec\n\u003e ansis.red('foo') - 23.000.000 ops/sec (x3 faster is incorrect result)\n\u003e ```\n\u003e\n\u003e The actual performance results of Chalk and Ansis in this test are very similar.\n\n### Run benchmarks\n\n```bash\ngit clone https://github.com/webdiscus/ansis.git\ncd ./ansis\nnpm i\nnpm run build\nnpm run bench\n```\n\n\u003e ### Tested on\n\u003e\n\u003e MacBook Pro 16\" M1 Max 64GB\\\n\u003e macOS Sequoia 15.1\\\n\u003e Node.js v22.11.0\\\n\u003e Terminal `iTerm2` v3.5.0\n\n---\n\n\u003e [!IMPORTANT]\n\u003e\n\u003e Each library uses the recommended **fastest** styling method to compare the **absolute performance**.\n\u003e\n\u003e In real practice, no one would use the **slowest** method (such as nested calls) to style a string when the library provides a **faster** and a **shorter** chained method.\n\u003e\n\u003e For example:\n\u003e\n\u003e ```js\n\u003e lib.red.bold.bgWhite(' ERROR ')           // ✅ faster, shorter, readable\n\u003e lib.red(lib.bold(lib.bgWhite(' ERROR '))) // ❌ slower, longer, unreadable\n\u003e ```\n\n\u003ca id=\"bench-simple\" name=\"bench-simple\"\u003e\u003c/a\u003e\n### Simple bench\n\nThe simple test uses only single style.\nPicocolors, Colorette and Kleur do not support [chained syntax](#chained-syntax) or [correct style break](#new-line) (wenn used ``` `\\n` ``` in a string),\nso they are the fastest in this simple use case. _No function, no performance overhead_.\n\n```js\nansis.red('foo')\nchalk.red('foo')\npicocolors.red('foo')\n...\n```\n\n```diff\n+  picocolors@1.1.1    109.212.939 ops/sec\n   colorette@2.0.20    108.044.800 ops/sec\n   kleur@4.1.5          87.800.739 ops/sec\n-\u003e ansis@3.5.0          60.606.043 ops/sec  -44.5%\n-  chalk@5.3.0          55.702.479 ops/sec  -48.9%\n   kolorist@1.8.0       37.069.069 ops/sec\n   ansi-colors@4.1.3    14.364.378 ops/sec\n   colors@1.4.0          7.060.583 ops/sec\n   cli-color@2.0.4       2.753.751 ops/sec\n   colors-cli@1.0.33       897.746 ops/sec\n```\n\n\u003ca id=\"bench-2-styles\" name=\"bench-2-styles\"\u003e\u003c/a\u003e\n### Using 2 styles\n\nUsing only 2 styles, picocolors is already a bit slower, because using the [chained syntax](#chained-syntax) is faster than nested calls.\n\n```js\nansis.red.bold('foo')\nchalk.red.bold('foo')\npicocolors.red(picocolors.bold('foo')) // chained syntax is not supported\n...\n```\n\n```diff\n+  ansis@3.5.0          60.468.181 ops/sec\n-  picocolors@1.1.1     58.777.183 ops/sec    -2.8%\n-  chalk@5.3.0          47.789.020 ops/sec   -21.5%\n   colorette@2.0.20     33.387.988 ops/sec\n   kolorist@1.8.0       13.420.047 ops/sec\n   kleur@4.1.5           5.972.681 ops/sec\n   ansi-colors@4.1.3     4.086.412 ops/sec\n   colors@1.4.0          3.018.244 ops/sec\n   cli-color@2.0.4       1.817.039 ops/sec\n   colors-cli@1.0.33       695.601 ops/sec\n```\n\n\u003ca id=\"bench-3-styles\" name=\"bench-3-styles\"\u003e\u003c/a\u003e\n### Using 3 styles\n\nUsing 3 styles, picocolors is 2x slower than ansis.\n\n```js\nansis.red.bold.bgWhite('foo')\nchalk.red.bold.bgWhite('foo')\npicocolors.red(picocolors.bold(picocolors.bgWhite('foo'))) // chained syntax is not supported\n...\n```\n\n```diff\n+  ansis@3.5.0          59.463.640 ops/sec\n-  chalk@5.3.0          42.166.783 ops/sec  -29.0%\n-  picocolors@1.1.1     32.434.017 ops/sec  -45.5% (~2x slower than Ansis)\n   colorette@2.0.20     13.008.117 ops/sec\n   kolorist@1.8.0        5.608.244 ops/sec\n   kleur@4.1.5           5.268.630 ops/sec\n   ansi-colors@4.1.3     2.145.517 ops/sec\n   colors@1.4.0          1.686.728 ops/sec\n   cli-color@2.0.4       1.453.611 ops/sec\n   colors-cli@1.0.33       590.467 ops/sec\n```\n\n\u003ca id=\"bench-4-styles\" name=\"bench-4-styles\"\u003e\u003c/a\u003e\n### Using 4 styles\n\nIn rare cases, when using 4 styles, picocolors becomes 3.4x slower than ansis.\n\n```js\nansis.red.bold.underline.bgWhite('foo')\nchalk.red.bold.underline.bgWhite('foo')\npicocolors.red(picocolors.bold(picocolors.underline(picocolors.bgWhite('foo')))) // chained syntax is not supported\n...\n```\n\n```diff\n+  ansis@3.5.0          59.104.535 ops/sec\n-  chalk@5.3.0          36.147.547 ops/sec  -38.8%\n-  picocolors@1.1.1     17.581.709 ops/sec  -70.2% (~3x slower than Ansis)\n   colorette@2.0.20      7.981.171 ops/sec\n   kleur@4.1.5           4.825.665 ops/sec\n   kolorist@1.8.0        3.729.880 ops/sec\n   ansi-colors@4.1.3     1.514.053 ops/sec\n   colors@1.4.0          1.229.999 ops/sec\n   cli-color@2.0.4       1.210.931 ops/sec\n   colors-cli@1.0.33       481.073 ops/sec\n```\n\n### Deeply nested styles\n\nThe complex test with deeply nested single styles.\n\n```js\nc.green(\n  `green ${c.cyan(\n    `cyan ${c.red(\n      `red ${c.yellow(\n        `yellow ${c.blue(\n          `blue ${c.magenta(`magenta ${c.underline(`underline ${c.italic(`italic`)} underline`)} magenta`)} blue`,\n        )} yellow`,\n      )} red`,\n    )} cyan`,\n  )} green`,\n)\n```\n\n```diff\n+  colorette@2.0.20      1.110.056 ops/sec\n-  picocolors@1.1.1      1.073.299 ops/sec\n-\u003e ansis@3.5.0             847.246 ops/sec  -23.7%\n   kolorist@1.8.0          847.110 ops/sec\n-  chalk@5.3.0             573.942 ops/sec  -48.3%\n   kleur@4.1.5             471.285 ops/sec\n   colors@1.4.0            439.588 ops/sec\n   ansi-colors@4.1.3       382.862 ops/sec\n   cli-color@2.0.4         213.351 ops/sec\n   colors-cli@1.0.33        41.097 ops/sec\n```\n\n### Colorette bench\n\nThe benchmark used in [`colorette`](https://github.com/jorgebucaran/colorette/blob/main/bench/index.js) for single styles.\n\n```js\nc.red(`${c.bold(`${c.cyan(`${c.yellow('yellow')}cyan`)}`)}red`)\n```\n\n```diff\n+  picocolors@1.1.1      3.861.384 ops/sec\n   colorette@2.0.20      3.815.039 ops/sec\n-\u003e ansis@3.5.0           2.918.269 ops/sec  -24.4%\n   kolorist@1.8.0        2.548.564 ops/sec\n-  chalk@5.3.0           2.502.850 ops/sec  -35.2%\n   kleur@4.1.5           2.229.023 ops/sec\n   ansi-colors@4.1.3     1.426.279 ops/sec\n   colors@1.4.0          1.123.139 ops/sec\n   cli-color@2.0.4         481.708 ops/sec\n   colors-cli@1.0.33       114.570 ops/sec\n```\n\u003ca id=\"bench-picocolors-complex\" name=\"bench-picocolors-complex\"\u003e\u003c/a\u003e\n\n### Picocolors complex bench\n\nThe [`picocolors`](https://github.com/alexeyraspopov/picocolors/blob/main/benchmarks/complex.mjs) benchmark, slightly modified.\nAdded a bit more complexity by applying two styles to the colored word instead of one.\n\n```js\nlet index = 1e8;\nc.red('.') +\nc.yellow('.') +\nc.green('.') +\nc.red.bold(' ERROR ') +\nc.red('Add plugin ' + c.cyan.underline('name') + ' to use time limit with ' + c.cyan(++index));\n```\n\n```diff\n+  picocolors@1.1.1      2.601.559 ops/sec\n-\u003e ansis@3.5.0           2.501.227 ops/sec   -3.8%\n   colorette@2.0.20      2.326.491 ops/sec\n-  chalk@5.3.0           2.129.106 ops/sec  -18.1%\n   kleur@4.1.5           1.780.496 ops/sec\n   kolorist@1.8.0        1.685.703 ops/sec\n   ansi-colors@4.1.3       838.542 ops/sec\n   colors@1.4.0            533.362 ops/sec\n   cli-color@2.0.4         287.558 ops/sec\n   colors-cli@1.0.33        97.463 ops/sec\n```\n\n\u003e [!NOTE]\n\u003e\n\u003e In this test, which is closer to practical use, each library uses the **fastest** styling method available.\n\u003e\n\u003e So, `chalk`, `ansis`, `ansi-colors`, `cli-color`, `colors-cli` and `colors` uses chained method, e.g. `c.red.bold(' ERROR ')`.\n\u003e While `picocolors`, `colorette` and `kolorist` uses nested calls, e.g. `c.red(c.bold(' ERROR '))`, because doesn't support the chained syntax.\n\n\n---\n\n#### [↑ top](#top)\n\n\u003ca id=\"switch-to-ansis\" name=\"switch-to-ansis\"\u003e\u003c/a\u003e\n\n## How to switch to Ansis\n\nAnsis is a powerful, small, and fast replacement that requires **no code migration** for many similar libraries.\\\nJust replace your `import ... from ...` or `require(...)` to `ansis`.\n\n\u003ca id=\"replacing-chalk\" name=\"replacing-chalk\"\u003e\u003c/a\u003e\n\n### Drop-in replacement for [chalk], no migration required\n\n```diff\n- import chalk from 'chalk';\n+ import chalk from 'ansis';\n```\n\nAnsis supports the Chalk syntax and is compatible* with [styles and color names](https://github.com/chalk/chalk?tab=readme-ov-file#styles), so you don't need to modify the\noriginal code:\n\n```js\nchalk.red.bold('Error!');\n\n// colorize \"Error: file not found!\"\nchalk.red(`Error: ${chalk.cyan.bold('file')} not found!`);\n\n// ANSI 256 colors\nchalk.ansi256(93)('Violet color');\nchalk.bgAnsi256(194)('Honeydew, more or less');\n\n// truecolor\nchalk.hex('#FFA500').bold('Bold orange color');\nchalk.rgb(123, 45, 67).underline('Underlined reddish color');\nchalk.bgHex('#E0115F')('Ruby');\nchalk.bgHex('#96C')('Amethyst');\n```\n\n\u003e [!WARNING]\n\u003e\n\u003e Ansis doesn't not support the `overline` style, because it's **not widely supported** and no one uses it.\\\n\u003e Check you code and remove the `overline` style:\n\u003e\n\u003e ```diff\n\u003e - chalk.red.overline('text');\n\u003e + chalk.red('text');\n\u003e ```\n\nOptionally, you can rewrite the same code to make it even shorter and cleaner:\n\n```js\nimport { red, cyan, fg, bg, hex, rgb, bgHex, bgRgb } from 'ansis';\n\nred.bold('Error!'); // using parentheses\nred.bold`Error!`;   // using template string\n\n// colorize \"Error: file not found!\"\nred`Error: ${cyan.bold`file`} not found!`;\n\n// ANSI 256 colors\nfg(93)`Violet color`; // alias for ansi256()\nbg(194)`Honeydew, more or less`;  // alias for bgAnsi256()\n\n// truecolor\nhex('#FFA500').bold`Bold orange color`;\nrgb(123, 45, 67).underline`Underlined reddish color`;\nbgHex('#E0115F')`Ruby`;\nbgHex('#96C')`Amethyst`;\n```\n\n#### [↑ top](#top)\n\n\u003ca id=\"replacing-colorette\" name=\"replacing-colorette\"\u003e\u003c/a\u003e\n\n### Drop-in replacement for [colorette], no migration required\n\n```diff\n- import { red, bold, underline } from 'colorette';\n+ import { red, bold, underline } from 'ansis';\n```\n\nAnsis is fully compatible with `colorette` [styles and color names](https://github.com/jorgebucaran/colorette#supported-colors), so you don't need to modify the\noriginal code:\n\n```js\nred.bold('Error!');\nbold(`I'm ${red(`da ba ${underline(\"dee\")} da ba`)} daa`);\n```\n\nOptionally, you can rewrite the same code to make it even shorter and cleaner:\n\n```js\nred.bold`Error!`;\nbold`I'm ${red`da ba ${underline`dee`} da ba`} daa`;\n```\n\n#### [↑ top](#top)\n\n\u003ca id=\"replacing-picocolors\" name=\"replacing-picocolors\"\u003e\u003c/a\u003e\n\n### Drop-in replacement for [picocolors], no migration required\n\n```diff\n- import pico from 'picocolors';\n+ import pico from 'ansis';\n```\n\nAnsis is fully compatible with `picocolors` [styles and color names](https://github.com/alexeyraspopov/picocolors#usage), so you don't need to modify the\noriginal code:\n\n```js\npico.red(pico.bold('text'));\npico.red(pico.bold(variable));\n\n// colorize \"Error: file not found!\"\npico.red('Error: ' + pico.cyan(pico.bold('file')) + ' not found!');\n```\n\nOptionally, you can rewrite the same code to make it even shorter and cleaner:\n\n```js\nimport { red, cyan } from 'ansis';\n\nred.bold`text`;\nred.bold(variable);\n\n// colorize \"Error: file not found!\"\nred`Error: ${cyan.bold`file`} not found!`\n```\n\n#### [↑ top](#top)\n\n\u003ca id=\"replacing-ansi-colors\" name=\"replacing-ansi-colors\"\u003e\u003c/a\u003e\n\n### Drop-in replacement for [ansi-colors], no migration required\n\n```diff\n- const c = require('ansi-colors');\n+ const c = require('ansis');\n```\n\nAnsis is fully compatible with `ansi-color` [styles and color names](https://github.com/doowb/ansi-colors#available-styles), so you don't need to modify the\noriginal code:\n\n```js\nc.red.bold('Error!');\n\n// colorize \"Error: file not found!\"\nc.red(`Error: ${c.cyan.bold('file')} not found!`);\n```\n\nOptionally, you can rewrite the same code to make it even shorter and cleaner:\n\n```js\nimport { red, cyan } from 'ansis';\n\nred.bold('Error!'); // using parentheses\nred.bold`Error!`;   // using template string\n\n// colorize \"Error: file not found!\"\nred`Error: ${cyan.bold`file`} not found!`;\n```\n\n#### [↑ top](#top)\n\n\u003ca id=\"replacing-kleur\" name=\"replacing-kleur\"\u003e\u003c/a\u003e\n\n### Migration from [kleur]\n\n```diff\n- import { red, green, yellow, cyan } from 'kleur';\n+ import { red, green, yellow, cyan } from 'ansis';\n```\n\nAnsis is fully compatible with `kleur` [styles and color names](https://github.com/lukeed/kleur#api),\nbut Kleur `v3.0` no longer uses Chalk-style syntax (magical getter):\n\n```js\ngreen().bold().underline('this is a bold green underlined message');\nyellow(`foo ${red().bold('red')} bar ${cyan('cyan')} baz`);\n```\n\nIf you uses chained methods then it requires a simple code modification.\nJust replace `().` with `.`:\n\n```js\ngreen.bold.underline('this is a bold green underlined message');\nyellow(`foo ${red.bold('red')} bar ${cyan('cyan')} baz`);\n```\n\nOptionally, you can rewrite the same code to make it even shorter and cleaner:\n\n```js\nyellow`foo ${red.bold`red`} bar ${cyan`cyan`} baz`;\n```\n\n#### [↑ top](#top)\n\n\u003ca id=\"replacing-cli-color\" name=\"replacing-cli-color\"\u003e\u003c/a\u003e\n\n### Migration from [cli-color]\n\n```diff\n- const clc = require('cli-color');\n+ const clc = require('ansis');\n```\n\nAnsis is compatible* with `cli-color` [styles and color names](https://github.com/medikoo/cli-color#colors):\n\n```js\nclc.red.bold('Error!');\n\n// colorize \"Error: file not found!\"\nclc.red(`Error: ${c.cyan.bold('file')} not found!`);\n```\n\n\u003e [!WARNING]\n\u003e\n\u003e Ansis doesn't not support the `blink` style, because it's **not widely supported** and no one uses it.\\\n\u003e Check you code and remove the `blink` style:\n\u003e\n\u003e ```diff\n\u003e - clc.red.blink('text');\n\u003e + clc.red('text');\n\u003e ```\n\nIf you use ANSI 256 color functions, replace `xterm` with `fg` and `bgXterm` replace `bg`:\n\n```diff\n- clc.xterm(202).bgXterm(236)('Orange text on dark gray background');\n+ clc.fg(202).bg(236)('Orange text on dark gray background');\n```\n\nOptionally, you can rewrite the same code to make it even shorter and cleaner:\n\n```js\nimport { red, cyan, fg, bg } from 'ansis';\n\nred.bold`Error!`;\n\n// colorize \"Error: file not found!\"\nred`Error: ${cyan.bold`file`} not found!`;\n\nfg(202).bg(236)`Orange text on dark gray background`;\n```\n\n---\n\n#### [↑ top](#top)\n\n## Testing\n\n`npm run test` will run the unit and integration tests.\\\n`npm run test:coverage` will run the tests with coverage.\n\n---\n\n#### [↑ top](#top)\n\n## License\n\n[ISC](https://github.com/webdiscus/ansis/blob/master/LICENSE)\n\n[colors.js]: https://github.com/DABH/colors.js\n\n[colorette]: https://github.com/jorgebucaran/colorette\n\n[picocolors]: https://github.com/alexeyraspopov/picocolors\n\n[cli-color]: https://github.com/medikoo/cli-color\n\n[colors-cli]: https://github.com/jaywcjlove/colors-cli\n\n[ansi-colors]: https://github.com/doowb/ansi-colors\n\n[kleur]: https://github.com/lukeed/kleur\n\n[kolorist]: https://github.com/marvinhagemeister/kolorist\n\n[chalk]: https://github.com/chalk/chalk\n\n[ansis]: https://github.com/webdiscus/ansis\n\n[tinyrainbow]: https://github.com/tinylibs/tinyrainbow\n\n[npm-colors.js]: https://www.npmjs.com/package/@colors/colors\n\n[npm-colorette]: https://www.npmjs.com/package/colorette\n\n[npm-picocolors]: https://www.npmjs.com/package/picocolors\n\n[npm-cli-color]: https://www.npmjs.com/package/cli-color\n\n[npm-colors-cli]: https://www.npmjs.com/package/colors-cli\n\n[npm-ansi-colors]: https://www.npmjs.com/package/ansi-colors\n\n[npm-kleur]: https://www.npmjs.com/package/kleur\n\n[npm-kolorist]: https://www.npmjs.com/package/kolorist\n\n[npm-chalk]: https://www.npmjs.com/package/chalk\n\n[npm-ansis]: https://www.npmjs.com/package/ansis\n\n[npm-tinyrainbow]: https://www.npmjs.com/package/tinyrainbow","funding_links":["https://patreon.com/biodiscus"],"categories":["JavaScript","Utilities","cli"],"sub_categories":["Command Line Interfaces (CLI)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebdiscus%2Fansis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebdiscus%2Fansis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebdiscus%2Fansis/lists"}