CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
readme.md298 linesDownload Raw Back to chalk
1<h1 align="center">2	<br>3	<br>4	<img width="320" src="media/logo.svg" alt="Chalk">5	<br>6	<br>7	<br>8</h1>9 10> Terminal string styling done right11 12[![Coverage Status](https://codecov.io/gh/chalk/chalk/branch/main/graph/badge.svg)](https://codecov.io/gh/chalk/chalk)13[![npm dependents](https://badgen.net/npm/dependents/chalk)](https://www.npmjs.com/package/chalk?activeTab=dependents)14[![Downloads](https://badgen.net/npm/dt/chalk)](https://www.npmjs.com/package/chalk)15 16![](media/screenshot.png)17 18## Info19 20- [Why not switch to a smaller coloring package?](https://github.com/chalk/chalk?tab=readme-ov-file#why-not-switch-to-a-smaller-coloring-package)21- See [yoctocolors](https://github.com/sindresorhus/yoctocolors) for a smaller alternative22 23## Highlights24 25- Expressive API26- Highly performant27- No dependencies28- Ability to nest styles29- [256/Truecolor color support](#256-and-truecolor-color-support)30- Auto-detects color support31- Doesn't extend `String.prototype`32- Clean and focused33- Actively maintained34- [Used by ~115,000 packages](https://www.npmjs.com/browse/depended/chalk) as of July 4, 202435 36## Install37 38```sh39npm install chalk40```41 42**IMPORTANT:** Chalk 5 is ESM. If you want to use Chalk with TypeScript or a build tool, you will probably want to use Chalk 4 for now. [Read more.](https://github.com/chalk/chalk/releases/tag/v5.0.0)43 44## Usage45 46```js47import chalk from 'chalk';48 49console.log(chalk.blue('Hello world!'));50```51 52Chalk comes with an easy to use composable API where you just chain and nest the styles you want.53 54```js55import chalk from 'chalk';56 57const log = console.log;58 59// Combine styled and normal strings60log(chalk.blue('Hello') + ' World' + chalk.red('!'));61 62// Compose multiple styles using the chainable API63log(chalk.blue.bgRed.bold('Hello world!'));64 65// Pass in multiple arguments66log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));67 68// Nest styles69log(chalk.red('Hello', chalk.underline.bgBlue('world') + '!'));70 71// Nest styles of the same type even (color, underline, background)72log(chalk.green(73	'I am a green line ' +74	chalk.blue.underline.bold('with a blue substring') +75	' that becomes green again!'76));77 78// ES2015 template literal79log(`80CPU: ${chalk.red('90%')}81RAM: ${chalk.green('40%')}82DISK: ${chalk.yellow('70%')}83`);84 85// Use RGB colors in terminal emulators that support it.86log(chalk.rgb(123, 45, 67).underline('Underlined reddish color'));87log(chalk.hex('#DEADED').bold('Bold gray!'));88```89 90Easily define your own themes:91 92```js93import chalk from 'chalk';94 95const error = chalk.bold.red;96const warning = chalk.hex('#FFA500'); // Orange color97 98console.log(error('Error!'));99console.log(warning('Warning!'));100```101 102Take advantage of console.log [string substitution](https://nodejs.org/docs/latest/api/console.html#console_console_log_data_args):103 104```js105import chalk from 'chalk';106 107const name = 'Sindre';108console.log(chalk.green('Hello %s'), name);109//=> 'Hello Sindre'110```111 112## API113 114### chalk.`<style>[.<style>...](string, [string...])`115 116Example: `chalk.red.bold.underline('Hello', 'world');`117 118Chain [styles](#styles) and call the last one as a method with a string argument. Order doesn't matter, and later styles take precedent in case of a conflict. This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.119 120Multiple arguments will be separated by space.121 122### chalk.level123 124Specifies the level of color support.125 126Color support is automatically detected, but you can override it by setting the `level` property. You should however only do this in your own code as it applies globally to all Chalk consumers.127 128If you need to change this in a reusable module, create a new instance:129 130```js131import {Chalk} from 'chalk';132 133const customChalk = new Chalk({level: 0});134```135 136| Level | Description |137| :---: | :--- |138| `0` | All colors disabled |139| `1` | Basic color support (16 colors) |140| `2` | 256 color support |141| `3` | Truecolor support (16 million colors) |142 143### supportsColor144 145Detect whether the terminal [supports color](https://github.com/chalk/supports-color). Used internally and handled for you, but exposed for convenience.146 147Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, use the environment variable `FORCE_COLOR=1` (level 1), `FORCE_COLOR=2` (level 2), or `FORCE_COLOR=3` (level 3) to forcefully enable color, or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.148 149Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.150 151### chalkStderr and supportsColorStderr152 153`chalkStderr` contains a separate instance configured with color support detected for `stderr` stream instead of `stdout`. Override rules from `supportsColor` apply to this too. `supportsColorStderr` is exposed for convenience.154 155### modifierNames, foregroundColorNames, backgroundColorNames, and colorNames156 157All supported style strings are exposed as an array of strings for convenience. `colorNames` is the combination of `foregroundColorNames` and `backgroundColorNames`.158 159This can be useful if you wrap Chalk and need to validate input:160 161```js162import {modifierNames, foregroundColorNames} from 'chalk';163 164console.log(modifierNames.includes('bold'));165//=> true166 167console.log(foregroundColorNames.includes('pink'));168//=> false169```170 171## Styles172 173### Modifiers174 175- `reset` - Reset the current style.176- `bold` - Make the text bold.177- `dim` - Make the text have lower opacity.178- `italic` - Make the text italic. *(Not widely supported)*179- `underline` - Put a horizontal line below the text. *(Not widely supported)*180- `overline` - Put a horizontal line above the text. *(Not widely supported)*181- `inverse`- Invert background and foreground colors.182- `hidden` - Print the text but make it invisible.183- `strikethrough` - Puts a horizontal line through the center of the text. *(Not widely supported)*184- `visible`- Print the text only when Chalk has a color level above zero. Can be useful for things that are purely cosmetic.185 186### Colors187 188- `black`189- `red`190- `green`191- `yellow`192- `blue`193- `magenta`194- `cyan`195- `white`196- `blackBright` (alias: `gray`, `grey`)197- `redBright`198- `greenBright`199- `yellowBright`200- `blueBright`201- `magentaBright`202- `cyanBright`203- `whiteBright`204 205### Background colors206 207- `bgBlack`208- `bgRed`209- `bgGreen`210- `bgYellow`211- `bgBlue`212- `bgMagenta`213- `bgCyan`214- `bgWhite`215- `bgBlackBright` (alias: `bgGray`, `bgGrey`)216- `bgRedBright`217- `bgGreenBright`218- `bgYellowBright`219- `bgBlueBright`220- `bgMagentaBright`221- `bgCyanBright`222- `bgWhiteBright`223 224## 256 and Truecolor color support225 226Chalk supports 256 colors and [Truecolor](https://github.com/termstandard/colors) (16 million colors) on supported terminal apps.227 228Colors are downsampled from 16 million RGB values to an ANSI color format that is supported by the terminal emulator (or by specifying `{level: n}` as a Chalk option). For example, Chalk configured to run at level 1 (basic color support) will downsample an RGB value of #FF0000 (red) to 31 (ANSI escape for red).229 230Examples:231 232- `chalk.hex('#DEADED').underline('Hello, world!')`233- `chalk.rgb(15, 100, 204).inverse('Hello!')`234 235Background versions of these models are prefixed with `bg` and the first level of the module capitalized (e.g. `hex` for foreground colors and `bgHex` for background colors).236 237- `chalk.bgHex('#DEADED').underline('Hello, world!')`238- `chalk.bgRgb(15, 100, 204).inverse('Hello!')`239 240The following color models can be used:241 242- [`rgb`](https://en.wikipedia.org/wiki/RGB_color_model) - Example: `chalk.rgb(255, 136, 0).bold('Orange!')`243- [`hex`](https://en.wikipedia.org/wiki/Web_colors#Hex_triplet) - Example: `chalk.hex('#FF8800').bold('Orange!')`244- [`ansi256`](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) - Example: `chalk.bgAnsi256(194)('Honeydew, more or less')`245 246## Browser support247 248Since Chrome 69, ANSI escape codes are natively supported in the developer console.249 250## Windows251 252If you're on Windows, do yourself a favor and use [Windows Terminal](https://github.com/microsoft/terminal) instead of `cmd.exe`.253 254## FAQ255 256### Why not switch to a smaller coloring package?257 258Chalk may be larger, but there is a reason for that. It offers a more user-friendly API, well-documented types, supports millions of colors, and covers edge cases that smaller alternatives miss. Chalk is mature, reliable, and built to last.259 260But beyond the technical aspects, there's something more critical: trust and long-term maintenance. I have been active in open source for over a decade, and I'm committed to keeping Chalk maintained. Smaller packages might seem appealing now, but there's no guarantee they will be around for the long term, or that they won't become malicious over time.261 262Chalk is also likely already in your dependency tree (since 100K+ packages depend on it), so switching won’t save space—in fact, it might increase it. npm deduplicates dependencies, so multiple Chalk instances turn into one, but adding another package alongside it will increase your overall size.263 264If the goal is to clean up the ecosystem, switching away from Chalk won’t even make a dent. The real problem lies with packages that have very deep dependency trees (for example, those including a lot of polyfills). Chalk has no dependencies. It's better to focus on impactful changes rather than minor optimizations.265 266If absolute package size is important to you, I also maintain [yoctocolors](https://github.com/sindresorhus/yoctocolors), one of the smallest color packages out there.267 268*\- [Sindre](https://github.com/sindresorhus)*269 270### But the smaller coloring package has benchmarks showing it is faster271 272[Micro-benchmarks are flawed](https://sindresorhus.com/blog/micro-benchmark-fallacy) because they measure performance in unrealistic, isolated scenarios, often giving a distorted view of real-world performance. Don't believe marketing fluff. All the coloring packages are more than fast enough.273 274## Related275 276- [chalk-template](https://github.com/chalk/chalk-template) - [Tagged template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) support for this module277- [chalk-cli](https://github.com/chalk/chalk-cli) - CLI for this module278- [ansi-styles](https://github.com/chalk/ansi-styles) - ANSI escape codes for styling strings in the terminal279- [supports-color](https://github.com/chalk/supports-color) - Detect whether a terminal supports color280- [strip-ansi](https://github.com/chalk/strip-ansi) - Strip ANSI escape codes281- [strip-ansi-stream](https://github.com/chalk/strip-ansi-stream) - Strip ANSI escape codes from a stream282- [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes283- [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes284- [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes285- [slice-ansi](https://github.com/chalk/slice-ansi) - Slice a string with ANSI escape codes286- [color-convert](https://github.com/qix-/color-convert) - Converts colors between different models287- [chalk-animation](https://github.com/bokub/chalk-animation) - Animate strings in the terminal288- [gradient-string](https://github.com/bokub/gradient-string) - Apply color gradients to strings289- [chalk-pipe](https://github.com/LitoMore/chalk-pipe) - Create chalk style schemes with simpler style strings290- [terminal-link](https://github.com/sindresorhus/terminal-link) - Create clickable links in the terminal291 292*(Not accepting additional entries)*293 294## Maintainers295 296- [Sindre Sorhus](https://github.com/sindresorhus)297- [Josh Junon](https://github.com/qix-)298