{"id":13393641,"url":"https://github.com/lukeed/kleur","last_synced_at":"2025-05-13T21:11:21.509Z","repository":{"id":37719147,"uuid":"140393403","full_name":"lukeed/kleur","owner":"lukeed","description":"The fastest Node.js library for formatting terminal text with ANSI colors~!","archived":false,"fork":false,"pushed_at":"2023-06-07T07:24:18.000Z","size":129,"stargazers_count":1654,"open_issues_count":13,"forks_count":47,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-06T07:05:57.860Z","etag":null,"topics":[],"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/lukeed.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"lukeed"}},"created_at":"2018-07-10T07:22:28.000Z","updated_at":"2025-04-22T09:35:37.000Z","dependencies_parsed_at":"2024-05-10T20:46:15.271Z","dependency_job_id":null,"html_url":"https://github.com/lukeed/kleur","commit_stats":{"total_commits":123,"total_committers":16,"mean_commits":7.6875,"dds":0.1382113821138211,"last_synced_commit":"fa3454483899ddab550d08c18c028e6db1aab0e5"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fkleur","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fkleur/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fkleur/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fkleur/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukeed","download_url":"https://codeload.github.com/lukeed/kleur/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252896169,"owners_count":21821258,"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":[],"created_at":"2024-07-30T17:00:57.816Z","updated_at":"2025-05-13T21:11:16.170Z","avatar_url":"https://github.com/lukeed.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"shots/logo.png\" alt=\"kleur\" height=\"120\" /\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://npmjs.org/package/kleur\"\u003e\n    \u003cimg src=\"https://badgen.now.sh/npm/v/kleur\" alt=\"version\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/lukeed/kleur/actions?query=workflow%3ACI\"\u003e\n    \u003cimg src=\"https://github.com/lukeed/kleur/workflows/CI/badge.svg?event=push\" alt=\"CI\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://npmjs.org/package/kleur\"\u003e\n    \u003cimg src=\"https://badgen.now.sh/npm/dm/kleur\" alt=\"downloads\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://packagephobia.now.sh/result?p=kleur\"\u003e\n    \u003cimg src=\"https://packagephobia.now.sh/badge?p=kleur\" alt=\"install size\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003eThe fastest Node.js library for formatting terminal text with ANSI colors~!\u003c/div\u003e\n\n## Features\n\n* No dependencies\n* Super [lightweight](#load-time) \u0026 [performant](#performance)\n* Supports [nested](#nested-methods) \u0026 [chained](#chained-methods) colors\n* No `String.prototype` modifications\n* Conditional [color support](#conditional-support)\n* [Fully treeshakable](#individual-colors)\n* Familiar [API](#api)\n\n---\n\nAs of `v3.0` the Chalk-style syntax (magical getter) is no longer used.\u003cbr\u003ePlease visit [History](#history) for migration paths supporting that syntax.\n\n---\n\n\n## Install\n\n```\n$ npm install --save kleur\n```\n\n\n## Usage\n\n```js\nimport kleur from 'kleur';\n\n// basic usage\nkleur.red('red text');\n\n// chained methods\nkleur.blue().bold().underline('howdy partner');\n\n// nested methods\nkleur.bold(`${ white().bgRed('[ERROR]') } ${ kleur.red().italic('Something happened')}`);\n```\n\n### Chained Methods\n\n```js\nconst { bold, green } = require('kleur');\n\nconsole.log(bold().red('this is a bold red message'));\nconsole.log(bold().italic('this is a bold italicized message'));\nconsole.log(bold().yellow().bgRed().italic('this is a bold yellow italicized message'));\nconsole.log(green().bold().underline('this is a bold green underlined message'));\n```\n\n\u003cimg src=\"shots/1.png\" width=\"300\" /\u003e\n\n### Nested Methods\n\n```js\nconst { yellow, red, cyan } = require('kleur');\n\nconsole.log(yellow(`foo ${red().bold('red')} bar ${cyan('cyan')} baz`));\nconsole.log(yellow('foo ' + red().bold('red') + ' bar ' + cyan('cyan') + ' baz'));\n```\n\n\u003cimg src=\"shots/2.png\" width=\"300\" /\u003e\n\n\n### Conditional Support\n\nToggle color support as needed; `kleur` includes simple auto-detection which may not cover all cases.\n\n\u003e **Note:** Both `kleur` and `kleur/colors` share the same detection logic.\n\n```js\nimport kleur from 'kleur';\n\n// manually disable\nkleur.enabled = false;\n\n// or use another library to detect support\nkleur.enabled = require('color-support').level \u003e 0;\n\nconsole.log(kleur.red('I will only be colored red if the terminal supports colors'));\n```\n\n\u003e **Important:** \u003cbr\u003eColors will be disabled automatically in non [TTY contexts](https://nodejs.org/api/process.html#process_a_note_on_process_i_o). For example, spawning another process or piping output into another process will disable colorization automatically. To force colors in your piped output, you may do so with the `FORCE_COLOR=1` environment variable:\n\n```sh\n$ node app.js #=\u003e COLORS\n$ node app.js \u003e log.txt  #=\u003e NO COLORS\n$ FORCE_COLOR=1 node app.js \u003e log.txt #=\u003e COLORS\n$ FORCE_COLOR=0 node app.js \u003e log.txt #=\u003e NO COLORS\n```\n\n## API\n\nAny `kleur` method returns a `String` when invoked with input; otherwise chaining is expected.\n\n\u003e It's up to the developer to pass the output to destinations like `console.log`, `process.stdout.write`, etc.\n\nThe methods below are grouped by type for legibility purposes only. They each can be [chained](#chained-methods) or [nested](#nested-methods) with one another.\n\n***Colors:***\n\u003e black \u0026mdash; red \u0026mdash; green \u0026mdash; yellow \u0026mdash; blue \u0026mdash; magenta \u0026mdash; cyan \u0026mdash; white \u0026mdash; gray \u0026mdash; grey\n\n***Backgrounds:***\n\u003e bgBlack \u0026mdash; bgRed \u0026mdash; bgGreen \u0026mdash; bgYellow \u0026mdash; bgBlue \u0026mdash; bgMagenta \u0026mdash; bgCyan \u0026mdash; bgWhite\n\n***Modifiers:***\n\u003e reset \u0026mdash; bold \u0026mdash; dim \u0026mdash; italic* \u0026mdash; underline \u0026mdash; inverse \u0026mdash; hidden \u0026mdash; strikethrough*\n\n\u003csup\u003e* \u003cem\u003eNot widely supported\u003c/em\u003e\u003c/sup\u003e\n\n\n## Individual Colors\n\nWhen you only need a few colors, it doesn't make sense to import _all_ of `kleur` because, as small as it is, `kleur` is not treeshakeable, and so most of its code will be doing nothing. In order to fix this, you can import from the `kleur/colors` submodule which _fully_ supports tree-shaking.\n\nThe caveat with this approach is that color functions **are not** chainable~!\u003cbr\u003eEach function receives and colorizes its input. You may combine colors, backgrounds, and modifiers by nesting function calls within other functions.\n\n```js\n// or: import * as kleur from 'kleur/colors';\nimport { red, underline, bgWhite } from 'kleur/colors';\n\nred('red text');\n//~\u003e kleur.red('red text');\n\nunderline(red('red underlined text'));\n//~\u003e kleur.underline().red('red underlined text');\n\nbgWhite(underline(red('red underlined text w/ white background')));\n//~\u003e kleur.bgWhite().underline().red('red underlined text w/ white background');\n```\n\n\u003e **Note:** All the same [colors, backgrounds, and modifiers](#api) are available.\n\n***Conditional Support***\n\nThe `kleur/colors` submodule also allows you to toggle color support, as needed.\u003cbr\u003e\nIt includes the same initial assumptions as `kleur`, in an attempt to have colors enabled by default.\n\nUnlike `kleur`, this setting exists as `kleur.$.enabled` instead of `kleur.enabled`:\n\n```js\nimport * as kleur from 'kleur/colors';\n// or: import { $, red } from 'kleur/colors';\n\n// manually disabled\nkleur.$.enabled = false;\n\n// or use another library to detect support\nkleur.$.enabled = require('color-support').level \u003e 0;\n\nconsole.log(red('I will only be colored red if the terminal supports colors'));\n```\n\n\n## Benchmarks\n\n\u003e Using Node v10.13.0\n\n### Load time\n\n```\nchalk        :: 5.303ms\nkleur        :: 0.488ms\nkleur/colors :: 0.369ms\nansi-colors  :: 1.504ms\n```\n\n### Performance\n\n```\n# All Colors\n  ansi-colors      x 177,625 ops/sec ±1.47% (92 runs sampled)\n  chalk            x 611,907 ops/sec ±0.20% (92 runs sampled)\n  kleur            x 742,509 ops/sec ±1.47% (93 runs sampled)\n  kleur/colors     x 881,742 ops/sec ±0.19% (98 runs sampled)\n\n# Stacked colors\n  ansi-colors      x  23,331 ops/sec ±1.81% (94 runs sampled)\n  chalk            x 337,178 ops/sec ±0.20% (98 runs sampled)\n  kleur            x  78,299 ops/sec ±1.01% (97 runs sampled)\n  kleur/colors     x 104,431 ops/sec ±0.22% (97 runs sampled)\n\n# Nested colors\n  ansi-colors      x  67,181 ops/sec ±1.15% (92 runs sampled)\n  chalk            x 116,361 ops/sec ±0.63% (94 runs sampled)\n  kleur            x 139,514 ops/sec ±0.76% (95 runs sampled)\n  kleur/colors     x 145,716 ops/sec ±0.97% (97 runs sampled)\n```\n\n\n## History\n\nThis project originally forked [`ansi-colors`](https://github.com/doowb/ansi-colors).\n\nBeginning with `kleur@3.0`, the Chalk-style syntax (magical getter) has been replaced with function calls per key:\n\n```js\n// Old:\nc.red.bold.underline('old');\n\n// New:\nc.red().bold().underline('new');\n```\n\u003e \u003csup\u003e\u003cem\u003eAs I work more with Rust, the newer syntax feels so much better \u0026 more natural!\u003c/em\u003e\u003c/sup\u003e\n\nIf you prefer the old syntax, you may migrate to `ansi-colors` or newer `chalk` releases.\u003cbr\u003eVersions below `kleur@3.0` have been officially deprecated.\n\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","funding_links":["https://github.com/sponsors/lukeed"],"categories":["JavaScript","Repository","Packages","Node.js"],"sub_categories":["Command-line Utilities","CLI","CLI (TTY etc..)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fkleur","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukeed%2Fkleur","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fkleur/lists"}