diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index d588995..5cd8789 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -13,9 +13,10 @@ jobs:
- 18
- 16
- 14
+ - 12
steps:
- - uses: actions/checkout@v4
- - uses: actions/setup-node@v4
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
diff --git a/.replit b/.replit
new file mode 100644
index 0000000..cf3930d
--- /dev/null
+++ b/.replit
@@ -0,0 +1,2 @@
+language = "nodejs"
+run = "cd examples && node rainbow"
diff --git a/examples/rainbow.js b/examples/rainbow.js
index 5b2b1d2..3501dab 100644
--- a/examples/rainbow.js
+++ b/examples/rainbow.js
@@ -1,6 +1,6 @@
-import {setTimeout as delay} from 'node:timers/promises';
import convertColor from 'color-convert';
import updateLog from 'log-update';
+import delay from 'yoctodelay';
import chalk from '../source/index.js';
const ignoreChars = /[^!-~]/g;
@@ -10,7 +10,7 @@ function rainbow(string, offset) {
return string;
}
- const hueStep = 360 / string.replaceAll(ignoreChars, '').length;
+ const hueStep = 360 / string.replace(ignoreChars, '').length;
let hue = offset % 360;
const characters = [];
@@ -33,6 +33,8 @@ async function animateString(string) {
}
}
-console.log();
-await animateString('We hope you enjoy Chalk! <3');
-console.log();
+(async () => {
+ console.log();
+ await animateString('We hope you enjoy Chalk! <3');
+ console.log();
+})();
diff --git a/package.json b/package.json
index c9e0dc5..1736ff9 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "chalk",
- "version": "5.6.2",
+ "version": "5.1.1",
"description": "Terminal string styling done right",
"license": "MIT",
"repository": "chalk/chalk",
@@ -16,7 +16,6 @@
}
},
"types": "./source/index.d.ts",
- "sideEffects": false,
"engines": {
"node": "^12.17.0 || ^14.13 || >=16.0.0"
},
@@ -59,7 +58,7 @@
"log-update": "^5.0.0",
"matcha": "^0.7.0",
"tsd": "^0.19.0",
- "xo": "^0.57.0",
+ "xo": "^0.52.4",
"yoctodelay": "^2.0.0"
},
"xo": {
@@ -67,8 +66,7 @@
"unicorn/prefer-string-slice": "off",
"@typescript-eslint/consistent-type-imports": "off",
"@typescript-eslint/consistent-type-exports": "off",
- "@typescript-eslint/consistent-type-definitions": "off",
- "unicorn/expiring-todo-comments": "off"
+ "@typescript-eslint/consistent-type-definitions": "off"
}
},
"c8": {
diff --git a/readme.md b/readme.md
index ce1f3f3..f18b2aa 100644
--- a/readme.md
+++ b/readme.md
@@ -12,13 +12,71 @@
[](https://codecov.io/gh/chalk/chalk)
[](https://www.npmjs.com/package/chalk?activeTab=dependents)
[](https://www.npmjs.com/package/chalk)
+[](https://repl.it/github/chalk/chalk)

-## Info
+
-- [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)
-- See [yoctocolors](https://github.com/sindresorhus/yoctocolors) for a smaller alternative
+---
+
+
+
+---
+
+
## Highlights
@@ -31,7 +89,7 @@
- Doesn't extend `String.prototype`
- Clean and focused
- Actively maintained
-- [Used by ~115,000 packages](https://www.npmjs.com/browse/depended/chalk) as of July 4, 2024
+- [Used by ~86,000 packages](https://www.npmjs.com/browse/depended/chalk) as of October 4, 2022
## Install
@@ -178,10 +236,10 @@ console.log(foregroundColorNames.includes('pink'));
- `italic` - Make the text italic. *(Not widely supported)*
- `underline` - Put a horizontal line below the text. *(Not widely supported)*
- `overline` - Put a horizontal line above the text. *(Not widely supported)*
-- `inverse` - Invert background and foreground colors.
+- `inverse`- Invert background and foreground colors.
- `hidden` - Print the text but make it invisible.
- `strikethrough` - Puts a horizontal line through the center of the text. *(Not widely supported)*
-- `visible` - Print the text only when Chalk has a color level above zero. Can be useful for things that are purely cosmetic.
+- `visible`- Print the text only when Chalk has a color level above zero. Can be useful for things that are purely cosmetic.
### Colors
@@ -223,7 +281,7 @@ console.log(foregroundColorNames.includes('pink'));
## 256 and Truecolor color support
-Chalk supports 256 colors and [Truecolor](https://github.com/termstandard/colors) (16 million colors) on supported terminal apps.
+Chalk supports 256 colors and [Truecolor](https://gist.github.com/XVilka/8346728) (16 million colors) on supported terminal apps.
Colors 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).
@@ -251,25 +309,9 @@ Since Chrome 69, ANSI escape codes are natively supported in the developer conso
If you're on Windows, do yourself a favor and use [Windows Terminal](https://github.com/microsoft/terminal) instead of `cmd.exe`.
-## FAQ
+## Origin story
-### Why not switch to a smaller coloring package?
-
-Chalk 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.
-
-But 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.
-
-Chalk 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.
-
-If 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.
-
-If absolute package size is important to you, I also maintain [yoctocolors](https://github.com/sindresorhus/yoctocolors), one of the smallest color packages out there.
-
-*\- [Sindre](https://github.com/sindresorhus)*
-
-### But the smaller coloring package has benchmarks showing it is faster
-
-[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.
+[colors.js](https://github.com/Marak/colors.js) used to be the most popular string styling module, but it has serious deficiencies like extending `String.prototype` which causes all kinds of [problems](https://github.com/yeoman/yo/issues/68) and the package is unmaintained. Although there are other packages, they either do too much or not enough. Chalk is a clean and focused alternative.
## Related
@@ -289,8 +331,6 @@ If absolute package size is important to you, I also maintain [yoctocolors](http
- [chalk-pipe](https://github.com/LitoMore/chalk-pipe) - Create chalk style schemes with simpler style strings
- [terminal-link](https://github.com/sindresorhus/terminal-link) - Create clickable links in the terminal
-*(Not accepting additional entries)*
-
## Maintainers
- [Sindre Sorhus](https://github.com/sindresorhus)
diff --git a/source/index.d.ts b/source/index.d.ts
index 8295d92..b0cd2ae 100644
--- a/source/index.d.ts
+++ b/source/index.d.ts
@@ -1,12 +1,7 @@
// TODO: Make it this when TS suports that.
// import {ModifierName, ForegroundColor, BackgroundColor, ColorName} from '#ansi-styles';
// import {ColorInfo, ColorSupportLevel} from '#supports-color';
-import {
- ModifierName,
- ForegroundColorName,
- BackgroundColorName,
- ColorName,
-} from './vendor/ansi-styles/index.js';
+import {ModifierName, ForegroundColorName, BackgroundColorName, ColorName} from './vendor/ansi-styles/index.js';
import {ColorInfo, ColorSupportLevel} from './vendor/supports-color/index.js';
export interface Options {
diff --git a/source/index.test-d.ts b/source/index.test-d.ts
index 92da39d..e729675 100644
--- a/source/index.test-d.ts
+++ b/source/index.test-d.ts
@@ -1,22 +1,7 @@
-import {
- expectType,
- expectAssignable,
- expectError,
- expectDeprecated,
-} from 'tsd';
+import {expectType, expectAssignable, expectError, expectDeprecated} from 'tsd';
import chalk, {
- Chalk,
- ChalkInstance,
- ColorInfo,
- ColorSupport,
- ColorSupportLevel,
- chalkStderr,
- supportsColor,
- supportsColorStderr,
- ModifierName,
- ForegroundColorName,
- BackgroundColorName,
- ColorName,
+ Chalk, ChalkInstance, ColorInfo, ColorSupport, ColorSupportLevel, chalkStderr, supportsColor, supportsColorStderr,
+ ModifierName, ForegroundColorName, BackgroundColorName, ColorName,
Modifiers,
} from './index.js';
diff --git a/source/vendor/ansi-styles/index.js b/source/vendor/ansi-styles/index.js
index eaa7bed..bd1010c 100644
--- a/source/vendor/ansi-styles/index.js
+++ b/source/vendor/ansi-styles/index.js
@@ -65,11 +65,6 @@ const styles = {
},
};
-export const modifierNames = Object.keys(styles.modifier);
-export const foregroundColorNames = Object.keys(styles.color);
-export const backgroundColorNames = Object.keys(styles.bgColor);
-export const colorNames = [...foregroundColorNames, ...backgroundColorNames];
-
function assembleStyles() {
const codes = new Map();
@@ -221,3 +216,8 @@ function assembleStyles() {
const ansiStyles = assembleStyles();
export default ansiStyles;
+
+export const modifierNames = Object.keys(styles.modifier);
+export const foregroundColorNames = Object.keys(styles.color);
+export const backgroundColorNames = Object.keys(styles.bgColor);
+export const colorNames = [...foregroundColorNames, ...backgroundColorNames];
diff --git a/source/vendor/supports-color/browser.js b/source/vendor/supports-color/browser.js
index fbb6ce0..4e75e86 100644
--- a/source/vendor/supports-color/browser.js
+++ b/source/vendor/supports-color/browser.js
@@ -1,30 +1,15 @@
/* eslint-env browser */
-const level = (() => {
- if (!('navigator' in globalThis)) {
- return 0;
- }
+const isBlinkBasedBrowser = navigator.userAgentData
+ ? navigator.userAgentData.brands.some(({brand}) => brand === 'Chromium')
+ : /\b(Chrome|Chromium)\//.test(navigator.userAgent);
- if (globalThis.navigator.userAgentData) {
- const brand = navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium');
- if (brand && brand.version > 93) {
- return 3;
- }
- }
-
- if (/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)) {
- return 1;
- }
-
- return 0;
-})();
-
-const colorSupport = level !== 0 && {
- level,
+const colorSupport = isBlinkBasedBrowser ? {
+ level: 1,
hasBasic: true,
- has256: level >= 2,
- has16m: level >= 3,
-};
+ has256: false,
+ has16m: false,
+} : false;
const supportsColor = {
stdout: colorSupport,
diff --git a/source/vendor/supports-color/index.d.ts b/source/vendor/supports-color/index.d.ts
index db44a78..98e3618 100644
--- a/source/vendor/supports-color/index.d.ts
+++ b/source/vendor/supports-color/index.d.ts
@@ -1,13 +1,13 @@
-import type {WriteStream} from 'node:tty';
+import {WriteStream} from 'node:tty';
-export type Options = {
+export interface Options {
/**
Whether `process.argv` should be sniffed for `--color` and `--no-color` flags.
@default true
*/
readonly sniffFlags?: boolean;
-};
+}
/**
Levels:
@@ -21,7 +21,7 @@ export type ColorSupportLevel = 0 | 1 | 2 | 3;
/**
Detect whether the terminal supports color.
*/
-export type ColorSupport = {
+export interface ColorSupport {
/**
The color level.
*/
@@ -41,11 +41,11 @@ export type ColorSupport = {
Whether Truecolor 16 million colors are supported.
*/
has16m: boolean;
-};
+}
export type ColorInfo = ColorSupport | false;
-export function createSupportsColor(stream?: WriteStream, options?: Options): ColorInfo;
+export function createSupportsColor(stream: WriteStream, options?: Options): ColorInfo;
declare const supportsColor: {
stdout: ColorInfo;
diff --git a/source/vendor/supports-color/index.js b/source/vendor/supports-color/index.js
index 265d7f8..55f813c 100644
--- a/source/vendor/supports-color/index.js
+++ b/source/vendor/supports-color/index.js
@@ -3,8 +3,7 @@ import os from 'node:os';
import tty from 'node:tty';
// From: https://github.com/sindresorhus/has-flag/blob/main/index.js
-/// function hasFlag(flag, argv = globalThis.Deno?.args ?? process.argv) {
-function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process.argv) {
+function hasFlag(flag, argv = process.argv) {
const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
const position = argv.indexOf(prefix + flag);
const terminatorPosition = argv.indexOf('--');
@@ -81,12 +80,6 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
}
}
- // Check for Azure DevOps pipelines.
- // Has to be above the `!streamIsTTY` check.
- if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
- return 1;
- }
-
if (haveStream && !streamIsTTY && forceColor === undefined) {
return 0;
}
@@ -112,11 +105,7 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
}
if ('CI' in env) {
- if (['GITHUB_ACTIONS', 'GITEA_ACTIONS', 'CIRCLECI'].some(key => key in env)) {
- return 3;
- }
-
- if (['TRAVIS', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
+ if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
return 1;
}
@@ -127,33 +116,23 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
}
+ // Check for Azure DevOps pipelines
+ if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
+ return 1;
+ }
+
if (env.COLORTERM === 'truecolor') {
return 3;
}
- if (env.TERM === 'xterm-kitty') {
- return 3;
- }
-
- if (env.TERM === 'xterm-ghostty') {
- return 3;
- }
-
- if (env.TERM === 'wezterm') {
- return 3;
- }
-
if ('TERM_PROGRAM' in env) {
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
switch (env.TERM_PROGRAM) {
- case 'iTerm.app': {
+ case 'iTerm.app':
return version >= 3 ? 3 : 2;
- }
-
- case 'Apple_Terminal': {
+ case 'Apple_Terminal':
return 2;
- }
// No default
}
}