From 445092f9af0a0c71070c3acc435340a9278e67f1 Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Wed, 9 Sep 2020 17:48:28 +0200
Subject: [PATCH 01/72] Update readme.md
---
readme.md | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/readme.md b/readme.md
index 338f42c..c1d4ebc 100644
--- a/readme.md
+++ b/readme.md
@@ -13,6 +13,30 @@
+
+
+---
+
+
+
+---
+
+
+
## Highlights
- Expressive API
From b31d6fb48a570d9be48044abe656c36dcac094e4 Mon Sep 17 00:00:00 2001
From: Richie Bendall
Date: Sun, 4 Oct 2020 10:55:17 +1300
Subject: [PATCH 02/72] Add browser support information (#415)
---
readme.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/readme.md b/readme.md
index c1d4ebc..e4ac487 100644
--- a/readme.md
+++ b/readme.md
@@ -280,6 +280,10 @@ The following color models can be used:
- [`ansi`](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) - Example: `chalk.ansi(31).bgAnsi(93)('red on yellowBright')`
- [`ansi256`](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) - Example: `chalk.bgAnsi256(194)('Honeydew, more or less')`
+## Browser support
+
+Since Chrome 69, ANSI escape codes are natively supported in the developer console.
+
## Windows
If you're on Windows, do yourself a favor and use [Windows Terminal](https://github.com/microsoft/terminal) instead of `cmd.exe`.
From c0d8e7ed8a3ec549c81597fc06163276142d948d Mon Sep 17 00:00:00 2001
From: Richie Bendall
Date: Sun, 4 Oct 2020 10:56:24 +1300
Subject: [PATCH 03/72] Update test dependencies (#414)
---
examples/rainbow.js | 4 +++-
index.d.ts | 32 ++++++++++++++++----------------
index.test-d.ts | 38 +++++++++++++++++++-------------------
package.json | 12 ++++++------
source/templates.js | 4 ++--
test/instance.js | 4 ++--
test/template-literal.js | 2 +-
7 files changed, 49 insertions(+), 47 deletions(-)
diff --git a/examples/rainbow.js b/examples/rainbow.js
index 813e026..6e0664c 100644
--- a/examples/rainbow.js
+++ b/examples/rainbow.js
@@ -3,7 +3,9 @@ const chalk = require('..');
const ignoreChars = /[^!-~]/g;
-const delay = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds));
+const delay = milliseconds => new Promise(resolve => {
+ setTimeout(resolve, milliseconds);
+});
function rainbow(string, offset) {
if (!string || string.length === 0) {
diff --git a/index.d.ts b/index.d.ts
index 9cd88f3..8fa375f 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -181,7 +181,7 @@ declare namespace chalk {
chalk.hex('#DEADED');
```
*/
- hex(color: string): Chalk;
+ hex: (color: string) => Chalk;
/**
Use keyword color value to set text color.
@@ -195,27 +195,27 @@ declare namespace chalk {
chalk.keyword('orange');
```
*/
- keyword(color: string): Chalk;
+ keyword: (color: string) => Chalk;
/**
Use RGB values to set text color.
*/
- rgb(red: number, green: number, blue: number): Chalk;
+ rgb: (red: number, green: number, blue: number) => Chalk;
/**
Use HSL values to set text color.
*/
- hsl(hue: number, saturation: number, lightness: number): Chalk;
+ hsl: (hue: number, saturation: number, lightness: number) => Chalk;
/**
Use HSV values to set text color.
*/
- hsv(hue: number, saturation: number, value: number): Chalk;
+ hsv: (hue: number, saturation: number, value: number) => Chalk;
/**
Use HWB values to set text color.
*/
- hwb(hue: number, whiteness: number, blackness: number): Chalk;
+ hwb: (hue: number, whiteness: number, blackness: number) => Chalk;
/**
Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set text color.
@@ -223,12 +223,12 @@ declare namespace chalk {
30 <= code && code < 38 || 90 <= code && code < 98
For example, 31 for red, 91 for redBright.
*/
- ansi(code: number): Chalk;
+ ansi: (code: number) => Chalk;
/**
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
*/
- ansi256(index: number): Chalk;
+ ansi256: (index: number) => Chalk;
/**
Use HEX value to set background color.
@@ -242,7 +242,7 @@ declare namespace chalk {
chalk.bgHex('#DEADED');
```
*/
- bgHex(color: string): Chalk;
+ bgHex: (color: string) => Chalk;
/**
Use keyword color value to set background color.
@@ -256,27 +256,27 @@ declare namespace chalk {
chalk.bgKeyword('orange');
```
*/
- bgKeyword(color: string): Chalk;
+ bgKeyword: (color: string) => Chalk;
/**
Use RGB values to set background color.
*/
- bgRgb(red: number, green: number, blue: number): Chalk;
+ bgRgb: (red: number, green: number, blue: number) => Chalk;
/**
Use HSL values to set background color.
*/
- bgHsl(hue: number, saturation: number, lightness: number): Chalk;
+ bgHsl: (hue: number, saturation: number, lightness: number) => Chalk;
/**
Use HSV values to set background color.
*/
- bgHsv(hue: number, saturation: number, value: number): Chalk;
+ bgHsv: (hue: number, saturation: number, value: number) => Chalk;
/**
Use HWB values to set background color.
*/
- bgHwb(hue: number, whiteness: number, blackness: number): Chalk;
+ bgHwb: (hue: number, whiteness: number, blackness: number) => Chalk;
/**
Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set background color.
@@ -285,12 +285,12 @@ declare namespace chalk {
For example, 31 for red, 91 for redBright.
Use the foreground code, not the background code (for example, not 41, nor 101).
*/
- bgAnsi(code: number): Chalk;
+ bgAnsi: (code: number) => Chalk;
/**
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
*/
- bgAnsi256(index: number): Chalk;
+ bgAnsi256: (index: number) => Chalk;
/**
Modifier: Resets the current color chain.
diff --git a/index.test-d.ts b/index.test-d.ts
index aa9e2f5..ba91b63 100644
--- a/index.test-d.ts
+++ b/index.test-d.ts
@@ -1,4 +1,4 @@
-import {expectType, expectError} from 'tsd';
+import {expectType, expectAssignable, expectError} from 'tsd';
import chalk = require('.');
// - Helpers -
@@ -13,7 +13,7 @@ if (chalk.supportsColor) {
}
// - stderr -
-expectType(chalk.stderr);
+expectAssignable(chalk.stderr);
expectType(chalk.stderr.supportsColor);
if (chalk.stderr.supportsColor) {
expectType(chalk.stderr.supportsColor.hasBasic);
@@ -41,22 +41,22 @@ expectType(chalk`Hello {bold.red ${name}}`);
expectType(chalk`Works with numbers {bold.red ${1}}`);
// -- Color methods --
-expectType(chalk.hex('#DEADED'));
-expectType(chalk.keyword('orange'));
-expectType(chalk.rgb(0, 0, 0));
-expectType(chalk.hsl(0, 0, 0));
-expectType(chalk.hsv(0, 0, 0));
-expectType(chalk.hwb(0, 0, 0));
-expectType(chalk.ansi(30));
-expectType(chalk.ansi256(0));
-expectType(chalk.bgHex('#DEADED'));
-expectType(chalk.bgKeyword('orange'));
-expectType(chalk.bgRgb(0, 0, 0));
-expectType(chalk.bgHsl(0, 0, 0));
-expectType(chalk.bgHsv(0, 0, 0));
-expectType(chalk.bgHwb(0, 0, 0));
-expectType(chalk.bgAnsi(30));
-expectType(chalk.bgAnsi256(0));
+expectAssignable(chalk.hex('#DEADED'));
+expectAssignable(chalk.keyword('orange'));
+expectAssignable(chalk.rgb(0, 0, 0));
+expectAssignable(chalk.hsl(0, 0, 0));
+expectAssignable(chalk.hsv(0, 0, 0));
+expectAssignable(chalk.hwb(0, 0, 0));
+expectAssignable(chalk.ansi(30));
+expectAssignable(chalk.ansi256(0));
+expectAssignable(chalk.bgHex('#DEADED'));
+expectAssignable(chalk.bgKeyword('orange'));
+expectAssignable(chalk.bgRgb(0, 0, 0));
+expectAssignable(chalk.bgHsl(0, 0, 0));
+expectAssignable(chalk.bgHsv(0, 0, 0));
+expectAssignable(chalk.bgHwb(0, 0, 0));
+expectAssignable(chalk.bgAnsi(30));
+expectAssignable(chalk.bgAnsi256(0));
// -- Modifiers --
expectType(chalk.reset('foo'));
@@ -158,5 +158,5 @@ expectType(chalk.red.bgGreen.bold`Hello {italic.blue ${name}}`);
expectType(chalk.strikethrough.cyanBright.bgBlack`Works with {reset {bold numbers}} {bold.red ${1}}`);
// -- Color types ==
-expectType('red');
+expectAssignable('red');
expectError('hotpink');
diff --git a/package.json b/package.json
index 0d99f0f..7a3bd25 100644
--- a/package.json
+++ b/package.json
@@ -46,14 +46,14 @@
},
"devDependencies": {
"ava": "^2.4.0",
- "coveralls": "^3.0.7",
- "execa": "^4.0.0",
- "import-fresh": "^3.1.0",
+ "coveralls": "^3.1.0",
+ "execa": "^4.0.3",
+ "import-fresh": "^3.2.1",
"matcha": "^0.7.0",
- "nyc": "^15.0.0",
+ "nyc": "^15.1.0",
"resolve-from": "^5.0.0",
- "tsd": "^0.7.4",
- "xo": "^0.28.2"
+ "tsd": "^0.13.1",
+ "xo": "^0.33.1"
},
"xo": {
"rules": {
diff --git a/source/templates.js b/source/templates.js
index b130949..bfdaba8 100644
--- a/source/templates.js
+++ b/source/templates.js
@@ -22,11 +22,11 @@ function unescape(c) {
const bracket = c[1] === '{';
if ((u && !bracket && c.length === 5) || (c[0] === 'x' && c.length === 3)) {
- return String.fromCharCode(parseInt(c.slice(1), 16));
+ return String.fromCharCode(Number.parseInt(c.slice(1), 16));
}
if (u && bracket) {
- return String.fromCodePoint(parseInt(c.slice(2, -1), 16));
+ return String.fromCodePoint(Number.parseInt(c.slice(2, -1), 16));
}
return ESCAPES.get(c) || c;
diff --git a/test/instance.js b/test/instance.js
index e936333..37c72eb 100644
--- a/test/instance.js
+++ b/test/instance.js
@@ -17,10 +17,10 @@ test('the `level` option should be a number from 0 to 3', t => {
/* eslint-disable no-new */
t.throws(() => {
new chalk.Instance({level: 10});
- }, /should be an integer from 0 to 3/);
+ }, {message: /should be an integer from 0 to 3/});
t.throws(() => {
new chalk.Instance({level: -1});
- }, /should be an integer from 0 to 3/);
+ }, {message: /should be an integer from 0 to 3/});
/* eslint-enable no-new */
});
diff --git a/test/template-literal.js b/test/template-literal.js
index 2f75e03..c918a5b 100644
--- a/test/template-literal.js
+++ b/test/template-literal.js
@@ -179,7 +179,7 @@ test('throws if an extra unescaped } is found', t => {
test('should not parse upper-case escapes', t => {
const instance = new chalk.Instance({level: 0});
- t.is(instance`\N\n\T\t\X07\x07\U000A\u000A\U000a\u000a`, 'N\nT\tX07\x07U000A\u000AU000a\u000A');
+ t.is(instance`\N\n\T\t\X07\x07\U000A\u000A\U000a\u000A`, 'N\nT\tX07\x07U000A\u000AU000a\u000A');
});
test('should properly handle undefined template interpolated values', t => {
From 72299f99a0f785128b3b974afac7d8a9bccbeb4a Mon Sep 17 00:00:00 2001
From: Toon Baeyens
Date: Fri, 20 Nov 2020 15:26:28 +0100
Subject: [PATCH 04/72] remove fixed number of iterations (#406)
---
benchmark.js | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/benchmark.js b/benchmark.js
index 25b3f5d..98ee5ee 100644
--- a/benchmark.js
+++ b/benchmark.js
@@ -1,10 +1,8 @@
-/* globals suite, set, bench */
+/* globals suite, bench */
'use strict';
const chalk = require('.');
suite('chalk', () => {
- set('iterations', 1000000);
-
const chalkRed = chalk.red;
const chalkBgRed = chalk.bgRed;
const chalkBlueBgRed = chalk.blue.bgRed;
@@ -48,8 +46,6 @@ suite('chalk', () => {
chalkBgRed(blueStyledString);
});
- set('iterations', 10000);
-
bench('cached: 1 style template literal', () => {
// eslint-disable-next-line no-unused-expressions
chalkRed`the fox jumps over the lazy dog`;
From 02abeebac3fa41b346ad1f0b4674d371953da932 Mon Sep 17 00:00:00 2001
From: Richie Bendall
Date: Sun, 22 Nov 2020 02:07:13 +1300
Subject: [PATCH 05/72] Only iterate through models once (#421)
---
source/index.js | 2 --
1 file changed, 2 deletions(-)
diff --git a/source/index.js b/source/index.js
index 75ec663..6313bde 100644
--- a/source/index.js
+++ b/source/index.js
@@ -87,9 +87,7 @@ for (const model of usedModels) {
};
}
};
-}
-for (const model of usedModels) {
const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
styles[bgModel] = {
get() {
From e304e8c2302c5fc3a1705756640a3bee94dec857 Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Tue, 8 Dec 2020 21:43:19 +0700
Subject: [PATCH 06/72] Add Dev badge
---
readme.md | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/readme.md b/readme.md
index e4ac487..f0e2eb5 100644
--- a/readme.md
+++ b/readme.md
@@ -9,7 +9,11 @@
> Terminal string styling done right
-[](https://travis-ci.org/chalk/chalk) [](https://coveralls.io/github/chalk/chalk?branch=master) [](https://www.npmjs.com/package/chalk?activeTab=dependents) [](https://www.npmjs.com/package/chalk) [](https://www.youtube.com/watch?v=9auOCbH5Ns4) [](https://github.com/xojs/xo)  [](https://repl.it/github/chalk/chalk)
+[](https://travis-ci.org/chalk/chalk)
+[](https://coveralls.io/github/chalk/chalk?branch=master)
+[](https://www.npmjs.com/package/chalk?activeTab=dependents) [](https://www.npmjs.com/package/chalk)
+[](https://repl.it/github/chalk/chalk)
+[](https://stakes.social/0x44d871aebF0126Bf646753E2C976Aa7e68A66c15)
@@ -21,7 +25,7 @@
- Sindre Sorhus' open source work is supported by the community
+ Sindre Sorhus' open source work is supported by the community on GitHub Sponsors and Dev
Special thanks to:
From ca330532ecfb83e46efa9e94d1c0630a058ff1ba Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Wed, 16 Dec 2020 10:09:08 +0700
Subject: [PATCH 07/72] Add @Qix- to funding.yml
---
.github/funding.yml | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/.github/funding.yml b/.github/funding.yml
index baa12cf..5692ede 100644
--- a/.github/funding.yml
+++ b/.github/funding.yml
@@ -1,5 +1,4 @@
-github: sindresorhus
+github: [sindresorhus,Qix-]
open_collective: sindresorhus
-patreon: sindresorhus
tidelift: npm/chalk
custom: https://sindresorhus.com/donate
From d5fb377019c26e3beae55f97906c4fd1bec30402 Mon Sep 17 00:00:00 2001
From: Richie Bendall
Date: Sun, 3 Jan 2021 02:38:53 +1300
Subject: [PATCH 08/72] Move to GitHub Actions (#426)
* Move to GitHub Actions
* Update readme.md
---
.github/workflows/main.yml | 22 ++++++++++++++++++++++
.travis.yml | 6 ------
readme.md | 1 -
3 files changed, 22 insertions(+), 7 deletions(-)
create mode 100644 .github/workflows/main.yml
delete mode 100644 .travis.yml
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
new file mode 100644
index 0000000..c1870cf
--- /dev/null
+++ b/.github/workflows/main.yml
@@ -0,0 +1,22 @@
+name: CI
+on:
+ - push
+ - pull_request
+jobs:
+ test:
+ name: Node.js ${{ matrix.node-version }}
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ node-version:
+ - 14
+ - 12
+ - 10
+ steps:
+ - uses: actions/checkout@v2
+ - uses: actions/setup-node@v1
+ with:
+ node-version: ${{ matrix.node-version }}
+ - run: npm install
+ - run: npm test
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index fd301d7..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-language: node_js
-node_js:
- - '12'
- - '10'
-after_success:
- - './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
diff --git a/readme.md b/readme.md
index f0e2eb5..e8fe039 100644
--- a/readme.md
+++ b/readme.md
@@ -9,7 +9,6 @@
> Terminal string styling done right
-[](https://travis-ci.org/chalk/chalk)
[](https://coveralls.io/github/chalk/chalk?branch=master)
[](https://www.npmjs.com/package/chalk?activeTab=dependents) [](https://www.npmjs.com/package/chalk)
[](https://repl.it/github/chalk/chalk)
From 0433fcff2af28a64cc4e07345b0e78cb664142ea Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Wed, 20 Jan 2021 14:45:02 +0700
Subject: [PATCH 09/72] Update a link
---
readme.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/readme.md b/readme.md
index e8fe039..18a0554 100644
--- a/readme.md
+++ b/readme.md
@@ -30,7 +30,7 @@
Special thanks to:
-
+
From 97a08618485d25cee6c62712584648f838777727 Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Thu, 21 Jan 2021 10:19:50 +0700
Subject: [PATCH 10/72] Update badge
---
readme.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/readme.md b/readme.md
index 18a0554..ba83864 100644
--- a/readme.md
+++ b/readme.md
@@ -12,7 +12,7 @@
[](https://coveralls.io/github/chalk/chalk?branch=master)
[](https://www.npmjs.com/package/chalk?activeTab=dependents) [](https://www.npmjs.com/package/chalk)
[](https://repl.it/github/chalk/chalk)
-[](https://stakes.social/0x44d871aebF0126Bf646753E2C976Aa7e68A66c15)
+[](https://stakes.social/0x44d871aebF0126Bf646753E2C976Aa7e68A66c15)
From 2a9abb18f4c33b71fbda25be0f3de53bd86eef31 Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Sun, 24 Jan 2021 14:27:41 +0700
Subject: [PATCH 11/72] Rename `master` branch to `main`
---
index.d.ts | 6 +++---
readme.md | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/index.d.ts b/index.d.ts
index 8fa375f..ddaf8d4 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -1,7 +1,7 @@
/**
Basic foreground colors.
-[More colors here.](https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support)
+[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
declare type ForegroundColor =
| 'black'
@@ -26,7 +26,7 @@ declare type ForegroundColor =
/**
Basic background colors.
-[More colors here.](https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support)
+[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
declare type BackgroundColor =
| 'bgBlack'
@@ -51,7 +51,7 @@ declare type BackgroundColor =
/**
Basic colors.
-[More colors here.](https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support)
+[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
declare type Color = ForegroundColor | BackgroundColor;
diff --git a/readme.md b/readme.md
index ba83864..eeaac7c 100644
--- a/readme.md
+++ b/readme.md
@@ -9,7 +9,7 @@
> Terminal string styling done right
-[](https://coveralls.io/github/chalk/chalk?branch=master)
+[](https://coveralls.io/github/chalk/chalk?branch=main)
[](https://www.npmjs.com/package/chalk?activeTab=dependents) [](https://www.npmjs.com/package/chalk)
[](https://repl.it/github/chalk/chalk)
[](https://stakes.social/0x44d871aebF0126Bf646753E2C976Aa7e68A66c15)
From 9bf298571eeee20001ba9ff5158b07d2d8a67ec1 Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Sat, 30 Jan 2021 16:59:16 +0700
Subject: [PATCH 12/72] Meta tweaks
---
readme.md | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/readme.md b/readme.md
index eeaac7c..f1c9b9e 100644
--- a/readme.md
+++ b/readme.md
@@ -31,7 +31,12 @@
-
+
+
+
+
+
+
From 4dab5e1fb6f42c6c9fdacbe34b9dafd24359208e Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Sat, 13 Mar 2021 00:51:42 +0700
Subject: [PATCH 13/72] Meta tweaks
---
readme.md | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/readme.md b/readme.md
index f1c9b9e..4867321 100644
--- a/readme.md
+++ b/readme.md
@@ -38,6 +38,19 @@
+
+
+
+
+

+
+ All your environment variables, in one place
+
+ Stop struggling with scattered API keys, hacking together home-brewed tools,
+
+ and avoiding access controls. Keep your team and servers in sync with Doppler.
+
+
From fa16f4ec37c1c25bda6ca1864bf53ecd3ea3d3c9 Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Fri, 16 Apr 2021 15:23:29 +0700
Subject: [PATCH 14/72] Require Node.js 12 and move to ESM
---
.github/funding.yml | 2 +-
.github/workflows/main.yml | 3 +-
benchmark.js | 3 +-
examples/rainbow.js | 9 +-
examples/screenshot.js | 5 +-
index.d.ts | 550 ++++++++++++++++++-------------------
index.test-d.ts | 18 +-
license | 2 +-
package.json | 21 +-
readme.md | 17 +-
source/index.js | 20 +-
source/templates.js | 11 +-
source/util.js | 19 +-
test/_fixture.js | 3 +-
test/_supports-color.js | 21 --
test/chalk.js | 7 +-
test/constructor.js | 3 +-
test/instance.js | 6 +-
test/level.js | 10 +-
test/no-color-support.js | 32 +--
test/template-literal.js | 6 +-
test/visible.js | 6 +-
22 files changed, 362 insertions(+), 412 deletions(-)
delete mode 100644 test/_supports-color.js
diff --git a/.github/funding.yml b/.github/funding.yml
index 5692ede..1cd069f 100644
--- a/.github/funding.yml
+++ b/.github/funding.yml
@@ -1,4 +1,4 @@
-github: [sindresorhus,Qix-]
+github: [sindresorhus, Qix-]
open_collective: sindresorhus
tidelift: npm/chalk
custom: https://sindresorhus.com/donate
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index c1870cf..d36e1a8 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -12,10 +12,9 @@ jobs:
node-version:
- 14
- 12
- - 10
steps:
- uses: actions/checkout@v2
- - uses: actions/setup-node@v1
+ - uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
diff --git a/benchmark.js b/benchmark.js
index 98ee5ee..c5c6e27 100644
--- a/benchmark.js
+++ b/benchmark.js
@@ -1,6 +1,5 @@
/* globals suite, bench */
-'use strict';
-const chalk = require('.');
+import chalk from './index.js';
suite('chalk', () => {
const chalkRed = chalk.red;
diff --git a/examples/rainbow.js b/examples/rainbow.js
index 6e0664c..67dd236 100644
--- a/examples/rainbow.js
+++ b/examples/rainbow.js
@@ -1,5 +1,4 @@
-'use strict';
-const chalk = require('..');
+import chalk from '../index.js';
const ignoreChars = /[^!-~]/g;
@@ -17,7 +16,7 @@ function rainbow(string, offset) {
let hue = offset % 360;
const characters = [];
for (const character of string) {
- if (character.match(ignoreChars)) {
+ if (ignoreChars.test(character)) {
characters.push(character);
} else {
characters.push(chalk.hsl(hue, 100, 50)(character));
@@ -30,8 +29,8 @@ function rainbow(string, offset) {
async function animateString(string) {
console.log();
- for (let i = 0; i < 360 * 5; i++) {
- console.log('\u001B[1F\u001B[G', rainbow(string, i));
+ for (let index = 0; index < 360 * 5; index++) {
+ console.log('\u001B[1F\u001B[G', rainbow(string, index));
await delay(2); // eslint-disable-line no-await-in-loop
}
}
diff --git a/examples/screenshot.js b/examples/screenshot.js
index fc64030..ea61e0c 100644
--- a/examples/screenshot.js
+++ b/examples/screenshot.js
@@ -1,6 +1,5 @@
-'use strict';
-const styles = require('ansi-styles');
-const chalk = require('..');
+import styles from 'ansi-styles';
+import chalk from '../index.js';
// Generates screenshot
for (const key of Object.keys(styles)) {
diff --git a/index.d.ts b/index.d.ts
index ddaf8d4..268ab75 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -3,7 +3,7 @@ Basic foreground colors.
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
-declare type ForegroundColor =
+export type ForegroundColor =
| 'black'
| 'red'
| 'green'
@@ -28,7 +28,7 @@ Basic background colors.
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
-declare type BackgroundColor =
+export type BackgroundColor =
| 'bgBlack'
| 'bgRed'
| 'bgGreen'
@@ -53,9 +53,9 @@ Basic colors.
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
*/
-declare type Color = ForegroundColor | BackgroundColor;
+export type Color = ForegroundColor | BackgroundColor;
-declare type Modifiers =
+export type Modifiers =
| 'reset'
| 'bold'
| 'dim'
@@ -66,350 +66,346 @@ declare type Modifiers =
| 'strikethrough'
| 'visible';
-declare namespace chalk {
+/**
+Levels:
+- `0` - All colors disabled.
+- `1` - Basic 16 colors support.
+- `2` - ANSI 256 colors support.
+- `3` - Truecolor 16 million colors support.
+*/
+export type ColorSupportLevel = 0 | 1 | 2 | 3;
+
+export interface Options {
/**
+ Specify the color support for Chalk.
+
+ By default, color support is automatically detected based on the environment.
+
Levels:
- `0` - All colors disabled.
- `1` - Basic 16 colors support.
- `2` - ANSI 256 colors support.
- `3` - Truecolor 16 million colors support.
*/
- type Level = 0 | 1 | 2 | 3;
+ readonly level?: ColorSupportLevel;
+}
- interface Options {
- /**
- Specify the color support for Chalk.
+/**
+Return a new Chalk instance.
+*/
+export type ChalkInstance = new (options?: Options) => Chalk;
- By default, color support is automatically detected based on the environment.
+/**
+Detect whether the terminal supports color.
+*/
+export interface ColorSupport {
+ /**
+ The color level used by Chalk.
+ */
+ level: ColorSupportLevel;
- Levels:
- - `0` - All colors disabled.
- - `1` - Basic 16 colors support.
- - `2` - ANSI 256 colors support.
- - `3` - Truecolor 16 million colors support.
- */
- level?: Level;
- }
+ /**
+ Return whether Chalk supports basic 16 colors.
+ */
+ hasBasic: boolean;
+ /**
+ Return whether Chalk supports ANSI 256 colors.
+ */
+ has256: boolean;
+
+ /**
+ Return whether Chalk supports Truecolor 16 million colors.
+ */
+ has16m: boolean;
+}
+
+interface ChalkFunction {
+ /**
+ Use a template string.
+
+ @remarks Template literals are unsupported for nested calls (see [issue #341](https://github.com/chalk/chalk/issues/341))
+
+ @example
+ ```
+ import chalk from 'chalk';
+
+ log(chalk`
+ CPU: {red ${cpu.totalPercent}%}
+ RAM: {green ${ram.used / ram.total * 100}%}
+ DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
+ `);
+ ```
+
+ @example
+ ```
+ import chalk from 'chalk';
+
+ log(chalk.red.bgBlack`2 + 3 = {bold ${2 + 3}}`)
+ ```
+ */
+ (text: TemplateStringsArray, ...placeholders: unknown[]): string;
+
+ (...text: unknown[]): string;
+}
+
+export interface Chalk extends ChalkFunction {
/**
Return a new Chalk instance.
*/
- type Instance = new (options?: Options) => Chalk;
+ Instance: ChalkInstance;
/**
- Detect whether the terminal supports color.
+ The color support for Chalk.
+
+ By default, color support is automatically detected based on the environment.
+
+ Levels:
+ - `0` - All colors disabled.
+ - `1` - Basic 16 colors support.
+ - `2` - ANSI 256 colors support.
+ - `3` - Truecolor 16 million colors support.
*/
- interface ColorSupport {
- /**
- The color level used by Chalk.
- */
- level: Level;
+ level: ColorSupportLevel;
- /**
- Return whether Chalk supports basic 16 colors.
- */
- hasBasic: boolean;
+ /**
+ Use HEX value to set text color.
- /**
- Return whether Chalk supports ANSI 256 colors.
- */
- has256: boolean;
+ @param color - Hexadecimal value representing the desired color.
- /**
- Return whether Chalk supports Truecolor 16 million colors.
- */
- has16m: boolean;
- }
+ @example
+ ```
+ import chalk from 'chalk';
- interface ChalkFunction {
- /**
- Use a template string.
+ chalk.hex('#DEADED');
+ ```
+ */
+ hex: (color: string) => Chalk;
- @remarks Template literals are unsupported for nested calls (see [issue #341](https://github.com/chalk/chalk/issues/341))
+ /**
+ Use keyword color value to set text color.
- @example
- ```
- import chalk = require('chalk');
+ @param color - Keyword value representing the desired color.
- log(chalk`
- CPU: {red ${cpu.totalPercent}%}
- RAM: {green ${ram.used / ram.total * 100}%}
- DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
- `);
- ```
+ @example
+ ```
+ import chalk from 'chalk';
- @example
- ```
- import chalk = require('chalk');
+ chalk.keyword('orange');
+ ```
+ */
+ keyword: (color: string) => Chalk;
- log(chalk.red.bgBlack`2 + 3 = {bold ${2 + 3}}`)
- ```
- */
- (text: TemplateStringsArray, ...placeholders: unknown[]): string;
+ /**
+ Use RGB values to set text color.
+ */
+ rgb: (red: number, green: number, blue: number) => Chalk;
- (...text: unknown[]): string;
- }
+ /**
+ Use HSL values to set text color.
+ */
+ hsl: (hue: number, saturation: number, lightness: number) => Chalk;
- interface Chalk extends ChalkFunction {
- /**
- Return a new Chalk instance.
- */
- Instance: Instance;
+ /**
+ Use HSV values to set text color.
+ */
+ hsv: (hue: number, saturation: number, value: number) => Chalk;
- /**
- The color support for Chalk.
+ /**
+ Use HWB values to set text color.
+ */
+ hwb: (hue: number, whiteness: number, blackness: number) => Chalk;
- By default, color support is automatically detected based on the environment.
+ /**
+ Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set text color.
- Levels:
- - `0` - All colors disabled.
- - `1` - Basic 16 colors support.
- - `2` - ANSI 256 colors support.
- - `3` - Truecolor 16 million colors support.
- */
- level: Level;
+ 30 <= code && code < 38 || 90 <= code && code < 98
+ For example, 31 for red, 91 for redBright.
+ */
+ ansi: (code: number) => Chalk;
- /**
- Use HEX value to set text color.
+ /**
+ Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
+ */
+ ansi256: (index: number) => Chalk;
- @param color - Hexadecimal value representing the desired color.
+ /**
+ Use HEX value to set background color.
- @example
- ```
- import chalk = require('chalk');
+ @param color - Hexadecimal value representing the desired color.
- chalk.hex('#DEADED');
- ```
- */
- hex: (color: string) => Chalk;
+ @example
+ ```
+ import chalk from 'chalk';
- /**
- Use keyword color value to set text color.
+ chalk.bgHex('#DEADED');
+ ```
+ */
+ bgHex: (color: string) => Chalk;
- @param color - Keyword value representing the desired color.
+ /**
+ Use keyword color value to set background color.
- @example
- ```
- import chalk = require('chalk');
+ @param color - Keyword value representing the desired color.
- chalk.keyword('orange');
- ```
- */
- keyword: (color: string) => Chalk;
+ @example
+ ```
+ import chalk from 'chalk';
- /**
- Use RGB values to set text color.
- */
- rgb: (red: number, green: number, blue: number) => Chalk;
+ chalk.bgKeyword('orange');
+ ```
+ */
+ bgKeyword: (color: string) => Chalk;
- /**
- Use HSL values to set text color.
- */
- hsl: (hue: number, saturation: number, lightness: number) => Chalk;
+ /**
+ Use RGB values to set background color.
+ */
+ bgRgb: (red: number, green: number, blue: number) => Chalk;
- /**
- Use HSV values to set text color.
- */
- hsv: (hue: number, saturation: number, value: number) => Chalk;
+ /**
+ Use HSL values to set background color.
+ */
+ bgHsl: (hue: number, saturation: number, lightness: number) => Chalk;
- /**
- Use HWB values to set text color.
- */
- hwb: (hue: number, whiteness: number, blackness: number) => Chalk;
+ /**
+ Use HSV values to set background color.
+ */
+ bgHsv: (hue: number, saturation: number, value: number) => Chalk;
- /**
- Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set text color.
+ /**
+ Use HWB values to set background color.
+ */
+ bgHwb: (hue: number, whiteness: number, blackness: number) => Chalk;
- 30 <= code && code < 38 || 90 <= code && code < 98
- For example, 31 for red, 91 for redBright.
- */
- ansi: (code: number) => Chalk;
+ /**
+ Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set background color.
- /**
- Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
- */
- ansi256: (index: number) => Chalk;
+ 30 <= code && code < 38 || 90 <= code && code < 98
+ For example, 31 for red, 91 for redBright.
+ Use the foreground code, not the background code (for example, not 41, nor 101).
+ */
+ bgAnsi: (code: number) => Chalk;
- /**
- Use HEX value to set background color.
+ /**
+ Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
+ */
+ bgAnsi256: (index: number) => Chalk;
- @param color - Hexadecimal value representing the desired color.
+ /**
+ Modifier: Resets the current color chain.
+ */
+ readonly reset: Chalk;
- @example
- ```
- import chalk = require('chalk');
+ /**
+ Modifier: Make text bold.
+ */
+ readonly bold: Chalk;
- chalk.bgHex('#DEADED');
- ```
- */
- bgHex: (color: string) => Chalk;
+ /**
+ Modifier: Emitting only a small amount of light.
+ */
+ readonly dim: Chalk;
- /**
- Use keyword color value to set background color.
+ /**
+ Modifier: Make text italic. (Not widely supported)
+ */
+ readonly italic: Chalk;
- @param color - Keyword value representing the desired color.
+ /**
+ Modifier: Make text underline. (Not widely supported)
+ */
+ readonly underline: Chalk;
- @example
- ```
- import chalk = require('chalk');
+ /**
+ Modifier: Inverse background and foreground colors.
+ */
+ readonly inverse: Chalk;
- chalk.bgKeyword('orange');
- ```
- */
- bgKeyword: (color: string) => Chalk;
+ /**
+ Modifier: Prints the text, but makes it invisible.
+ */
+ readonly hidden: Chalk;
- /**
- Use RGB values to set background color.
- */
- bgRgb: (red: number, green: number, blue: number) => Chalk;
+ /**
+ Modifier: Puts a horizontal line through the center of the text. (Not widely supported)
+ */
+ readonly strikethrough: Chalk;
- /**
- Use HSL values to set background color.
- */
- bgHsl: (hue: number, saturation: number, lightness: number) => Chalk;
+ /**
+ Modifier: Prints the text only when Chalk has a color support level > 0.
+ Can be useful for things that are purely cosmetic.
+ */
+ readonly visible: Chalk;
- /**
- Use HSV values to set background color.
- */
- bgHsv: (hue: number, saturation: number, value: number) => Chalk;
+ readonly black: Chalk;
+ readonly red: Chalk;
+ readonly green: Chalk;
+ readonly yellow: Chalk;
+ readonly blue: Chalk;
+ readonly magenta: Chalk;
+ readonly cyan: Chalk;
+ readonly white: Chalk;
- /**
- Use HWB values to set background color.
- */
- bgHwb: (hue: number, whiteness: number, blackness: number) => Chalk;
+ /*
+ Alias for `blackBright`.
+ */
+ readonly gray: Chalk;
- /**
- Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set background color.
+ /*
+ Alias for `blackBright`.
+ */
+ readonly grey: Chalk;
- 30 <= code && code < 38 || 90 <= code && code < 98
- For example, 31 for red, 91 for redBright.
- Use the foreground code, not the background code (for example, not 41, nor 101).
- */
- bgAnsi: (code: number) => Chalk;
+ readonly blackBright: Chalk;
+ readonly redBright: Chalk;
+ readonly greenBright: Chalk;
+ readonly yellowBright: Chalk;
+ readonly blueBright: Chalk;
+ readonly magentaBright: Chalk;
+ readonly cyanBright: Chalk;
+ readonly whiteBright: Chalk;
- /**
- Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
- */
- bgAnsi256: (index: number) => Chalk;
+ readonly bgBlack: Chalk;
+ readonly bgRed: Chalk;
+ readonly bgGreen: Chalk;
+ readonly bgYellow: Chalk;
+ readonly bgBlue: Chalk;
+ readonly bgMagenta: Chalk;
+ readonly bgCyan: Chalk;
+ readonly bgWhite: Chalk;
- /**
- Modifier: Resets the current color chain.
- */
- readonly reset: Chalk;
+ /*
+ Alias for `bgBlackBright`.
+ */
+ readonly bgGray: Chalk;
- /**
- Modifier: Make text bold.
- */
- readonly bold: Chalk;
+ /*
+ Alias for `bgBlackBright`.
+ */
+ readonly bgGrey: Chalk;
- /**
- Modifier: Emitting only a small amount of light.
- */
- readonly dim: Chalk;
-
- /**
- Modifier: Make text italic. (Not widely supported)
- */
- readonly italic: Chalk;
-
- /**
- Modifier: Make text underline. (Not widely supported)
- */
- readonly underline: Chalk;
-
- /**
- Modifier: Inverse background and foreground colors.
- */
- readonly inverse: Chalk;
-
- /**
- Modifier: Prints the text, but makes it invisible.
- */
- readonly hidden: Chalk;
-
- /**
- Modifier: Puts a horizontal line through the center of the text. (Not widely supported)
- */
- readonly strikethrough: Chalk;
-
- /**
- Modifier: Prints the text only when Chalk has a color support level > 0.
- Can be useful for things that are purely cosmetic.
- */
- readonly visible: Chalk;
-
- readonly black: Chalk;
- readonly red: Chalk;
- readonly green: Chalk;
- readonly yellow: Chalk;
- readonly blue: Chalk;
- readonly magenta: Chalk;
- readonly cyan: Chalk;
- readonly white: Chalk;
-
- /*
- Alias for `blackBright`.
- */
- readonly gray: Chalk;
-
- /*
- Alias for `blackBright`.
- */
- readonly grey: Chalk;
-
- readonly blackBright: Chalk;
- readonly redBright: Chalk;
- readonly greenBright: Chalk;
- readonly yellowBright: Chalk;
- readonly blueBright: Chalk;
- readonly magentaBright: Chalk;
- readonly cyanBright: Chalk;
- readonly whiteBright: Chalk;
-
- readonly bgBlack: Chalk;
- readonly bgRed: Chalk;
- readonly bgGreen: Chalk;
- readonly bgYellow: Chalk;
- readonly bgBlue: Chalk;
- readonly bgMagenta: Chalk;
- readonly bgCyan: Chalk;
- readonly bgWhite: Chalk;
-
- /*
- Alias for `bgBlackBright`.
- */
- readonly bgGray: Chalk;
-
- /*
- Alias for `bgBlackBright`.
- */
- readonly bgGrey: Chalk;
-
- readonly bgBlackBright: Chalk;
- readonly bgRedBright: Chalk;
- readonly bgGreenBright: Chalk;
- readonly bgYellowBright: Chalk;
- readonly bgBlueBright: Chalk;
- readonly bgMagentaBright: Chalk;
- readonly bgCyanBright: Chalk;
- readonly bgWhiteBright: Chalk;
- }
+ readonly bgBlackBright: Chalk;
+ readonly bgRedBright: Chalk;
+ readonly bgGreenBright: Chalk;
+ readonly bgYellowBright: Chalk;
+ readonly bgBlueBright: Chalk;
+ readonly bgMagentaBright: Chalk;
+ readonly bgCyanBright: Chalk;
+ readonly bgWhiteBright: Chalk;
}
/**
Main Chalk object that allows to chain styles together.
+
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`.
*/
-declare const chalk: chalk.Chalk & chalk.ChalkFunction & {
- supportsColor: chalk.ColorSupport | false;
- Level: chalk.Level;
- Color: Color;
- ForegroundColor: ForegroundColor;
- BackgroundColor: BackgroundColor;
- Modifiers: Modifiers;
- stderr: chalk.Chalk & {supportsColor: chalk.ColorSupport | false};
+declare const chalk: Chalk & ChalkFunction & {
+ supportsColor: ColorSupport | false;
+ stderr: Chalk & {supportsColor: ColorSupport | false};
};
-export = chalk;
+export default chalk;
diff --git a/index.test-d.ts b/index.test-d.ts
index ba91b63..292707e 100644
--- a/index.test-d.ts
+++ b/index.test-d.ts
@@ -1,11 +1,11 @@
import {expectType, expectAssignable, expectError} from 'tsd';
-import chalk = require('.');
+import chalk, {Chalk, Color, ColorSupport, ColorSupportLevel} from './index.js';
// - Helpers -
-type colorReturn = chalk.Chalk & {supportsColor?: never};
+type colorReturn = Chalk & {supportsColor?: never};
// - supportsColor -
-expectType(chalk.supportsColor);
+expectType(chalk.supportsColor);
if (chalk.supportsColor) {
expectType(chalk.supportsColor.hasBasic);
expectType(chalk.supportsColor.has256);
@@ -13,8 +13,8 @@ if (chalk.supportsColor) {
}
// - stderr -
-expectAssignable(chalk.stderr);
-expectType(chalk.stderr.supportsColor);
+expectAssignable(chalk.stderr);
+expectType(chalk.stderr.supportsColor);
if (chalk.stderr.supportsColor) {
expectType(chalk.stderr.supportsColor.hasBasic);
expectType(chalk.stderr.supportsColor.has256);
@@ -29,10 +29,10 @@ expectError(chalk.reset.supportsColor);
// - Chalk -
// -- Instance --
-expectType(new chalk.Instance({level: 1}));
+expectType(new chalk.Instance({level: 1}));
// -- Properties --
-expectType(chalk.level);
+expectType(chalk.level);
// -- Template literal --
expectType(chalk``);
@@ -158,5 +158,5 @@ expectType(chalk.red.bgGreen.bold`Hello {italic.blue ${name}}`);
expectType(chalk.strikethrough.cyanBright.bgBlack`Works with {reset {bold numbers}} {bold.red ${1}}`);
// -- Color types ==
-expectAssignable('red');
-expectError('hotpink');
+expectAssignable('red');
+expectError('hotpink');
diff --git a/license b/license
index e7af2f7..fa7ceba 100644
--- a/license
+++ b/license
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) Sindre Sorhus (sindresorhus.com)
+Copyright (c) Sindre Sorhus (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
diff --git a/package.json b/package.json
index 7a3bd25..9e6f031 100644
--- a/package.json
+++ b/package.json
@@ -5,9 +5,10 @@
"license": "MIT",
"repository": "chalk/chalk",
"funding": "https://github.com/chalk/chalk?sponsor=1",
- "main": "source",
+ "type": "module",
+ "exports": "./source/index.js",
"engines": {
- "node": ">=10"
+ "node": ">=12"
},
"scripts": {
"test": "xo && nyc ava && tsd",
@@ -42,26 +43,20 @@
],
"dependencies": {
"ansi-styles": "^4.1.0",
- "supports-color": "^7.1.0"
+ "supports-color": "^9.0.0"
},
"devDependencies": {
- "ava": "^2.4.0",
+ "ava": "^3.15.0",
"coveralls": "^3.1.0",
- "execa": "^4.0.3",
- "import-fresh": "^3.2.1",
+ "execa": "^5.0.0",
"matcha": "^0.7.0",
"nyc": "^15.1.0",
- "resolve-from": "^5.0.0",
- "tsd": "^0.13.1",
- "xo": "^0.33.1"
+ "tsd": "^0.14.0",
+ "xo": "^0.38.2"
},
"xo": {
"rules": {
"unicorn/prefer-string-slice": "off",
- "unicorn/prefer-includes": "off",
- "@typescript-eslint/member-ordering": "off",
- "no-redeclare": "off",
- "unicorn/string-content": "off",
"unicorn/better-regex": "off"
}
}
diff --git a/readme.md b/readme.md
index 4867321..c48056c 100644
--- a/readme.md
+++ b/readme.md
@@ -79,7 +79,7 @@ $ npm install chalk
## Usage
```js
-const chalk = require('chalk');
+import chalk from 'chalk';
console.log(chalk.blue('Hello world!'));
```
@@ -87,7 +87,8 @@ console.log(chalk.blue('Hello world!'));
Chalk comes with an easy to use composable API where you just chain and nest the styles you want.
```js
-const chalk = require('chalk');
+import chalk from 'chalk';
+
const log = console.log;
// Combine styled and normal strings
@@ -132,7 +133,7 @@ log(chalk.hex('#DEADED').bold('Bold gray!'));
Easily define your own themes:
```js
-const chalk = require('chalk');
+import chalk from 'chalk';
const error = chalk.bold.red;
const warning = chalk.keyword('orange');
@@ -144,6 +145,8 @@ console.log(warning('Warning!'));
Take advantage of console.log [string substitution](https://nodejs.org/docs/latest/api/console.html#console_console_log_data_args):
```js
+import chalk from 'chalk';
+
const name = 'Sindre';
console.log(chalk.green('Hello %s'), name);
//=> 'Hello Sindre'
@@ -168,7 +171,9 @@ Color support is automatically detected, but you can override it by setting the
If you need to change this in a reusable module, create a new instance:
```js
-const ctx = new chalk.Instance({level: 0});
+import chalk from 'chalk';
+
+const customChalk = new chalk.Instance({level: 0});
```
| Level | Description |
@@ -247,7 +252,7 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
Chalk can be used as a [tagged template literal](https://exploringjs.com/es6/ch_template-literals.html#_tagged-template-literals).
```js
-const chalk = require('chalk');
+import chalk from 'chalk';
const miles = 18;
const calculateFeet = miles => miles * 5280;
@@ -263,6 +268,8 @@ Blocks are delimited by an opening curly brace (`{`), a style, some content, and
Template styles are chained exactly like normal Chalk styles. The following three statements are equivalent:
```js
+import chalk from 'chalk';
+
console.log(chalk.bold.rgb(10, 100, 200)('Hello!'));
console.log(chalk.bold.rgb(10, 100, 200)`Hello!`);
console.log(chalk`{bold.rgb(10,100,200) Hello!}`);
diff --git a/source/index.js b/source/index.js
index 6313bde..9a9986d 100644
--- a/source/index.js
+++ b/source/index.js
@@ -1,11 +1,12 @@
-'use strict';
-const ansiStyles = require('ansi-styles');
-const {stdout: stdoutColor, stderr: stderrColor} = require('supports-color');
-const {
+import ansiStyles from 'ansi-styles';
+import supportsColor from 'supports-color';
+import {
stringReplaceAll,
stringEncaseCRLFWithFirstIndex
-} = require('./util');
+} from './util.js';
+import template from './templates.js';
+const {stdout: stdoutColor, stderr: stderrColor} = supportsColor;
const {isArray} = Array;
// `supportsColor.level` → `ansiStyles.color[name]` mapping
@@ -168,7 +169,7 @@ const applyStyle = (self, string) => {
}
const {openAll, closeAll} = styler;
- if (string.indexOf('\u001B') !== -1) {
+ if (string.includes('\u001B')) {
while (styler !== undefined) {
// Replace any instances already present with a re-opening code
// otherwise only the part of the string until said closing code
@@ -190,7 +191,6 @@ const applyStyle = (self, string) => {
return openAll + string + closeAll;
};
-let template;
const chalkTag = (chalk, ...strings) => {
const [firstString] = strings;
@@ -210,10 +210,6 @@ const chalkTag = (chalk, ...strings) => {
);
}
- if (template === undefined) {
- template = require('./templates');
- }
-
return template(chalk, parts.join(''));
};
@@ -224,4 +220,4 @@ chalk.supportsColor = stdoutColor;
chalk.stderr = Chalk({level: stderrColor ? stderrColor.level : 0}); // eslint-disable-line new-cap
chalk.stderr.supportsColor = stderrColor;
-module.exports = chalk;
+export default chalk;
diff --git a/source/templates.js b/source/templates.js
index bfdaba8..1a2f95c 100644
--- a/source/templates.js
+++ b/source/templates.js
@@ -1,4 +1,3 @@
-'use strict';
const TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
@@ -62,7 +61,7 @@ function parseStyle(style) {
if (matches[2]) {
const args = parseArguments(name, matches[2]);
- results.push([name].concat(args));
+ results.push([name, ...args]);
} else {
results.push([name]);
}
@@ -96,7 +95,7 @@ function buildStyle(chalk, styles) {
return current;
}
-module.exports = (chalk, temporary) => {
+export default function template(chalk, temporary) {
const styles = [];
const chunks = [];
let chunk = [];
@@ -126,9 +125,9 @@ module.exports = (chalk, temporary) => {
chunks.push(chunk.join(''));
if (styles.length > 0) {
- const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
- throw new Error(errMessage);
+ const errorMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
+ throw new Error(errorMessage);
}
return chunks.join('');
-};
+}
diff --git a/source/util.js b/source/util.js
index ca466fd..4d8bc4a 100644
--- a/source/util.js
+++ b/source/util.js
@@ -1,6 +1,4 @@
-'use strict';
-
-const stringReplaceAll = (string, substring, replacer) => {
+export function stringReplaceAll(string, substring, replacer) {
let index = string.indexOf(substring);
if (index === -1) {
return string;
@@ -15,11 +13,11 @@ const stringReplaceAll = (string, substring, replacer) => {
index = string.indexOf(substring, endIndex);
} while (index !== -1);
- returnValue += string.substr(endIndex);
+ returnValue += string.slice(endIndex);
return returnValue;
-};
+}
-const stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => {
+export function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
let endIndex = 0;
let returnValue = '';
do {
@@ -29,11 +27,6 @@ const stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => {
index = string.indexOf('\n', endIndex);
} while (index !== -1);
- returnValue += string.substr(endIndex);
+ returnValue += string.slice(endIndex);
return returnValue;
-};
-
-module.exports = {
- stringReplaceAll,
- stringEncaseCRLFWithFirstIndex
-};
+}
diff --git a/test/_fixture.js b/test/_fixture.js
index 29f34b0..1a8e8ba 100644
--- a/test/_fixture.js
+++ b/test/_fixture.js
@@ -1,4 +1,3 @@
-'use strict';
-const chalk = require('../source');
+import chalk from '../source/index.js';
console.log(`${chalk.hex('#ff6159')('testout')} ${chalk.stderr.hex('#ff6159')('testerr')}`);
diff --git a/test/_supports-color.js b/test/_supports-color.js
deleted file mode 100644
index b5c0f78..0000000
--- a/test/_supports-color.js
+++ /dev/null
@@ -1,21 +0,0 @@
-'use strict';
-const resolveFrom = require('resolve-from');
-
-const DEFAULT = {
- stdout: {
- level: 3,
- hasBasic: true,
- has256: true,
- has16m: true
- },
- stderr: {
- level: 3,
- hasBasic: true,
- has256: true,
- has16m: true
- }
-};
-
-module.exports = (dir, override) => {
- require.cache[resolveFrom(dir, 'supports-color')] = {exports: override || DEFAULT};
-};
diff --git a/test/chalk.js b/test/chalk.js
index 4e78565..93e9c23 100644
--- a/test/chalk.js
+++ b/test/chalk.js
@@ -1,9 +1,8 @@
import test from 'ava';
+import chalk from '../source/index.js';
-// Spoof supports-color
-require('./_supports-color')(__dirname);
-
-const chalk = require('../source');
+chalk.level = 3;
+chalk.stderr.level = 3;
console.log('TERM:', process.env.TERM || '[none]');
console.log('platform:', process.platform || '[unknown]');
diff --git a/test/constructor.js b/test/constructor.js
index f4e9ca1..78ee070 100644
--- a/test/constructor.js
+++ b/test/constructor.js
@@ -1,6 +1,5 @@
import test from 'ava';
-
-const chalk = require('../source');
+import chalk from '../source/index.js';
test('Chalk.constructor should throw an expected error', t => {
const expectedError = t.throws(() => {
diff --git a/test/instance.js b/test/instance.js
index 37c72eb..c063109 100644
--- a/test/instance.js
+++ b/test/instance.js
@@ -1,9 +1,7 @@
import test from 'ava';
+import chalk from '../source/index.js';
-// Spoof supports-color
-require('./_supports-color')(__dirname);
-
-const chalk = require('../source');
+chalk.level = 1;
test('create an isolated context where colors can be disabled (by level)', t => {
const instance = new chalk.Instance({level: 0});
diff --git a/test/level.js b/test/level.js
index 65d4720..4aab162 100644
--- a/test/level.js
+++ b/test/level.js
@@ -1,11 +1,9 @@
-import path from 'path';
+import {fileURLToPath} from 'url';
import test from 'ava';
import execa from 'execa';
+import chalk from '../source/index.js';
-// Spoof supports-color
-require('./_supports-color')(__dirname);
-
-const chalk = require('../source');
+chalk.level = 1;
test('don\'t output colors when manually disabled', t => {
const oldLevel = chalk.level;
@@ -40,6 +38,6 @@ test('propagate enable/disable changes from child colors', t => {
});
test('disable colors if they are not supported', async t => {
- const {stdout} = await execa.node(path.join(__dirname, '_fixture'));
+ const {stdout} = await execa.node(fileURLToPath(new URL('./_fixture.js', import.meta.url)));
t.is(stdout, 'testout testerr');
});
diff --git a/test/no-color-support.js b/test/no-color-support.js
index ae88ac9..0a5734d 100644
--- a/test/no-color-support.js
+++ b/test/no-color-support.js
@@ -1,22 +1,22 @@
import test from 'ava';
+import chalk from '../source/index.js';
+// TODO: Do this when ESM supports loader hooks
// Spoof supports-color
-require('./_supports-color')(__dirname, {
- stdout: {
- level: 0,
- hasBasic: false,
- has256: false,
- has16m: false
- },
- stderr: {
- level: 0,
- hasBasic: false,
- has256: false,
- has16m: false
- }
-});
-
-const chalk = require('../source');
+// require('./_supports-color')(__dirname, {
+// stdout: {
+// level: 0,
+// hasBasic: false,
+// has256: false,
+// has16m: false
+// },
+// stderr: {
+// level: 0,
+// hasBasic: false,
+// has256: false,
+// has16m: false
+// }
+// });
test('colors can be forced by using chalk.level', t => {
chalk.level = 1;
diff --git a/test/template-literal.js b/test/template-literal.js
index c918a5b..95383c4 100644
--- a/test/template-literal.js
+++ b/test/template-literal.js
@@ -1,10 +1,8 @@
/* eslint-disable unicorn/no-hex-escape */
import test from 'ava';
+import chalk from '../source/index.js';
-// Spoof supports-color
-require('./_supports-color')(__dirname);
-
-const chalk = require('../source');
+chalk.level = 1;
test('return an empty string for an empty literal', t => {
const instance = new chalk.Instance();
diff --git a/test/visible.js b/test/visible.js
index 7987712..cd9e46d 100644
--- a/test/visible.js
+++ b/test/visible.js
@@ -1,9 +1,7 @@
import test from 'ava';
+import chalk from '../source/index.js';
-// Spoof supports-color
-require('./_supports-color')(__dirname);
-
-const chalk = require('../source');
+chalk.level = 1;
test('visible: normal output when level > 0', t => {
const instance = new chalk.Instance({level: 3});
From d798222a5a3ff208782ce81f5fbd3babb286b3e3 Mon Sep 17 00:00:00 2001
From: Richie Bendall
Date: Sun, 18 Apr 2021 00:33:03 +1200
Subject: [PATCH 15/72] Add named exports (#432)
---
index.d.ts | 141 +++++++++++++++++++--------------------
index.test-d.ts | 32 ++++-----
readme.md | 10 +--
source/index.js | 25 ++++---
test/_fixture.js | 4 +-
test/chalk.js | 24 +++----
test/constructor.js | 14 ----
test/instance.js | 8 +--
test/template-literal.js | 46 ++++++-------
test/visible.js | 8 +--
10 files changed, 147 insertions(+), 165 deletions(-)
delete mode 100644 test/constructor.js
diff --git a/index.d.ts b/index.d.ts
index 268ab75..a1d2857 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -93,7 +93,7 @@ export interface Options {
/**
Return a new Chalk instance.
*/
-export type ChalkInstance = new (options?: Options) => Chalk;
+export const Chalk: new (options?: Options) => ChalkInstance;
/**
Detect whether the terminal supports color.
@@ -149,12 +149,7 @@ interface ChalkFunction {
(...text: unknown[]): string;
}
-export interface Chalk extends ChalkFunction {
- /**
- Return a new Chalk instance.
- */
- Instance: ChalkInstance;
-
+export interface ChalkInstance extends ChalkFunction {
/**
The color support for Chalk.
@@ -180,7 +175,7 @@ export interface Chalk extends ChalkFunction {
chalk.hex('#DEADED');
```
*/
- hex: (color: string) => Chalk;
+ hex: (color: string) => this;
/**
Use keyword color value to set text color.
@@ -194,27 +189,27 @@ export interface Chalk extends ChalkFunction {
chalk.keyword('orange');
```
*/
- keyword: (color: string) => Chalk;
+ keyword: (color: string) => this;
/**
Use RGB values to set text color.
*/
- rgb: (red: number, green: number, blue: number) => Chalk;
+ rgb: (red: number, green: number, blue: number) => this;
/**
Use HSL values to set text color.
*/
- hsl: (hue: number, saturation: number, lightness: number) => Chalk;
+ hsl: (hue: number, saturation: number, lightness: number) => this;
/**
Use HSV values to set text color.
*/
- hsv: (hue: number, saturation: number, value: number) => Chalk;
+ hsv: (hue: number, saturation: number, value: number) => this;
/**
Use HWB values to set text color.
*/
- hwb: (hue: number, whiteness: number, blackness: number) => Chalk;
+ hwb: (hue: number, whiteness: number, blackness: number) => this;
/**
Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set text color.
@@ -222,12 +217,12 @@ export interface Chalk extends ChalkFunction {
30 <= code && code < 38 || 90 <= code && code < 98
For example, 31 for red, 91 for redBright.
*/
- ansi: (code: number) => Chalk;
+ ansi: (code: number) => this;
/**
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
*/
- ansi256: (index: number) => Chalk;
+ ansi256: (index: number) => this;
/**
Use HEX value to set background color.
@@ -241,7 +236,7 @@ export interface Chalk extends ChalkFunction {
chalk.bgHex('#DEADED');
```
*/
- bgHex: (color: string) => Chalk;
+ bgHex: (color: string) => this;
/**
Use keyword color value to set background color.
@@ -255,27 +250,27 @@ export interface Chalk extends ChalkFunction {
chalk.bgKeyword('orange');
```
*/
- bgKeyword: (color: string) => Chalk;
+ bgKeyword: (color: string) => this;
/**
Use RGB values to set background color.
*/
- bgRgb: (red: number, green: number, blue: number) => Chalk;
+ bgRgb: (red: number, green: number, blue: number) => this;
/**
Use HSL values to set background color.
*/
- bgHsl: (hue: number, saturation: number, lightness: number) => Chalk;
+ bgHsl: (hue: number, saturation: number, lightness: number) => this;
/**
Use HSV values to set background color.
*/
- bgHsv: (hue: number, saturation: number, value: number) => Chalk;
+ bgHsv: (hue: number, saturation: number, value: number) => this;
/**
Use HWB values to set background color.
*/
- bgHwb: (hue: number, whiteness: number, blackness: number) => Chalk;
+ bgHwb: (hue: number, whiteness: number, blackness: number) => this;
/**
Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set background color.
@@ -284,114 +279,114 @@ export interface Chalk extends ChalkFunction {
For example, 31 for red, 91 for redBright.
Use the foreground code, not the background code (for example, not 41, nor 101).
*/
- bgAnsi: (code: number) => Chalk;
+ bgAnsi: (code: number) => this;
/**
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
*/
- bgAnsi256: (index: number) => Chalk;
+ bgAnsi256: (index: number) => this;
/**
Modifier: Resets the current color chain.
*/
- readonly reset: Chalk;
+ readonly reset: this;
/**
Modifier: Make text bold.
*/
- readonly bold: Chalk;
+ readonly bold: this;
/**
Modifier: Emitting only a small amount of light.
*/
- readonly dim: Chalk;
+ readonly dim: this;
/**
Modifier: Make text italic. (Not widely supported)
*/
- readonly italic: Chalk;
+ readonly italic: this;
/**
Modifier: Make text underline. (Not widely supported)
*/
- readonly underline: Chalk;
+ readonly underline: this;
/**
Modifier: Inverse background and foreground colors.
*/
- readonly inverse: Chalk;
+ readonly inverse: this;
/**
Modifier: Prints the text, but makes it invisible.
*/
- readonly hidden: Chalk;
+ readonly hidden: this;
/**
Modifier: Puts a horizontal line through the center of the text. (Not widely supported)
*/
- readonly strikethrough: Chalk;
+ readonly strikethrough: this;
/**
Modifier: Prints the text only when Chalk has a color support level > 0.
Can be useful for things that are purely cosmetic.
*/
- readonly visible: Chalk;
+ readonly visible: this;
- readonly black: Chalk;
- readonly red: Chalk;
- readonly green: Chalk;
- readonly yellow: Chalk;
- readonly blue: Chalk;
- readonly magenta: Chalk;
- readonly cyan: Chalk;
- readonly white: Chalk;
+ readonly black: this;
+ readonly red: this;
+ readonly green: this;
+ readonly yellow: this;
+ readonly blue: this;
+ readonly magenta: this;
+ readonly cyan: this;
+ readonly white: this;
/*
Alias for `blackBright`.
*/
- readonly gray: Chalk;
+ readonly gray: this;
/*
Alias for `blackBright`.
*/
- readonly grey: Chalk;
+ readonly grey: this;
- readonly blackBright: Chalk;
- readonly redBright: Chalk;
- readonly greenBright: Chalk;
- readonly yellowBright: Chalk;
- readonly blueBright: Chalk;
- readonly magentaBright: Chalk;
- readonly cyanBright: Chalk;
- readonly whiteBright: Chalk;
+ readonly blackBright: this;
+ readonly redBright: this;
+ readonly greenBright: this;
+ readonly yellowBright: this;
+ readonly blueBright: this;
+ readonly magentaBright: this;
+ readonly cyanBright: this;
+ readonly whiteBright: this;
- readonly bgBlack: Chalk;
- readonly bgRed: Chalk;
- readonly bgGreen: Chalk;
- readonly bgYellow: Chalk;
- readonly bgBlue: Chalk;
- readonly bgMagenta: Chalk;
- readonly bgCyan: Chalk;
- readonly bgWhite: Chalk;
+ readonly bgBlack: this;
+ readonly bgRed: this;
+ readonly bgGreen: this;
+ readonly bgYellow: this;
+ readonly bgBlue: this;
+ readonly bgMagenta: this;
+ readonly bgCyan: this;
+ readonly bgWhite: this;
/*
Alias for `bgBlackBright`.
*/
- readonly bgGray: Chalk;
+ readonly bgGray: this;
/*
Alias for `bgBlackBright`.
*/
- readonly bgGrey: Chalk;
+ readonly bgGrey: this;
- readonly bgBlackBright: Chalk;
- readonly bgRedBright: Chalk;
- readonly bgGreenBright: Chalk;
- readonly bgYellowBright: Chalk;
- readonly bgBlueBright: Chalk;
- readonly bgMagentaBright: Chalk;
- readonly bgCyanBright: Chalk;
- readonly bgWhiteBright: Chalk;
+ readonly bgBlackBright: this;
+ readonly bgRedBright: this;
+ readonly bgGreenBright: this;
+ readonly bgYellowBright: this;
+ readonly bgBlueBright: this;
+ readonly bgMagentaBright: this;
+ readonly bgCyanBright: this;
+ readonly bgWhiteBright: this;
}
/**
@@ -403,9 +398,11 @@ 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`.
*/
-declare const chalk: Chalk & ChalkFunction & {
- supportsColor: ColorSupport | false;
- stderr: Chalk & {supportsColor: ColorSupport | false};
-};
+declare const chalk: ChalkInstance & ChalkFunction;
+
+export const supportsColor: ColorSupport | false;
+
+export const chalkStderr: typeof chalk;
+export const supportsColorStderr: typeof supportsColor;
export default chalk;
diff --git a/index.test-d.ts b/index.test-d.ts
index 292707e..3e7e2d6 100644
--- a/index.test-d.ts
+++ b/index.test-d.ts
@@ -1,35 +1,35 @@
import {expectType, expectAssignable, expectError} from 'tsd';
-import chalk, {Chalk, Color, ColorSupport, ColorSupportLevel} from './index.js';
+import chalk, {Chalk, ChalkInstance, Color, ColorSupport, ColorSupportLevel, chalkStderr, supportsColor, supportsColorStderr} from './index.js';
// - Helpers -
-type colorReturn = Chalk & {supportsColor?: never};
+type colorReturn = ChalkInstance & {supportsColor?: never};
// - supportsColor -
-expectType(chalk.supportsColor);
-if (chalk.supportsColor) {
- expectType(chalk.supportsColor.hasBasic);
- expectType(chalk.supportsColor.has256);
- expectType(chalk.supportsColor.has16m);
+expectType(supportsColor);
+if (supportsColor) {
+ expectType(supportsColor.hasBasic);
+ expectType(supportsColor.has256);
+ expectType(supportsColor.has16m);
}
// - stderr -
-expectAssignable(chalk.stderr);
-expectType(chalk.stderr.supportsColor);
-if (chalk.stderr.supportsColor) {
- expectType(chalk.stderr.supportsColor.hasBasic);
- expectType(chalk.stderr.supportsColor.has256);
- expectType(chalk.stderr.supportsColor.has16m);
+expectAssignable(chalkStderr);
+expectType(supportsColorStderr);
+if (supportsColorStderr) {
+ expectType(supportsColorStderr.hasBasic);
+ expectType(supportsColorStderr.has256);
+ expectType(supportsColorStderr.has16m);
}
-// -- `stderr` is not a member of the Chalk interface --
-expectError(chalk.reset.stderr);
+// -- `supportsColorStderr` is not a member of the Chalk interface --
+expectError(chalk.reset.supportsColorStderr);
// -- `supportsColor` is not a member of the Chalk interface --
expectError(chalk.reset.supportsColor);
// - Chalk -
// -- Instance --
-expectType(new chalk.Instance({level: 1}));
+expectType(new Chalk({level: 1}));
// -- Properties --
expectType(chalk.level);
diff --git a/readme.md b/readme.md
index c48056c..45e4be7 100644
--- a/readme.md
+++ b/readme.md
@@ -171,9 +171,9 @@ Color support is automatically detected, but you can override it by setting the
If you need to change this in a reusable module, create a new instance:
```js
-import chalk from 'chalk';
+import {Chalk} from 'chalk';
-const customChalk = new chalk.Instance({level: 0});
+const customChalk = new Chalk({level: 0});
```
| Level | Description |
@@ -183,7 +183,7 @@ const customChalk = new chalk.Instance({level: 0});
| `2` | 256 color support |
| `3` | Truecolor support (16 million colors) |
-### chalk.supportsColor
+### supportsColor
Detect whether the terminal [supports color](https://github.com/chalk/supports-color). Used internally and handled for you, but exposed for convenience.
@@ -191,9 +191,9 @@ Can be overridden by the user with the flags `--color` and `--no-color`. For sit
Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
-### chalk.stderr and chalk.stderr.supportsColor
+### chalkStderr and supportsColorStderr
-`chalk.stderr` contains a separate instance configured with color support detected for `stderr` stream instead of `stdout`. Override rules from `chalk.supportsColor` apply to this too. `chalk.stderr.supportsColor` is exposed for convenience.
+`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.
## Styles
diff --git a/source/index.js b/source/index.js
index 9a9986d..0f159d4 100644
--- a/source/index.js
+++ b/source/index.js
@@ -29,7 +29,7 @@ const applyOptions = (object, options = {}) => {
object.level = options.level === undefined ? colorLevel : options.level;
};
-class ChalkClass {
+export class Chalk {
constructor(options) {
// eslint-disable-next-line no-constructor-return
return chalkFactory(options);
@@ -42,19 +42,15 @@ const chalkFactory = options => {
chalk.template = (...arguments_) => chalkTag(chalk.template, ...arguments_);
- Object.setPrototypeOf(chalk, Chalk.prototype);
+ Object.setPrototypeOf(chalk, createChalk.prototype);
Object.setPrototypeOf(chalk.template, chalk);
- chalk.template.constructor = () => {
- throw new Error('`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.');
- };
-
- chalk.template.Instance = ChalkClass;
+ chalk.template.Chalk = Chalk;
return chalk.template;
};
-function Chalk(options) {
+function createChalk(options) {
return chalkFactory(options);
}
@@ -213,11 +209,14 @@ const chalkTag = (chalk, ...strings) => {
return template(chalk, parts.join(''));
};
-Object.defineProperties(Chalk.prototype, styles);
+Object.defineProperties(createChalk.prototype, styles);
-const chalk = Chalk(); // eslint-disable-line new-cap
-chalk.supportsColor = stdoutColor;
-chalk.stderr = Chalk({level: stderrColor ? stderrColor.level : 0}); // eslint-disable-line new-cap
-chalk.stderr.supportsColor = stderrColor;
+const chalk = createChalk();
+export const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0});
+
+export {
+ stdoutColor as supportsColor,
+ stderrColor as supportsColorStderr
+};
export default chalk;
diff --git a/test/_fixture.js b/test/_fixture.js
index 1a8e8ba..c3e5b15 100644
--- a/test/_fixture.js
+++ b/test/_fixture.js
@@ -1,3 +1,3 @@
-import chalk from '../source/index.js';
+import chalk, {chalkStderr} from '../source/index.js';
-console.log(`${chalk.hex('#ff6159')('testout')} ${chalk.stderr.hex('#ff6159')('testerr')}`);
+console.log(`${chalk.hex('#ff6159')('testout')} ${chalkStderr.hex('#ff6159')('testerr')}`);
diff --git a/test/chalk.js b/test/chalk.js
index 93e9c23..adc1aed 100644
--- a/test/chalk.js
+++ b/test/chalk.js
@@ -1,8 +1,8 @@
import test from 'ava';
-import chalk from '../source/index.js';
+import chalk, {Chalk, chalkStderr} from '../source/index.js';
chalk.level = 3;
-chalk.stderr.level = 3;
+chalkStderr.level = 3;
console.log('TERM:', process.env.TERM || '[none]');
console.log('platform:', process.platform || '[unknown]');
@@ -94,26 +94,26 @@ test('line breaks should open and close colors with CRLF', t => {
});
test('properly convert RGB to 16 colors on basic color terminals', t => {
- t.is(new chalk.Instance({level: 1}).hex('#FF0000')('hello'), '\u001B[91mhello\u001B[39m');
- t.is(new chalk.Instance({level: 1}).bgHex('#FF0000')('hello'), '\u001B[101mhello\u001B[49m');
+ t.is(new Chalk({level: 1}).hex('#FF0000')('hello'), '\u001B[91mhello\u001B[39m');
+ t.is(new Chalk({level: 1}).bgHex('#FF0000')('hello'), '\u001B[101mhello\u001B[49m');
});
test('properly convert RGB to 256 colors on basic color terminals', t => {
- t.is(new chalk.Instance({level: 2}).hex('#FF0000')('hello'), '\u001B[38;5;196mhello\u001B[39m');
- t.is(new chalk.Instance({level: 2}).bgHex('#FF0000')('hello'), '\u001B[48;5;196mhello\u001B[49m');
- t.is(new chalk.Instance({level: 3}).bgHex('#FF0000')('hello'), '\u001B[48;2;255;0;0mhello\u001B[49m');
+ t.is(new Chalk({level: 2}).hex('#FF0000')('hello'), '\u001B[38;5;196mhello\u001B[39m');
+ t.is(new Chalk({level: 2}).bgHex('#FF0000')('hello'), '\u001B[48;5;196mhello\u001B[49m');
+ t.is(new Chalk({level: 3}).bgHex('#FF0000')('hello'), '\u001B[48;2;255;0;0mhello\u001B[49m');
});
test('don\'t emit RGB codes if level is 0', t => {
- t.is(new chalk.Instance({level: 0}).hex('#FF0000')('hello'), 'hello');
- t.is(new chalk.Instance({level: 0}).bgHex('#FF0000')('hello'), 'hello');
+ t.is(new Chalk({level: 0}).hex('#FF0000')('hello'), 'hello');
+ t.is(new Chalk({level: 0}).bgHex('#FF0000')('hello'), 'hello');
});
test('supports blackBright color', t => {
t.is(chalk.blackBright('foo'), '\u001B[90mfoo\u001B[39m');
});
-test('sets correct level for chalk.stderr and respects it', t => {
- t.is(chalk.stderr.level, 3);
- t.is(chalk.stderr.red.bold('foo'), '\u001B[31m\u001B[1mfoo\u001B[22m\u001B[39m');
+test('sets correct level for chalkStderr and respects it', t => {
+ t.is(chalkStderr.level, 3);
+ t.is(chalkStderr.red.bold('foo'), '\u001B[31m\u001B[1mfoo\u001B[22m\u001B[39m');
});
diff --git a/test/constructor.js b/test/constructor.js
deleted file mode 100644
index 78ee070..0000000
--- a/test/constructor.js
+++ /dev/null
@@ -1,14 +0,0 @@
-import test from 'ava';
-import chalk from '../source/index.js';
-
-test('Chalk.constructor should throw an expected error', t => {
- const expectedError = t.throws(() => {
- chalk.constructor();
- });
-
- t.is(expectedError.message, '`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.');
-
- t.throws(() => {
- new chalk.constructor(); // eslint-disable-line no-new
- });
-});
diff --git a/test/instance.js b/test/instance.js
index c063109..c3cc70b 100644
--- a/test/instance.js
+++ b/test/instance.js
@@ -1,10 +1,10 @@
import test from 'ava';
-import chalk from '../source/index.js';
+import chalk, {Chalk} from '../source/index.js';
chalk.level = 1;
test('create an isolated context where colors can be disabled (by level)', t => {
- const instance = new chalk.Instance({level: 0});
+ const instance = new Chalk({level: 0});
t.is(instance.red('foo'), 'foo');
t.is(chalk.red('foo'), '\u001B[31mfoo\u001B[39m');
instance.level = 2;
@@ -14,11 +14,11 @@ test('create an isolated context where colors can be disabled (by level)', t =>
test('the `level` option should be a number from 0 to 3', t => {
/* eslint-disable no-new */
t.throws(() => {
- new chalk.Instance({level: 10});
+ new Chalk({level: 10});
}, {message: /should be an integer from 0 to 3/});
t.throws(() => {
- new chalk.Instance({level: -1});
+ new Chalk({level: -1});
}, {message: /should be an integer from 0 to 3/});
/* eslint-enable no-new */
});
diff --git a/test/template-literal.js b/test/template-literal.js
index 95383c4..773e097 100644
--- a/test/template-literal.js
+++ b/test/template-literal.js
@@ -1,27 +1,27 @@
/* eslint-disable unicorn/no-hex-escape */
import test from 'ava';
-import chalk from '../source/index.js';
+import chalk, {Chalk} from '../source/index.js';
chalk.level = 1;
test('return an empty string for an empty literal', t => {
- const instance = new chalk.Instance();
+ const instance = new Chalk();
t.is(instance``, '');
});
test('return a regular string for a literal with no templates', t => {
- const instance = new chalk.Instance({level: 0});
+ const instance = new Chalk({level: 0});
t.is(instance`hello`, 'hello');
});
test('correctly perform template parsing', t => {
- const instance = new chalk.Instance({level: 0});
+ const instance = new Chalk({level: 0});
t.is(instance`{bold Hello, {cyan World!} This is a} test. {green Woo!}`,
instance.bold('Hello,', instance.cyan('World!'), 'This is a') + ' test. ' + instance.green('Woo!'));
});
test('correctly perform template substitutions', t => {
- const instance = new chalk.Instance({level: 0});
+ const instance = new Chalk({level: 0});
const name = 'Sindre';
const exclamation = 'Neat';
t.is(instance`{bold Hello, {cyan.inverse ${name}!} This is a} test. {green ${exclamation}!}`,
@@ -29,7 +29,7 @@ test('correctly perform template substitutions', t => {
});
test('correctly perform nested template substitutions', t => {
- const instance = new chalk.Instance({level: 0});
+ const instance = new Chalk({level: 0});
const name = 'Sindre';
const exclamation = 'Neat';
t.is(instance.bold`Hello, {cyan.inverse ${name}!} This is a` + ' test. ' + instance.green`${exclamation}!`,
@@ -48,7 +48,7 @@ test('correctly perform nested template substitutions', t => {
});
test('correctly parse and evaluate color-convert functions', t => {
- const instance = new chalk.Instance({level: 3});
+ const instance = new Chalk({level: 3});
t.is(instance`{bold.rgb(144,10,178).inverse Hello, {~inverse there!}}`,
'\u001B[1m\u001B[38;2;144;10;178m\u001B[7mHello, ' +
'\u001B[27m\u001B[39m\u001B[22m\u001B[1m' +
@@ -61,13 +61,13 @@ test('correctly parse and evaluate color-convert functions', t => {
});
test('properly handle escapes', t => {
- const instance = new chalk.Instance({level: 3});
+ const instance = new Chalk({level: 3});
t.is(instance`{bold hello \{in brackets\}}`,
'\u001B[1mhello {in brackets}\u001B[22m');
});
test('throw if there is an unclosed block', t => {
- const instance = new chalk.Instance({level: 3});
+ const instance = new Chalk({level: 3});
try {
console.log(instance`{bold this shouldn't appear ever\}`);
t.fail();
@@ -84,7 +84,7 @@ test('throw if there is an unclosed block', t => {
});
test('throw if there is an invalid style', t => {
- const instance = new chalk.Instance({level: 3});
+ const instance = new Chalk({level: 3});
try {
console.log(instance`{abadstylethatdoesntexist this shouldn't appear ever}`);
t.fail();
@@ -94,7 +94,7 @@ test('throw if there is an invalid style', t => {
});
test('properly style multiline color blocks', t => {
- const instance = new chalk.Instance({level: 3});
+ const instance = new Chalk({level: 3});
t.is(
instance`{bold
Hello! This is a
@@ -114,49 +114,49 @@ test('properly style multiline color blocks', t => {
});
test('escape interpolated values', t => {
- const instance = new chalk.Instance({level: 0});
+ const instance = new Chalk({level: 0});
t.is(instance`Hello {bold hi}`, 'Hello hi');
t.is(instance`Hello ${'{bold hi}'}`, 'Hello {bold hi}');
});
test('allow custom colors (themes) on custom contexts', t => {
- const instance = new chalk.Instance({level: 3});
+ const instance = new Chalk({level: 3});
instance.rose = instance.hex('#F6D9D9');
t.is(instance`Hello, {rose Rose}.`, 'Hello, \u001B[38;2;246;217;217mRose\u001B[39m.');
});
test('correctly parse newline literals (bug #184)', t => {
- const instance = new chalk.Instance({level: 0});
+ const instance = new Chalk({level: 0});
t.is(instance`Hello
{red there}`, 'Hello\nthere');
});
test('correctly parse newline escapes (bug #177)', t => {
- const instance = new chalk.Instance({level: 0});
+ const instance = new Chalk({level: 0});
t.is(instance`Hello\nthere!`, 'Hello\nthere!');
});
test('correctly parse escape in parameters (bug #177 comment 318622809)', t => {
- const instance = new chalk.Instance({level: 0});
+ const instance = new Chalk({level: 0});
const string = '\\';
t.is(instance`{blue ${string}}`, '\\');
});
test('correctly parses unicode/hex escapes', t => {
- const instance = new chalk.Instance({level: 0});
+ const instance = new Chalk({level: 0});
t.is(instance`\u0078ylophones are fo\x78y! {magenta.inverse \u0078ylophones are fo\x78y!}`,
'xylophones are foxy! xylophones are foxy!');
});
test('correctly parses string arguments', t => {
- const instance = new chalk.Instance({level: 3});
+ const instance = new Chalk({level: 3});
t.is(instance`{keyword('black').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
t.is(instance`{keyword('blac\x6B').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
t.is(instance`{keyword('blac\u006B').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
});
test('throws if a bad argument is encountered', t => {
- const instance = new chalk.Instance({level: 3}); // Keep level at least 1 in case we optimize for disabled chalk instances
+ const instance = new Chalk({level: 3}); // Keep level at least 1 in case we optimize for disabled chalk instances
try {
console.log(instance`{keyword(????) hi}`);
t.fail();
@@ -166,7 +166,7 @@ test('throws if a bad argument is encountered', t => {
});
test('throws if an extra unescaped } is found', t => {
- const instance = new chalk.Instance({level: 0});
+ const instance = new Chalk({level: 0});
try {
console.log(instance`{red hi!}}`);
t.fail();
@@ -176,18 +176,18 @@ test('throws if an extra unescaped } is found', t => {
});
test('should not parse upper-case escapes', t => {
- const instance = new chalk.Instance({level: 0});
+ const instance = new Chalk({level: 0});
t.is(instance`\N\n\T\t\X07\x07\U000A\u000A\U000a\u000A`, 'N\nT\tX07\x07U000A\u000AU000a\u000A');
});
test('should properly handle undefined template interpolated values', t => {
- const instance = new chalk.Instance({level: 0});
+ const instance = new Chalk({level: 0});
t.is(instance`hello ${undefined}`, 'hello undefined');
t.is(instance`hello ${null}`, 'hello null');
});
test('should allow bracketed Unicode escapes', t => {
- const instance = new chalk.Instance({level: 3});
+ const instance = new Chalk({level: 3});
t.is(instance`\u{AB}`, '\u{AB}');
t.is(instance`This is a {bold \u{AB681}} test`, 'This is a \u001B[1m\u{AB681}\u001B[22m test');
t.is(instance`This is a {bold \u{10FFFF}} test`, 'This is a \u001B[1m\u{10FFFF}\u001B[22m test');
diff --git a/test/visible.js b/test/visible.js
index cd9e46d..4d34af8 100644
--- a/test/visible.js
+++ b/test/visible.js
@@ -1,22 +1,22 @@
import test from 'ava';
-import chalk from '../source/index.js';
+import chalk, {Chalk} from '../source/index.js';
chalk.level = 1;
test('visible: normal output when level > 0', t => {
- const instance = new chalk.Instance({level: 3});
+ const instance = new Chalk({level: 3});
t.is(instance.visible.red('foo'), '\u001B[31mfoo\u001B[39m');
t.is(instance.red.visible('foo'), '\u001B[31mfoo\u001B[39m');
});
test('visible: no output when level is too low', t => {
- const instance = new chalk.Instance({level: 0});
+ const instance = new Chalk({level: 0});
t.is(instance.visible.red('foo'), '');
t.is(instance.red.visible('foo'), '');
});
test('test switching back and forth between level == 0 and level > 0', t => {
- const instance = new chalk.Instance({level: 3});
+ const instance = new Chalk({level: 3});
t.is(instance.red('foo'), '\u001B[31mfoo\u001B[39m');
t.is(instance.visible.red('foo'), '\u001B[31mfoo\u001B[39m');
t.is(instance.red.visible('foo'), '\u001B[31mfoo\u001B[39m');
From 0fba91b0373c86800c45096ad215d38481f49614 Mon Sep 17 00:00:00 2001
From: Richie Bendall
Date: Tue, 20 Apr 2021 18:48:30 +1200
Subject: [PATCH 16/72] Keep function prototype methods (#434)
---
source/index.js | 2 ++
test/chalk.js | 6 ++++++
2 files changed, 8 insertions(+)
diff --git a/source/index.js b/source/index.js
index 0f159d4..8db69d2 100644
--- a/source/index.js
+++ b/source/index.js
@@ -54,6 +54,8 @@ function createChalk(options) {
return chalkFactory(options);
}
+Object.setPrototypeOf(createChalk.prototype, Function.prototype);
+
for (const [styleName, style] of Object.entries(ansiStyles)) {
styles[styleName] = {
get() {
diff --git a/test/chalk.js b/test/chalk.js
index adc1aed..af43558 100644
--- a/test/chalk.js
+++ b/test/chalk.js
@@ -117,3 +117,9 @@ test('sets correct level for chalkStderr and respects it', t => {
t.is(chalkStderr.level, 3);
t.is(chalkStderr.red.bold('foo'), '\u001B[31m\u001B[1mfoo\u001B[22m\u001B[39m');
});
+
+test('keeps function prototype methods', t => {
+ t.is(chalk.apply(chalk, ['foo']), 'foo');
+ t.is(chalk.bind(chalk, 'foo')(), 'foo');
+ t.is(chalk.call(chalk, 'foo'), 'foo');
+});
From 89e9e3a5b0601f4eda4c3a92acd887ec836d0175 Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Wed, 21 Apr 2021 15:53:26 +0700
Subject: [PATCH 17/72] 4.1.1 - Add sponsors
---
package.json | 2 +-
readme.md | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 0d99f0f..c2d63f6 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "chalk",
- "version": "4.1.0",
+ "version": "4.1.1",
"description": "Terminal string styling done right",
"license": "MIT",
"repository": "chalk/chalk",
diff --git a/readme.md b/readme.md
index 338f42c..8512592 100644
--- a/readme.md
+++ b/readme.md
@@ -13,6 +13,48 @@
+
+
+---
+
+
+
+---
+
+
+
## Highlights
- Expressive API
From 4cf2e40e0739d4f5a3f1cd235b0e05e979bc5f34 Mon Sep 17 00:00:00 2001
From: Richie Bendall
Date: Thu, 22 Apr 2021 15:54:42 +1200
Subject: [PATCH 18/72] Add `overline` style and remove `keyword`, `hsl`,
`hsv`, `hwb` and `ansi` color spaces (#433)
---
examples/rainbow.js | 14 +++---
examples/screenshot.js | 2 +-
index.d.ts | 103 +++++++--------------------------------
index.test-d.ts | 15 ++----
package.json | 7 ++-
readme.md | 14 ++----
source/index.js | 26 ++++++++--
test/template-literal.js | 10 ++--
8 files changed, 63 insertions(+), 128 deletions(-)
diff --git a/examples/rainbow.js b/examples/rainbow.js
index 67dd236..9ea1d72 100644
--- a/examples/rainbow.js
+++ b/examples/rainbow.js
@@ -1,11 +1,10 @@
-import chalk from '../index.js';
+import chalk from '../source/index.js';
+import convertColor from 'color-convert';
+import updateLog from 'log-update';
+import delay from 'yoctodelay';
const ignoreChars = /[^!-~]/g;
-const delay = milliseconds => new Promise(resolve => {
- setTimeout(resolve, milliseconds);
-});
-
function rainbow(string, offset) {
if (!string || string.length === 0) {
return string;
@@ -19,7 +18,7 @@ function rainbow(string, offset) {
if (ignoreChars.test(character)) {
characters.push(character);
} else {
- characters.push(chalk.hsl(hue, 100, 50)(character));
+ characters.push(chalk.hex(convertColor.hsl.hex(hue, 100, 50))(character));
hue = (hue + hueStep) % 360;
}
}
@@ -28,9 +27,8 @@ function rainbow(string, offset) {
}
async function animateString(string) {
- console.log();
for (let index = 0; index < 360 * 5; index++) {
- console.log('\u001B[1F\u001B[G', rainbow(string, index));
+ updateLog(rainbow(string, index));
await delay(2); // eslint-disable-line no-await-in-loop
}
}
diff --git a/examples/screenshot.js b/examples/screenshot.js
index ea61e0c..6d5ed15 100644
--- a/examples/screenshot.js
+++ b/examples/screenshot.js
@@ -1,5 +1,5 @@
import styles from 'ansi-styles';
-import chalk from '../index.js';
+import chalk from '../source/index.js';
// Generates screenshot
for (const key of Object.keys(styles)) {
diff --git a/index.d.ts b/index.d.ts
index a1d2857..a21fa89 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -61,6 +61,7 @@ export type Modifiers =
| 'dim'
| 'italic'
| 'underline'
+ | 'overline'
| 'inverse'
| 'hidden'
| 'strikethrough'
@@ -163,6 +164,11 @@ export interface ChalkInstance extends ChalkFunction {
*/
level: ColorSupportLevel;
+ /**
+ Use RGB values to set text color.
+ */
+ rgb: (red: number, green: number, blue: number) => this;
+
/**
Use HEX value to set text color.
@@ -178,52 +184,15 @@ export interface ChalkInstance extends ChalkFunction {
hex: (color: string) => this;
/**
- Use keyword color value to set text color.
-
- @param color - Keyword value representing the desired color.
-
- @example
- ```
- import chalk from 'chalk';
-
- chalk.keyword('orange');
- ```
- */
- keyword: (color: string) => this;
-
- /**
- Use RGB values to set text color.
- */
- rgb: (red: number, green: number, blue: number) => this;
-
- /**
- Use HSL values to set text color.
- */
- hsl: (hue: number, saturation: number, lightness: number) => this;
-
- /**
- Use HSV values to set text color.
- */
- hsv: (hue: number, saturation: number, value: number) => this;
-
- /**
- Use HWB values to set text color.
- */
- hwb: (hue: number, whiteness: number, blackness: number) => this;
-
- /**
- Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set text color.
-
- 30 <= code && code < 38 || 90 <= code && code < 98
- For example, 31 for red, 91 for redBright.
- */
- ansi: (code: number) => this;
-
- /**
- Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
+ Use an [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
*/
ansi256: (index: number) => this;
+ /**
+ Use RGB values to set background color.
+ */
+ bgRgb: (red: number, green: number, blue: number) => this;
+
/**
Use HEX value to set background color.
@@ -238,49 +207,6 @@ export interface ChalkInstance extends ChalkFunction {
*/
bgHex: (color: string) => this;
- /**
- Use keyword color value to set background color.
-
- @param color - Keyword value representing the desired color.
-
- @example
- ```
- import chalk from 'chalk';
-
- chalk.bgKeyword('orange');
- ```
- */
- bgKeyword: (color: string) => this;
-
- /**
- Use RGB values to set background color.
- */
- bgRgb: (red: number, green: number, blue: number) => this;
-
- /**
- Use HSL values to set background color.
- */
- bgHsl: (hue: number, saturation: number, lightness: number) => this;
-
- /**
- Use HSV values to set background color.
- */
- bgHsv: (hue: number, saturation: number, value: number) => this;
-
- /**
- Use HWB values to set background color.
- */
- bgHwb: (hue: number, whiteness: number, blackness: number) => this;
-
- /**
- Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set background color.
-
- 30 <= code && code < 38 || 90 <= code && code < 98
- For example, 31 for red, 91 for redBright.
- Use the foreground code, not the background code (for example, not 41, nor 101).
- */
- bgAnsi: (code: number) => this;
-
/**
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
*/
@@ -311,6 +237,11 @@ export interface ChalkInstance extends ChalkFunction {
*/
readonly underline: this;
+ /**
+ Modifier: Make text overline. (Not widely supported)
+ */
+ readonly overline: this;
+
/**
Modifier: Inverse background and foreground colors.
*/
diff --git a/index.test-d.ts b/index.test-d.ts
index 3e7e2d6..45299d6 100644
--- a/index.test-d.ts
+++ b/index.test-d.ts
@@ -41,21 +41,11 @@ expectType(chalk`Hello {bold.red ${name}}`);
expectType(chalk`Works with numbers {bold.red ${1}}`);
// -- Color methods --
-expectAssignable(chalk.hex('#DEADED'));
-expectAssignable(chalk.keyword('orange'));
expectAssignable(chalk.rgb(0, 0, 0));
-expectAssignable(chalk.hsl(0, 0, 0));
-expectAssignable(chalk.hsv(0, 0, 0));
-expectAssignable(chalk.hwb(0, 0, 0));
-expectAssignable(chalk.ansi(30));
+expectAssignable(chalk.hex('#DEADED'));
expectAssignable(chalk.ansi256(0));
-expectAssignable(chalk.bgHex('#DEADED'));
-expectAssignable(chalk.bgKeyword('orange'));
expectAssignable(chalk.bgRgb(0, 0, 0));
-expectAssignable(chalk.bgHsl(0, 0, 0));
-expectAssignable(chalk.bgHsv(0, 0, 0));
-expectAssignable(chalk.bgHwb(0, 0, 0));
-expectAssignable(chalk.bgAnsi(30));
+expectAssignable(chalk.bgHex('#DEADED'));
expectAssignable(chalk.bgAnsi256(0));
// -- Modifiers --
@@ -64,6 +54,7 @@ expectType(chalk.bold('foo'));
expectType(chalk.dim('foo'));
expectType(chalk.italic('foo'));
expectType(chalk.underline('foo'));
+expectType(chalk.overline('foo'));
expectType(chalk.inverse('foo'));
expectType(chalk.hidden('foo'));
expectType(chalk.strikethrough('foo'));
diff --git a/package.json b/package.json
index 9e6f031..2509b62 100644
--- a/package.json
+++ b/package.json
@@ -42,17 +42,20 @@
"text"
],
"dependencies": {
- "ansi-styles": "^4.1.0",
+ "ansi-styles": "^6.1.0",
"supports-color": "^9.0.0"
},
"devDependencies": {
"ava": "^3.15.0",
+ "color-convert": "^2.0.1",
"coveralls": "^3.1.0",
"execa": "^5.0.0",
+ "log-update": "^4.0.0",
"matcha": "^0.7.0",
"nyc": "^15.1.0",
"tsd": "^0.14.0",
- "xo": "^0.38.2"
+ "xo": "^0.38.2",
+ "yoctodelay": "^1.2.0"
},
"xo": {
"rules": {
diff --git a/readme.md b/readme.md
index 45e4be7..6d92165 100644
--- a/readme.md
+++ b/readme.md
@@ -125,7 +125,6 @@ DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
`);
// Use RGB colors in terminal emulators that support it.
-log(chalk.keyword('orange')('Yay for orange colored text!'));
log(chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
log(chalk.hex('#DEADED').bold('Bold gray!'));
```
@@ -136,7 +135,7 @@ Easily define your own themes:
import chalk from 'chalk';
const error = chalk.bold.red;
-const warning = chalk.keyword('orange');
+const warning = chalk.hex('#FFA500'); // Orange color
console.log(error('Error!'));
console.log(warning('Warning!'));
@@ -275,7 +274,7 @@ console.log(chalk.bold.rgb(10, 100, 200)`Hello!`);
console.log(chalk`{bold.rgb(10,100,200) Hello!}`);
```
-Note that function styles (`rgb()`, `hsl()`, `keyword()`, etc.) may not contain spaces between parameters.
+Note that function styles (`rgb()`, `hex()`, etc.) may not contain spaces between parameters.
All interpolated values (`` chalk`${foo}` ``) are converted to strings via the `.toString()` method. All curly braces (`{` and `}`) in interpolated value strings are escaped.
@@ -288,24 +287,17 @@ Colors are downsampled from 16 million RGB values to an ANSI color format that i
Examples:
- `chalk.hex('#DEADED').underline('Hello, world!')`
-- `chalk.keyword('orange')('Some orange text')`
- `chalk.rgb(15, 100, 204).inverse('Hello!')`
-Background versions of these models are prefixed with `bg` and the first level of the module capitalized (e.g. `keyword` for foreground colors and `bgKeyword` for background colors).
+Background 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).
- `chalk.bgHex('#DEADED').underline('Hello, world!')`
-- `chalk.bgKeyword('orange')('Some orange text')`
- `chalk.bgRgb(15, 100, 204).inverse('Hello!')`
The following color models can be used:
- [`rgb`](https://en.wikipedia.org/wiki/RGB_color_model) - Example: `chalk.rgb(255, 136, 0).bold('Orange!')`
- [`hex`](https://en.wikipedia.org/wiki/Web_colors#Hex_triplet) - Example: `chalk.hex('#FF8800').bold('Orange!')`
-- [`keyword`](https://www.w3.org/wiki/CSS/Properties/color/keywords) (CSS keywords) - Example: `chalk.keyword('orange').bold('Orange!')`
-- [`hsl`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsl(32, 100, 50).bold('Orange!')`
-- [`hsv`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsv(32, 100, 100).bold('Orange!')`
-- [`hwb`](https://en.wikipedia.org/wiki/HWB_color_model) - Example: `chalk.hwb(32, 0, 50).bold('Orange!')`
-- [`ansi`](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) - Example: `chalk.ansi(31).bgAnsi(93)('red on yellowBright')`
- [`ansi256`](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) - Example: `chalk.bgAnsi256(194)('Honeydew, more or less')`
## Browser support
diff --git a/source/index.js b/source/index.js
index 8db69d2..70f7a5d 100644
--- a/source/index.js
+++ b/source/index.js
@@ -74,14 +74,34 @@ styles.visible = {
}
};
-const usedModels = ['rgb', 'hex', 'keyword', 'hsl', 'hsv', 'hwb', 'ansi', 'ansi256'];
+const getModelAnsi = (model, level, type, ...arguments_) => {
+ if (model === 'rgb') {
+ if (level === 'ansi16m') {
+ return ansiStyles[type].ansi16m(...arguments_);
+ }
+
+ if (level === 'ansi256') {
+ return ansiStyles[type].ansi256(ansiStyles.rgbToAnsi256(...arguments_));
+ }
+
+ return ansiStyles[type].ansi(ansiStyles.rgbToAnsi(...arguments_));
+ }
+
+ if (model === 'hex') {
+ return getModelAnsi('rgb', level, type, ...ansiStyles.hexToRgb(...arguments_));
+ }
+
+ return ansiStyles[type][model](...arguments_);
+};
+
+const usedModels = ['rgb', 'hex', 'ansi256'];
for (const model of usedModels) {
styles[model] = {
get() {
const {level} = this;
return function (...arguments_) {
- const styler = createStyler(ansiStyles.color[levelMapping[level]][model](...arguments_), ansiStyles.color.close, this._styler);
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], 'color', ...arguments_), ansiStyles.color.close, this._styler);
return createBuilder(this, styler, this._isEmpty);
};
}
@@ -92,7 +112,7 @@ for (const model of usedModels) {
get() {
const {level} = this;
return function (...arguments_) {
- const styler = createStyler(ansiStyles.bgColor[levelMapping[level]][model](...arguments_), ansiStyles.bgColor.close, this._styler);
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], 'bgColor', ...arguments_), ansiStyles.bgColor.close, this._styler);
return createBuilder(this, styler, this._isEmpty);
};
}
diff --git a/test/template-literal.js b/test/template-literal.js
index 773e097..e8d5950 100644
--- a/test/template-literal.js
+++ b/test/template-literal.js
@@ -150,18 +150,18 @@ test('correctly parses unicode/hex escapes', t => {
test('correctly parses string arguments', t => {
const instance = new Chalk({level: 3});
- t.is(instance`{keyword('black').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
- t.is(instance`{keyword('blac\x6B').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
- t.is(instance`{keyword('blac\u006B').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
+ t.is(instance`{hex('#000000').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
+ t.is(instance`{hex('#00000\x30').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
+ t.is(instance`{hex('#00000\u0030').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
});
test('throws if a bad argument is encountered', t => {
const instance = new Chalk({level: 3}); // Keep level at least 1 in case we optimize for disabled chalk instances
try {
- console.log(instance`{keyword(????) hi}`);
+ console.log(instance`{hex(????) hi}`);
t.fail();
} catch (error) {
- t.is(error.message, 'Invalid Chalk template style argument: ???? (in style \'keyword\')');
+ t.is(error.message, 'Invalid Chalk template style argument: ???? (in style \'hex\')');
}
});
From f8a3642a8107f6029c6923b72a43c35a1065a336 Mon Sep 17 00:00:00 2001
From: Richie Bendall
Date: Thu, 22 Apr 2021 20:03:48 +1200
Subject: [PATCH 19/72] Minor tweaks (#437)
Co-authored-by: Qix
---
index.d.ts | 2 +-
package.json | 2 +-
source/index.js | 30 +++++++++++++++++-------------
3 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/index.d.ts b/index.d.ts
index a21fa89..6f7ff2e 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -223,7 +223,7 @@ export interface ChalkInstance extends ChalkFunction {
readonly bold: this;
/**
- Modifier: Emitting only a small amount of light.
+ Modifier: Make text slightly darker. (Inconsistent across terminals; might do nothing)
*/
readonly dim: this;
diff --git a/package.json b/package.json
index 2509b62..05cbf72 100644
--- a/package.json
+++ b/package.json
@@ -54,7 +54,7 @@
"matcha": "^0.7.0",
"nyc": "^15.1.0",
"tsd": "^0.14.0",
- "xo": "^0.38.2",
+ "xo": "^0.39.1",
"yoctodelay": "^1.2.0"
},
"xo": {
diff --git a/source/index.js b/source/index.js
index 70f7a5d..8a3785b 100644
--- a/source/index.js
+++ b/source/index.js
@@ -9,6 +9,10 @@ import template from './templates.js';
const {stdout: stdoutColor, stderr: stderrColor} = supportsColor;
const {isArray} = Array;
+const GENERATOR = Symbol('GENERATOR');
+const STYLER = Symbol('STYLER');
+const IS_EMPTY = Symbol('IS_EMPTY');
+
// `supportsColor.level` → `ansiStyles.color[name]` mapping
const levelMapping = [
'ansi',
@@ -59,7 +63,7 @@ Object.setPrototypeOf(createChalk.prototype, Function.prototype);
for (const [styleName, style] of Object.entries(ansiStyles)) {
styles[styleName] = {
get() {
- const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
+ const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
Object.defineProperty(this, styleName, {value: builder});
return builder;
}
@@ -68,7 +72,7 @@ for (const [styleName, style] of Object.entries(ansiStyles)) {
styles.visible = {
get() {
- const builder = createBuilder(this, this._styler, true);
+ const builder = createBuilder(this, this[STYLER], true);
Object.defineProperty(this, 'visible', {value: builder});
return builder;
}
@@ -101,8 +105,8 @@ for (const model of usedModels) {
get() {
const {level} = this;
return function (...arguments_) {
- const styler = createStyler(getModelAnsi(model, levelMapping[level], 'color', ...arguments_), ansiStyles.color.close, this._styler);
- return createBuilder(this, styler, this._isEmpty);
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], 'color', ...arguments_), ansiStyles.color.close, this[STYLER]);
+ return createBuilder(this, styler, this[IS_EMPTY]);
};
}
};
@@ -112,8 +116,8 @@ for (const model of usedModels) {
get() {
const {level} = this;
return function (...arguments_) {
- const styler = createStyler(getModelAnsi(model, levelMapping[level], 'bgColor', ...arguments_), ansiStyles.bgColor.close, this._styler);
- return createBuilder(this, styler, this._isEmpty);
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], 'bgColor', ...arguments_), ansiStyles.bgColor.close, this[STYLER]);
+ return createBuilder(this, styler, this[IS_EMPTY]);
};
}
};
@@ -124,10 +128,10 @@ const proto = Object.defineProperties(() => {}, {
level: {
enumerable: true,
get() {
- return this._generator.level;
+ return this[GENERATOR].level;
},
set(level) {
- this._generator.level = level;
+ this[GENERATOR].level = level;
}
}
});
@@ -168,19 +172,19 @@ const createBuilder = (self, _styler, _isEmpty) => {
// no way to create a function with a different prototype
Object.setPrototypeOf(builder, proto);
- builder._generator = self;
- builder._styler = _styler;
- builder._isEmpty = _isEmpty;
+ builder[GENERATOR] = self;
+ builder[STYLER] = _styler;
+ builder[IS_EMPTY] = _isEmpty;
return builder;
};
const applyStyle = (self, string) => {
if (self.level <= 0 || !string) {
- return self._isEmpty ? '' : string;
+ return self[IS_EMPTY] ? '' : string;
}
- let styler = self._styler;
+ let styler = self[STYLER];
if (styler === undefined) {
return string;
From b68c8b5102f04fb80bfdf83319d143aedff68bcb Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Wed, 5 May 2021 21:40:56 +0700
Subject: [PATCH 20/72] Meta tweaks
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 05cbf72..a205ed7 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
"type": "module",
"exports": "./source/index.js",
"engines": {
- "node": ">=12"
+ "node": ">=12.17"
},
"scripts": {
"test": "xo && nyc ava && tsd",
From 48d25d156a109a6859ff2e907dbecf90a19e7e0a Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Fri, 30 Jul 2021 13:58:57 +0200
Subject: [PATCH 21/72] Meta tweaks
---
readme.md | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/readme.md b/readme.md
index 6d92165..9fe28fb 100644
--- a/readme.md
+++ b/readme.md
@@ -36,7 +36,7 @@
-
+
@@ -51,6 +51,12 @@
and avoiding access controls. Keep your team and servers in sync with Doppler.
+
+
+
+

+
+
From 625a2857722fb86cfe98f22c9c12888238e36f51 Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Fri, 30 Jul 2021 17:30:19 +0200
Subject: [PATCH 22/72] Add `types` field to package.json
Fixes #500
---
examples/rainbow.js | 2 +-
package.json | 14 +++++-----
index.d.ts => source/index.d.ts | 0
source/index.js | 22 ++++++++--------
index.test-d.ts => source/index.test-d.ts | 0
source/templates.js | 2 +-
test/chalk.js | 6 ++---
test/level.js | 2 +-
test/template-literal.js | 32 +++++++++++------------
9 files changed, 41 insertions(+), 39 deletions(-)
rename index.d.ts => source/index.d.ts (100%)
rename index.test-d.ts => source/index.test-d.ts (100%)
diff --git a/examples/rainbow.js b/examples/rainbow.js
index 9ea1d72..3501dab 100644
--- a/examples/rainbow.js
+++ b/examples/rainbow.js
@@ -1,7 +1,7 @@
-import chalk from '../source/index.js';
import convertColor from 'color-convert';
import updateLog from 'log-update';
import delay from 'yoctodelay';
+import chalk from '../source/index.js';
const ignoreChars = /[^!-~]/g;
diff --git a/package.json b/package.json
index a205ed7..3ad50b2 100644
--- a/package.json
+++ b/package.json
@@ -16,7 +16,7 @@
},
"files": [
"source",
- "index.d.ts"
+ "!source/index.test-d.ts"
],
"keywords": [
"color",
@@ -43,20 +43,22 @@
],
"dependencies": {
"ansi-styles": "^6.1.0",
- "supports-color": "^9.0.0"
+ "supports-color": "^9.0.2"
},
"devDependencies": {
"ava": "^3.15.0",
"color-convert": "^2.0.1",
- "coveralls": "^3.1.0",
- "execa": "^5.0.0",
+ "coveralls": "^3.1.1",
+ "execa": "^5.1.1",
"log-update": "^4.0.0",
"matcha": "^0.7.0",
"nyc": "^15.1.0",
- "tsd": "^0.14.0",
- "xo": "^0.39.1",
+ "tsd": "^0.17.0",
+ "typescript": "^4.3.5",
+ "xo": "^0.42.0",
"yoctodelay": "^1.2.0"
},
+ "types": "./source/index.d.ts",
"xo": {
"rules": {
"unicorn/prefer-string-slice": "off",
diff --git a/index.d.ts b/source/index.d.ts
similarity index 100%
rename from index.d.ts
rename to source/index.d.ts
diff --git a/source/index.js b/source/index.js
index 8a3785b..88c7528 100644
--- a/source/index.js
+++ b/source/index.js
@@ -2,7 +2,7 @@ import ansiStyles from 'ansi-styles';
import supportsColor from 'supports-color';
import {
stringReplaceAll,
- stringEncaseCRLFWithFirstIndex
+ stringEncaseCRLFWithFirstIndex,
} from './util.js';
import template from './templates.js';
@@ -18,7 +18,7 @@ const levelMapping = [
'ansi',
'ansi',
'ansi256',
- 'ansi16m'
+ 'ansi16m',
];
const styles = Object.create(null);
@@ -66,7 +66,7 @@ for (const [styleName, style] of Object.entries(ansiStyles)) {
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
Object.defineProperty(this, styleName, {value: builder});
return builder;
- }
+ },
};
}
@@ -75,7 +75,7 @@ styles.visible = {
const builder = createBuilder(this, this[STYLER], true);
Object.defineProperty(this, 'visible', {value: builder});
return builder;
- }
+ },
};
const getModelAnsi = (model, level, type, ...arguments_) => {
@@ -108,7 +108,7 @@ for (const model of usedModels) {
const styler = createStyler(getModelAnsi(model, levelMapping[level], 'color', ...arguments_), ansiStyles.color.close, this[STYLER]);
return createBuilder(this, styler, this[IS_EMPTY]);
};
- }
+ },
};
const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
@@ -119,7 +119,7 @@ for (const model of usedModels) {
const styler = createStyler(getModelAnsi(model, levelMapping[level], 'bgColor', ...arguments_), ansiStyles.bgColor.close, this[STYLER]);
return createBuilder(this, styler, this[IS_EMPTY]);
};
- }
+ },
};
}
@@ -132,8 +132,8 @@ const proto = Object.defineProperties(() => {}, {
},
set(level) {
this[GENERATOR].level = level;
- }
- }
+ },
+ },
});
const createStyler = (open, close, parent) => {
@@ -152,7 +152,7 @@ const createStyler = (open, close, parent) => {
close,
openAll,
closeAll,
- parent
+ parent,
};
};
@@ -228,7 +228,7 @@ const chalkTag = (chalk, ...strings) => {
for (let i = 1; i < firstString.length; i++) {
parts.push(
String(arguments_[i - 1]).replace(/[{}\\]/g, '\\$&'),
- String(firstString.raw[i])
+ String(firstString.raw[i]),
);
}
@@ -242,7 +242,7 @@ export const chalkStderr = createChalk({level: stderrColor ? stderrColor.level :
export {
stdoutColor as supportsColor,
- stderrColor as supportsColorStderr
+ stderrColor as supportsColorStderr,
};
export default chalk;
diff --git a/index.test-d.ts b/source/index.test-d.ts
similarity index 100%
rename from index.test-d.ts
rename to source/index.test-d.ts
diff --git a/source/templates.js b/source/templates.js
index 1a2f95c..590223f 100644
--- a/source/templates.js
+++ b/source/templates.js
@@ -13,7 +13,7 @@ const ESCAPES = new Map([
['0', '\0'],
['\\', '\\'],
['e', '\u001B'],
- ['a', '\u0007']
+ ['a', '\u0007'],
]);
function unescape(c) {
diff --git a/test/chalk.js b/test/chalk.js
index af43558..32b57c6 100644
--- a/test/chalk.js
+++ b/test/chalk.js
@@ -20,7 +20,7 @@ test('support automatic casting to string', t => {
t.is(chalk(123), '123');
t.is(chalk.bold(['foo', 'bar']), '\u001B[1mfoo,bar\u001B[22m');
- t.is(chalk.green(98765), '\u001B[32m98765\u001B[39m');
+ t.is(chalk.green(98_765), '\u001B[32m98765\u001B[39m');
});
test('style string', t => {
@@ -37,14 +37,14 @@ test('support applying multiple styles at once', t => {
test('support nesting styles', t => {
t.is(
chalk.red('foo' + chalk.underline.bgBlue('bar') + '!'),
- '\u001B[31mfoo\u001B[4m\u001B[44mbar\u001B[49m\u001B[24m!\u001B[39m'
+ '\u001B[31mfoo\u001B[4m\u001B[44mbar\u001B[49m\u001B[24m!\u001B[39m',
);
});
test('support nesting styles of the same type (color, underline, bg)', t => {
t.is(
chalk.red('a' + chalk.yellow('b' + chalk.green('c') + 'b') + 'c'),
- '\u001B[31ma\u001B[33mb\u001B[32mc\u001B[39m\u001B[31m\u001B[33mb\u001B[39m\u001B[31mc\u001B[39m'
+ '\u001B[31ma\u001B[33mb\u001B[32mc\u001B[39m\u001B[31m\u001B[33mb\u001B[39m\u001B[31mc\u001B[39m',
);
});
diff --git a/test/level.js b/test/level.js
index 4aab162..5fed269 100644
--- a/test/level.js
+++ b/test/level.js
@@ -1,4 +1,4 @@
-import {fileURLToPath} from 'url';
+import {fileURLToPath} from 'node:url';
import test from 'ava';
import execa from 'execa';
import chalk from '../source/index.js';
diff --git a/test/template-literal.js b/test/template-literal.js
index e8d5950..5e737a5 100644
--- a/test/template-literal.js
+++ b/test/template-literal.js
@@ -42,22 +42,22 @@ test('correctly perform nested template substitutions', t => {
instance.strikethrough.cyanBright.bgBlack('Works with ' + instance.reset.bold('numbers') + ' ' + instance.bold.red(1)));
t.is(chalk.bold`Also works on the shared {bgBlue chalk} object`,
- '\u001B[1mAlso works on the shared \u001B[1m' +
- '\u001B[44mchalk\u001B[49m\u001B[22m' +
- '\u001B[1m object\u001B[22m');
+ '\u001B[1mAlso works on the shared \u001B[1m'
+ + '\u001B[44mchalk\u001B[49m\u001B[22m'
+ + '\u001B[1m object\u001B[22m');
});
test('correctly parse and evaluate color-convert functions', t => {
const instance = new Chalk({level: 3});
t.is(instance`{bold.rgb(144,10,178).inverse Hello, {~inverse there!}}`,
- '\u001B[1m\u001B[38;2;144;10;178m\u001B[7mHello, ' +
- '\u001B[27m\u001B[39m\u001B[22m\u001B[1m' +
- '\u001B[38;2;144;10;178mthere!\u001B[39m\u001B[22m');
+ '\u001B[1m\u001B[38;2;144;10;178m\u001B[7mHello, '
+ + '\u001B[27m\u001B[39m\u001B[22m\u001B[1m'
+ + '\u001B[38;2;144;10;178mthere!\u001B[39m\u001B[22m');
t.is(instance`{bold.bgRgb(144,10,178).inverse Hello, {~inverse there!}}`,
- '\u001B[1m\u001B[48;2;144;10;178m\u001B[7mHello, ' +
- '\u001B[27m\u001B[49m\u001B[22m\u001B[1m' +
- '\u001B[48;2;144;10;178mthere!\u001B[49m\u001B[22m');
+ '\u001B[1m\u001B[48;2;144;10;178m\u001B[7mHello, '
+ + '\u001B[27m\u001B[49m\u001B[22m\u001B[1m'
+ + '\u001B[48;2;144;10;178mthere!\u001B[49m\u001B[22m');
});
test('properly handle escapes', t => {
@@ -103,13 +103,13 @@ test('properly style multiline color blocks', t => {
} {underline
I hope you enjoy
}`,
- '\u001B[1m\u001B[22m\n' +
- '\u001B[1m\t\t\tHello! This is a\u001B[22m\n' +
- '\u001B[1m\t\t\tmultiline block!\u001B[22m\n' +
- '\u001B[1m\t\t\t:)\u001B[22m\n' +
- '\u001B[1m\t\t\u001B[22m \u001B[4m\u001B[24m\n' +
- '\u001B[4m\t\t\tI hope you enjoy\u001B[24m\n' +
- '\u001B[4m\t\t\u001B[24m'
+ '\u001B[1m\u001B[22m\n'
+ + '\u001B[1m\t\t\tHello! This is a\u001B[22m\n'
+ + '\u001B[1m\t\t\tmultiline block!\u001B[22m\n'
+ + '\u001B[1m\t\t\t:)\u001B[22m\n'
+ + '\u001B[1m\t\t\u001B[22m \u001B[4m\u001B[24m\n'
+ + '\u001B[4m\t\t\tI hope you enjoy\u001B[24m\n'
+ + '\u001B[4m\t\t\u001B[24m',
);
});
From 95217429be9de27c826ca02fa37653e9e371e82f Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Wed, 11 Aug 2021 15:01:41 +0200
Subject: [PATCH 23/72] Minor tweaks
---
package.json | 3 +--
readme.md | 29 +++++++++++++++++------------
source/index.d.ts | 21 +++++++++++----------
3 files changed, 29 insertions(+), 24 deletions(-)
diff --git a/package.json b/package.json
index 3ad50b2..ef0cc13 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
"type": "module",
"exports": "./source/index.js",
"engines": {
- "node": ">=12.17"
+ "node": "^12.17.0 || ^14.13 || >=16.0.0"
},
"scripts": {
"test": "xo && nyc ava && tsd",
@@ -26,7 +26,6 @@
"console",
"cli",
"string",
- "str",
"ansi",
"style",
"styles",
diff --git a/readme.md b/readme.md
index 9fe28fb..18cddc7 100644
--- a/readme.md
+++ b/readme.md
@@ -52,9 +52,13 @@
-
+
-

+

+
+ Strapi is the leading open-source headless CMS.
+
+ It’s 100% JavaScript, fully customizable, and developer-first.
@@ -78,8 +82,8 @@
## Install
-```console
-$ npm install chalk
+```sh
+npm install chalk
```
## Usage
@@ -204,15 +208,16 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
### Modifiers
-- `reset` - Resets the current color chain.
-- `bold` - Make text bold.
-- `dim` - Emitting only a small amount of light.
-- `italic` - Make text italic. *(Not widely supported)*
-- `underline` - Make text underline. *(Not widely supported)*
-- `inverse`- Inverse background and foreground colors.
-- `hidden` - Prints the text, but makes it invisible.
+- `reset` - Reset the current style.
+- `bold` - Make the text bold.
+- `dim` - Make the text have lower opacity.
+- `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.
+- `hidden` - Print the text but make it invisible.
- `strikethrough` - Puts a horizontal line through the center of the text. *(Not widely supported)*
-- `visible`- Prints the text only when Chalk has a color level > 0. 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
diff --git a/source/index.d.ts b/source/index.d.ts
index 6f7ff2e..e94d260 100644
--- a/source/index.d.ts
+++ b/source/index.d.ts
@@ -213,52 +213,53 @@ export interface ChalkInstance extends ChalkFunction {
bgAnsi256: (index: number) => this;
/**
- Modifier: Resets the current color chain.
+ Modifier: Reset the current style.
*/
readonly reset: this;
/**
- Modifier: Make text bold.
+ Modifier: Make the text bold.
*/
readonly bold: this;
/**
- Modifier: Make text slightly darker. (Inconsistent across terminals; might do nothing)
+ Modifier: Make the text have lower opacity.
*/
readonly dim: this;
/**
- Modifier: Make text italic. (Not widely supported)
+ Modifier: Make the text italic. *(Not widely supported)*
*/
readonly italic: this;
/**
- Modifier: Make text underline. (Not widely supported)
+ Modifier: Put a horizontal line below the text. *(Not widely supported)*
*/
readonly underline: this;
/**
- Modifier: Make text overline. (Not widely supported)
+ Modifier: Put a horizontal line above the text. *(Not widely supported)*
*/
readonly overline: this;
/**
- Modifier: Inverse background and foreground colors.
+ Modifier: Invert background and foreground colors.
*/
readonly inverse: this;
/**
- Modifier: Prints the text, but makes it invisible.
+ Modifier: Print the text but make it invisible.
*/
readonly hidden: this;
/**
- Modifier: Puts a horizontal line through the center of the text. (Not widely supported)
+ Modifier: Puts a horizontal line through the center of the text. *(Not widely supported)*
*/
readonly strikethrough: this;
/**
- Modifier: Prints the text only when Chalk has a color support level > 0.
+ Modifier: Print the text only when Chalk has a color level above zero.
+
Can be useful for things that are purely cosmetic.
*/
readonly visible: this;
From 3761e455a17ebb1c01b2736fbe8bd42534383ab2 Mon Sep 17 00:00:00 2001
From: Richie Bendall
Date: Mon, 25 Oct 2021 08:07:02 +1300
Subject: [PATCH 24/72] Meta tweak (#520)
---
source/index.d.ts | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/source/index.d.ts b/source/index.d.ts
index e94d260..73ae767 100644
--- a/source/index.d.ts
+++ b/source/index.d.ts
@@ -166,6 +166,13 @@ export interface ChalkInstance extends ChalkFunction {
/**
Use RGB values to set text color.
+
+ @example
+ ```
+ import chalk from 'chalk';
+
+ chalk.rgb(222, 173, 237);
+ ```
*/
rgb: (red: number, green: number, blue: number) => this;
@@ -185,11 +192,25 @@ export interface ChalkInstance extends ChalkFunction {
/**
Use an [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
+
+ @example
+ ```
+ import chalk from 'chalk';
+
+ chalk.ansi256(201);
+ ```
*/
ansi256: (index: number) => this;
/**
Use RGB values to set background color.
+
+ @example
+ ```
+ import chalk from 'chalk';
+
+ chalk.bgRgb(222, 173, 237);
+ ```
*/
bgRgb: (red: number, green: number, blue: number) => this;
@@ -209,6 +230,13 @@ export interface ChalkInstance extends ChalkFunction {
/**
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
+
+ @example
+ ```
+ import chalk from 'chalk';
+
+ chalk.bgAnsi256(201);
+ ```
*/
bgAnsi256: (index: number) => this;
From f478655c3c04c844f70a596d9ec750c3da00f795 Mon Sep 17 00:00:00 2001
From: LightnerDev <79603731+LightnerDev@users.noreply.github.com>
Date: Tue, 26 Oct 2021 13:22:37 -0500
Subject: [PATCH 25/72] Update dependents number in readme (#521)
---
readme.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/readme.md b/readme.md
index 18cddc7..7f041b5 100644
--- a/readme.md
+++ b/readme.md
@@ -78,7 +78,7 @@
- Doesn't extend `String.prototype`
- Clean and focused
- Actively maintained
-- [Used by ~50,000 packages](https://www.npmjs.com/browse/depended/chalk) as of January 1, 2020
+- [Used by ~76,000 packages](https://www.npmjs.com/browse/depended/chalk) as of October 26, 2021
## Install
From c987c614869ba286f0eb11c1966ee1d135c80599 Mon Sep 17 00:00:00 2001
From: Richie Bendall
Date: Wed, 10 Nov 2021 22:12:33 +1300
Subject: [PATCH 26/72] Remove support for tagged template literals (#524)
---
readme.md | 40 +-------
source/index.d.ts | 31 +------
source/index.js | 46 +---------
source/index.test-d.ts | 6 --
source/templates.js | 133 ---------------------------
test/template-literal.js | 194 ---------------------------------------
6 files changed, 8 insertions(+), 442 deletions(-)
delete mode 100644 source/templates.js
delete mode 100644 test/template-literal.js
diff --git a/readme.md b/readme.md
index 7f041b5..ed157bd 100644
--- a/readme.md
+++ b/readme.md
@@ -127,13 +127,6 @@ RAM: ${chalk.green('40%')}
DISK: ${chalk.yellow('70%')}
`);
-// ES2015 tagged template literal
-log(chalk`
-CPU: {red ${cpu.totalPercent}%}
-RAM: {green ${ram.used / ram.total * 100}%}
-DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
-`);
-
// Use RGB colors in terminal emulators that support it.
log(chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
log(chalk.hex('#DEADED').bold('Bold gray!'));
@@ -257,38 +250,6 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
- `bgCyanBright`
- `bgWhiteBright`
-## Tagged template literal
-
-Chalk can be used as a [tagged template literal](https://exploringjs.com/es6/ch_template-literals.html#_tagged-template-literals).
-
-```js
-import chalk from 'chalk';
-
-const miles = 18;
-const calculateFeet = miles => miles * 5280;
-
-console.log(chalk`
- There are {bold 5280 feet} in a mile.
- In {bold ${miles} miles}, there are {green.bold ${calculateFeet(miles)} feet}.
-`);
-```
-
-Blocks are delimited by an opening curly brace (`{`), a style, some content, and a closing curly brace (`}`).
-
-Template styles are chained exactly like normal Chalk styles. The following three statements are equivalent:
-
-```js
-import chalk from 'chalk';
-
-console.log(chalk.bold.rgb(10, 100, 200)('Hello!'));
-console.log(chalk.bold.rgb(10, 100, 200)`Hello!`);
-console.log(chalk`{bold.rgb(10,100,200) Hello!}`);
-```
-
-Note that function styles (`rgb()`, `hex()`, etc.) may not contain spaces between parameters.
-
-All interpolated values (`` chalk`${foo}` ``) are converted to strings via the `.toString()` method. All curly braces (`{` and `}`) in interpolated value strings are escaped.
-
## 256 and Truecolor color support
Chalk supports 256 colors and [Truecolor](https://gist.github.com/XVilka/8346728) (16 million colors) on supported terminal apps.
@@ -331,6 +292,7 @@ The maintainers of chalk and thousands of other packages are working with Tideli
## Related
+- [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 module
- [chalk-cli](https://github.com/chalk/chalk-cli) - CLI for this module
- [ansi-styles](https://github.com/chalk/ansi-styles) - ANSI escape codes for styling strings in the terminal
- [supports-color](https://github.com/chalk/supports-color) - Detect whether a terminal supports color
diff --git a/source/index.d.ts b/source/index.d.ts
index 73ae767..a6c6f76 100644
--- a/source/index.d.ts
+++ b/source/index.d.ts
@@ -121,36 +121,9 @@ export interface ColorSupport {
has16m: boolean;
}
-interface ChalkFunction {
- /**
- Use a template string.
-
- @remarks Template literals are unsupported for nested calls (see [issue #341](https://github.com/chalk/chalk/issues/341))
-
- @example
- ```
- import chalk from 'chalk';
-
- log(chalk`
- CPU: {red ${cpu.totalPercent}%}
- RAM: {green ${ram.used / ram.total * 100}%}
- DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
- `);
- ```
-
- @example
- ```
- import chalk from 'chalk';
-
- log(chalk.red.bgBlack`2 + 3 = {bold ${2 + 3}}`)
- ```
- */
- (text: TemplateStringsArray, ...placeholders: unknown[]): string;
-
+export interface ChalkInstance {
(...text: unknown[]): string;
-}
-export interface ChalkInstance extends ChalkFunction {
/**
The color support for Chalk.
@@ -358,7 +331,7 @@ 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`.
*/
-declare const chalk: ChalkInstance & ChalkFunction;
+declare const chalk: ChalkInstance;
export const supportsColor: ColorSupport | false;
diff --git a/source/index.js b/source/index.js
index 88c7528..6411672 100644
--- a/source/index.js
+++ b/source/index.js
@@ -4,10 +4,8 @@ import {
stringReplaceAll,
stringEncaseCRLFWithFirstIndex,
} from './util.js';
-import template from './templates.js';
const {stdout: stdoutColor, stderr: stderrColor} = supportsColor;
-const {isArray} = Array;
const GENERATOR = Symbol('GENERATOR');
const STYLER = Symbol('STYLER');
@@ -41,17 +39,12 @@ export class Chalk {
}
const chalkFactory = options => {
- const chalk = {};
+ const chalk = (...strings) => strings.join(' ');
applyOptions(chalk, options);
- chalk.template = (...arguments_) => chalkTag(chalk.template, ...arguments_);
-
Object.setPrototypeOf(chalk, createChalk.prototype);
- Object.setPrototypeOf(chalk.template, chalk);
- chalk.template.Chalk = Chalk;
-
- return chalk.template;
+ return chalk;
};
function createChalk(options) {
@@ -157,16 +150,9 @@ const createStyler = (open, close, parent) => {
};
const createBuilder = (self, _styler, _isEmpty) => {
- const builder = (...arguments_) => {
- if (isArray(arguments_[0]) && isArray(arguments_[0].raw)) {
- // Called as a template literal, for example: chalk.red`2 + 3 = {bold ${2+3}}`
- return applyStyle(builder, chalkTag(builder, ...arguments_));
- }
-
- // Single argument is hot path, implicit coercion is faster than anything
- // eslint-disable-next-line no-implicit-coercion
- return applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' '));
- };
+ // Single argument is hot path, implicit coercion is faster than anything
+ // eslint-disable-next-line no-implicit-coercion
+ const builder = (...arguments_) => applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' '));
// We alter the prototype because we must return a function, but there is
// no way to create a function with a different prototype
@@ -213,28 +199,6 @@ const applyStyle = (self, string) => {
return openAll + string + closeAll;
};
-const chalkTag = (chalk, ...strings) => {
- const [firstString] = strings;
-
- if (!isArray(firstString) || !isArray(firstString.raw)) {
- // If chalk() was called by itself or with a string,
- // return the string itself as a string.
- return strings.join(' ');
- }
-
- const arguments_ = strings.slice(1);
- const parts = [firstString.raw[0]];
-
- for (let i = 1; i < firstString.length; i++) {
- parts.push(
- String(arguments_[i - 1]).replace(/[{}\\]/g, '\\$&'),
- String(firstString.raw[i]),
- );
- }
-
- return template(chalk, parts.join(''));
-};
-
Object.defineProperties(createChalk.prototype, styles);
const chalk = createChalk();
diff --git a/source/index.test-d.ts b/source/index.test-d.ts
index 45299d6..2bd0ed5 100644
--- a/source/index.test-d.ts
+++ b/source/index.test-d.ts
@@ -34,12 +34,6 @@ expectType(new Chalk({level: 1}));
// -- Properties --
expectType(chalk.level);
-// -- Template literal --
-expectType(chalk``);
-const name = 'John';
-expectType(chalk`Hello {bold.red ${name}}`);
-expectType(chalk`Works with numbers {bold.red ${1}}`);
-
// -- Color methods --
expectAssignable(chalk.rgb(0, 0, 0));
expectAssignable(chalk.hex('#DEADED'));
diff --git a/source/templates.js b/source/templates.js
deleted file mode 100644
index 590223f..0000000
--- a/source/templates.js
+++ /dev/null
@@ -1,133 +0,0 @@
-const TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
-const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
-const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
-const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
-
-const ESCAPES = new Map([
- ['n', '\n'],
- ['r', '\r'],
- ['t', '\t'],
- ['b', '\b'],
- ['f', '\f'],
- ['v', '\v'],
- ['0', '\0'],
- ['\\', '\\'],
- ['e', '\u001B'],
- ['a', '\u0007'],
-]);
-
-function unescape(c) {
- const u = c[0] === 'u';
- const bracket = c[1] === '{';
-
- if ((u && !bracket && c.length === 5) || (c[0] === 'x' && c.length === 3)) {
- return String.fromCharCode(Number.parseInt(c.slice(1), 16));
- }
-
- if (u && bracket) {
- return String.fromCodePoint(Number.parseInt(c.slice(2, -1), 16));
- }
-
- return ESCAPES.get(c) || c;
-}
-
-function parseArguments(name, arguments_) {
- const results = [];
- const chunks = arguments_.trim().split(/\s*,\s*/g);
- let matches;
-
- for (const chunk of chunks) {
- const number = Number(chunk);
- if (!Number.isNaN(number)) {
- results.push(number);
- } else if ((matches = chunk.match(STRING_REGEX))) {
- results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, character) => escape ? unescape(escape) : character));
- } else {
- throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
- }
- }
-
- return results;
-}
-
-function parseStyle(style) {
- STYLE_REGEX.lastIndex = 0;
-
- const results = [];
- let matches;
-
- while ((matches = STYLE_REGEX.exec(style)) !== null) {
- const name = matches[1];
-
- if (matches[2]) {
- const args = parseArguments(name, matches[2]);
- results.push([name, ...args]);
- } else {
- results.push([name]);
- }
- }
-
- return results;
-}
-
-function buildStyle(chalk, styles) {
- const enabled = {};
-
- for (const layer of styles) {
- for (const style of layer.styles) {
- enabled[style[0]] = layer.inverse ? null : style.slice(1);
- }
- }
-
- let current = chalk;
- for (const [styleName, styles] of Object.entries(enabled)) {
- if (!Array.isArray(styles)) {
- continue;
- }
-
- if (!(styleName in current)) {
- throw new Error(`Unknown Chalk style: ${styleName}`);
- }
-
- current = styles.length > 0 ? current[styleName](...styles) : current[styleName];
- }
-
- return current;
-}
-
-export default function template(chalk, temporary) {
- const styles = [];
- const chunks = [];
- let chunk = [];
-
- // eslint-disable-next-line max-params
- temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => {
- if (escapeCharacter) {
- chunk.push(unescape(escapeCharacter));
- } else if (style) {
- const string = chunk.join('');
- chunk = [];
- chunks.push(styles.length === 0 ? string : buildStyle(chalk, styles)(string));
- styles.push({inverse, styles: parseStyle(style)});
- } else if (close) {
- if (styles.length === 0) {
- throw new Error('Found extraneous } in Chalk template literal');
- }
-
- chunks.push(buildStyle(chalk, styles)(chunk.join('')));
- chunk = [];
- styles.pop();
- } else {
- chunk.push(character);
- }
- });
-
- chunks.push(chunk.join(''));
-
- if (styles.length > 0) {
- const errorMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
- throw new Error(errorMessage);
- }
-
- return chunks.join('');
-}
diff --git a/test/template-literal.js b/test/template-literal.js
deleted file mode 100644
index 5e737a5..0000000
--- a/test/template-literal.js
+++ /dev/null
@@ -1,194 +0,0 @@
-/* eslint-disable unicorn/no-hex-escape */
-import test from 'ava';
-import chalk, {Chalk} from '../source/index.js';
-
-chalk.level = 1;
-
-test('return an empty string for an empty literal', t => {
- const instance = new Chalk();
- t.is(instance``, '');
-});
-
-test('return a regular string for a literal with no templates', t => {
- const instance = new Chalk({level: 0});
- t.is(instance`hello`, 'hello');
-});
-
-test('correctly perform template parsing', t => {
- const instance = new Chalk({level: 0});
- t.is(instance`{bold Hello, {cyan World!} This is a} test. {green Woo!}`,
- instance.bold('Hello,', instance.cyan('World!'), 'This is a') + ' test. ' + instance.green('Woo!'));
-});
-
-test('correctly perform template substitutions', t => {
- const instance = new Chalk({level: 0});
- const name = 'Sindre';
- const exclamation = 'Neat';
- t.is(instance`{bold Hello, {cyan.inverse ${name}!} This is a} test. {green ${exclamation}!}`,
- instance.bold('Hello,', instance.cyan.inverse(name + '!'), 'This is a') + ' test. ' + instance.green(exclamation + '!'));
-});
-
-test('correctly perform nested template substitutions', t => {
- const instance = new Chalk({level: 0});
- const name = 'Sindre';
- const exclamation = 'Neat';
- t.is(instance.bold`Hello, {cyan.inverse ${name}!} This is a` + ' test. ' + instance.green`${exclamation}!`,
- instance.bold('Hello,', instance.cyan.inverse(name + '!'), 'This is a') + ' test. ' + instance.green(exclamation + '!'));
-
- t.is(instance.red.bgGreen.bold`Hello {italic.blue ${name}}`,
- instance.red.bgGreen.bold('Hello ' + instance.italic.blue(name)));
-
- t.is(instance.strikethrough.cyanBright.bgBlack`Works with {reset {bold numbers}} {bold.red ${1}}`,
- instance.strikethrough.cyanBright.bgBlack('Works with ' + instance.reset.bold('numbers') + ' ' + instance.bold.red(1)));
-
- t.is(chalk.bold`Also works on the shared {bgBlue chalk} object`,
- '\u001B[1mAlso works on the shared \u001B[1m'
- + '\u001B[44mchalk\u001B[49m\u001B[22m'
- + '\u001B[1m object\u001B[22m');
-});
-
-test('correctly parse and evaluate color-convert functions', t => {
- const instance = new Chalk({level: 3});
- t.is(instance`{bold.rgb(144,10,178).inverse Hello, {~inverse there!}}`,
- '\u001B[1m\u001B[38;2;144;10;178m\u001B[7mHello, '
- + '\u001B[27m\u001B[39m\u001B[22m\u001B[1m'
- + '\u001B[38;2;144;10;178mthere!\u001B[39m\u001B[22m');
-
- t.is(instance`{bold.bgRgb(144,10,178).inverse Hello, {~inverse there!}}`,
- '\u001B[1m\u001B[48;2;144;10;178m\u001B[7mHello, '
- + '\u001B[27m\u001B[49m\u001B[22m\u001B[1m'
- + '\u001B[48;2;144;10;178mthere!\u001B[49m\u001B[22m');
-});
-
-test('properly handle escapes', t => {
- const instance = new Chalk({level: 3});
- t.is(instance`{bold hello \{in brackets\}}`,
- '\u001B[1mhello {in brackets}\u001B[22m');
-});
-
-test('throw if there is an unclosed block', t => {
- const instance = new Chalk({level: 3});
- try {
- console.log(instance`{bold this shouldn't appear ever\}`);
- t.fail();
- } catch (error) {
- t.is(error.message, 'Chalk template literal is missing 1 closing bracket (`}`)');
- }
-
- try {
- console.log(instance`{bold this shouldn't {inverse appear {underline ever\} :) \}`);
- t.fail();
- } catch (error) {
- t.is(error.message, 'Chalk template literal is missing 3 closing brackets (`}`)');
- }
-});
-
-test('throw if there is an invalid style', t => {
- const instance = new Chalk({level: 3});
- try {
- console.log(instance`{abadstylethatdoesntexist this shouldn't appear ever}`);
- t.fail();
- } catch (error) {
- t.is(error.message, 'Unknown Chalk style: abadstylethatdoesntexist');
- }
-});
-
-test('properly style multiline color blocks', t => {
- const instance = new Chalk({level: 3});
- t.is(
- instance`{bold
- Hello! This is a
- ${'multiline'} block!
- :)
- } {underline
- I hope you enjoy
- }`,
- '\u001B[1m\u001B[22m\n'
- + '\u001B[1m\t\t\tHello! This is a\u001B[22m\n'
- + '\u001B[1m\t\t\tmultiline block!\u001B[22m\n'
- + '\u001B[1m\t\t\t:)\u001B[22m\n'
- + '\u001B[1m\t\t\u001B[22m \u001B[4m\u001B[24m\n'
- + '\u001B[4m\t\t\tI hope you enjoy\u001B[24m\n'
- + '\u001B[4m\t\t\u001B[24m',
- );
-});
-
-test('escape interpolated values', t => {
- const instance = new Chalk({level: 0});
- t.is(instance`Hello {bold hi}`, 'Hello hi');
- t.is(instance`Hello ${'{bold hi}'}`, 'Hello {bold hi}');
-});
-
-test('allow custom colors (themes) on custom contexts', t => {
- const instance = new Chalk({level: 3});
- instance.rose = instance.hex('#F6D9D9');
- t.is(instance`Hello, {rose Rose}.`, 'Hello, \u001B[38;2;246;217;217mRose\u001B[39m.');
-});
-
-test('correctly parse newline literals (bug #184)', t => {
- const instance = new Chalk({level: 0});
- t.is(instance`Hello
-{red there}`, 'Hello\nthere');
-});
-
-test('correctly parse newline escapes (bug #177)', t => {
- const instance = new Chalk({level: 0});
- t.is(instance`Hello\nthere!`, 'Hello\nthere!');
-});
-
-test('correctly parse escape in parameters (bug #177 comment 318622809)', t => {
- const instance = new Chalk({level: 0});
- const string = '\\';
- t.is(instance`{blue ${string}}`, '\\');
-});
-
-test('correctly parses unicode/hex escapes', t => {
- const instance = new Chalk({level: 0});
- t.is(instance`\u0078ylophones are fo\x78y! {magenta.inverse \u0078ylophones are fo\x78y!}`,
- 'xylophones are foxy! xylophones are foxy!');
-});
-
-test('correctly parses string arguments', t => {
- const instance = new Chalk({level: 3});
- t.is(instance`{hex('#000000').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
- t.is(instance`{hex('#00000\x30').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
- t.is(instance`{hex('#00000\u0030').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
-});
-
-test('throws if a bad argument is encountered', t => {
- const instance = new Chalk({level: 3}); // Keep level at least 1 in case we optimize for disabled chalk instances
- try {
- console.log(instance`{hex(????) hi}`);
- t.fail();
- } catch (error) {
- t.is(error.message, 'Invalid Chalk template style argument: ???? (in style \'hex\')');
- }
-});
-
-test('throws if an extra unescaped } is found', t => {
- const instance = new Chalk({level: 0});
- try {
- console.log(instance`{red hi!}}`);
- t.fail();
- } catch (error) {
- t.is(error.message, 'Found extraneous } in Chalk template literal');
- }
-});
-
-test('should not parse upper-case escapes', t => {
- const instance = new Chalk({level: 0});
- t.is(instance`\N\n\T\t\X07\x07\U000A\u000A\U000a\u000A`, 'N\nT\tX07\x07U000A\u000AU000a\u000A');
-});
-
-test('should properly handle undefined template interpolated values', t => {
- const instance = new Chalk({level: 0});
- t.is(instance`hello ${undefined}`, 'hello undefined');
- t.is(instance`hello ${null}`, 'hello null');
-});
-
-test('should allow bracketed Unicode escapes', t => {
- const instance = new Chalk({level: 3});
- t.is(instance`\u{AB}`, '\u{AB}');
- t.is(instance`This is a {bold \u{AB681}} test`, 'This is a \u001B[1m\u{AB681}\u001B[22m test');
- t.is(instance`This is a {bold \u{10FFFF}} test`, 'This is a \u001B[1m\u{10FFFF}\u001B[22m test');
-});
From 09fd5c4ba812cc2e3a0df183caf3e53cc556e440 Mon Sep 17 00:00:00 2001
From: Richie Bendall
Date: Sun, 21 Nov 2021 19:51:24 +1300
Subject: [PATCH 27/72] Re-export types from `supports-color` (#526)
---
examples/screenshot.js | 1 +
package.json | 4 ++--
source/index.d.ts | 46 +++++++++---------------------------------
source/index.test-d.ts | 23 ++++++++++-----------
test/chalk.js | 1 +
5 files changed, 25 insertions(+), 50 deletions(-)
diff --git a/examples/screenshot.js b/examples/screenshot.js
index 6d5ed15..6f66b77 100644
--- a/examples/screenshot.js
+++ b/examples/screenshot.js
@@ -1,3 +1,4 @@
+import process from 'node:process';
import styles from 'ansi-styles';
import chalk from '../source/index.js';
diff --git a/package.json b/package.json
index ef0cc13..703426b 100644
--- a/package.json
+++ b/package.json
@@ -42,7 +42,7 @@
],
"dependencies": {
"ansi-styles": "^6.1.0",
- "supports-color": "^9.0.2"
+ "supports-color": "^9.1.0"
},
"devDependencies": {
"ava": "^3.15.0",
@@ -54,7 +54,7 @@
"nyc": "^15.1.0",
"tsd": "^0.17.0",
"typescript": "^4.3.5",
- "xo": "^0.42.0",
+ "xo": "^0.46.4",
"yoctodelay": "^1.2.0"
},
"types": "./source/index.d.ts",
diff --git a/source/index.d.ts b/source/index.d.ts
index a6c6f76..cf6fb33 100644
--- a/source/index.d.ts
+++ b/source/index.d.ts
@@ -1,3 +1,5 @@
+import {ColorInfo, ColorSupportLevel} from 'supports-color';
+
/**
Basic foreground colors.
@@ -67,15 +69,6 @@ export type Modifiers =
| 'strikethrough'
| 'visible';
-/**
-Levels:
-- `0` - All colors disabled.
-- `1` - Basic 16 colors support.
-- `2` - ANSI 256 colors support.
-- `3` - Truecolor 16 million colors support.
-*/
-export type ColorSupportLevel = 0 | 1 | 2 | 3;
-
export interface Options {
/**
Specify the color support for Chalk.
@@ -94,32 +87,7 @@ export interface Options {
/**
Return a new Chalk instance.
*/
-export const Chalk: new (options?: Options) => ChalkInstance;
-
-/**
-Detect whether the terminal supports color.
-*/
-export interface ColorSupport {
- /**
- The color level used by Chalk.
- */
- level: ColorSupportLevel;
-
- /**
- Return whether Chalk supports basic 16 colors.
- */
- hasBasic: boolean;
-
- /**
- Return whether Chalk supports ANSI 256 colors.
- */
- has256: boolean;
-
- /**
- Return whether Chalk supports Truecolor 16 million colors.
- */
- has16m: boolean;
-}
+export const Chalk: new (options?: Options) => ChalkInstance; // eslint-disable-line @typescript-eslint/naming-convention
export interface ChalkInstance {
(...text: unknown[]): string;
@@ -333,9 +301,15 @@ This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
*/
declare const chalk: ChalkInstance;
-export const supportsColor: ColorSupport | false;
+export const supportsColor: ColorInfo;
export const chalkStderr: typeof chalk;
export const supportsColorStderr: typeof supportsColor;
+export {
+ ColorInfo,
+ ColorSupport,
+ ColorSupportLevel,
+} from 'supports-color';
+
export default chalk;
diff --git a/source/index.test-d.ts b/source/index.test-d.ts
index 2bd0ed5..a1ef854 100644
--- a/source/index.test-d.ts
+++ b/source/index.test-d.ts
@@ -1,12 +1,11 @@
import {expectType, expectAssignable, expectError} from 'tsd';
-import chalk, {Chalk, ChalkInstance, Color, ColorSupport, ColorSupportLevel, chalkStderr, supportsColor, supportsColorStderr} from './index.js';
-
-// - Helpers -
-type colorReturn = ChalkInstance & {supportsColor?: never};
+import chalk, {Chalk, ChalkInstance, Color, ColorInfo, ColorSupport, ColorSupportLevel, chalkStderr, supportsColor, supportsColorStderr} from './index.js';
// - supportsColor -
-expectType(supportsColor);
+expectType(supportsColor);
if (supportsColor) {
+ expectType(supportsColor);
+ expectType(supportsColor.level);
expectType(supportsColor.hasBasic);
expectType(supportsColor.has256);
expectType(supportsColor.has16m);
@@ -14,7 +13,7 @@ if (supportsColor) {
// - stderr -
expectAssignable(chalkStderr);
-expectType(supportsColorStderr);
+expectType(supportsColorStderr);
if (supportsColorStderr) {
expectType(supportsColorStderr.hasBasic);
expectType(supportsColorStderr.has256);
@@ -35,12 +34,12 @@ expectType(new Chalk({level: 1}));
expectType(chalk.level);
// -- Color methods --
-expectAssignable(chalk.rgb(0, 0, 0));
-expectAssignable(chalk.hex('#DEADED'));
-expectAssignable(chalk.ansi256(0));
-expectAssignable(chalk.bgRgb(0, 0, 0));
-expectAssignable(chalk.bgHex('#DEADED'));
-expectAssignable(chalk.bgAnsi256(0));
+expectType(chalk.rgb(0, 0, 0));
+expectType(chalk.hex('#DEADED'));
+expectType(chalk.ansi256(0));
+expectType(chalk.bgRgb(0, 0, 0));
+expectType(chalk.bgHex('#DEADED'));
+expectType(chalk.bgAnsi256(0));
// -- Modifiers --
expectType(chalk.reset('foo'));
diff --git a/test/chalk.js b/test/chalk.js
index 32b57c6..8d58e45 100644
--- a/test/chalk.js
+++ b/test/chalk.js
@@ -1,3 +1,4 @@
+import process from 'node:process';
import test from 'ava';
import chalk, {Chalk, chalkStderr} from '../source/index.js';
From d7c4aac07e422c8ae534897b3f1707aa71a51c73 Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Fri, 26 Nov 2021 16:00:01 +0700
Subject: [PATCH 28/72] Upgrade dependencies
---
package.json | 12 ++++++------
test/level.js | 4 ++--
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/package.json b/package.json
index 703426b..412fdad 100644
--- a/package.json
+++ b/package.json
@@ -48,14 +48,14 @@
"ava": "^3.15.0",
"color-convert": "^2.0.1",
"coveralls": "^3.1.1",
- "execa": "^5.1.1",
- "log-update": "^4.0.0",
+ "execa": "^6.0.0",
+ "log-update": "^5.0.0",
"matcha": "^0.7.0",
"nyc": "^15.1.0",
- "tsd": "^0.17.0",
- "typescript": "^4.3.5",
- "xo": "^0.46.4",
- "yoctodelay": "^1.2.0"
+ "tsd": "^0.19.0",
+ "typescript": "^4.5.2",
+ "xo": "^0.47.0",
+ "yoctodelay": "^2.0.0"
},
"types": "./source/index.d.ts",
"xo": {
diff --git a/test/level.js b/test/level.js
index 5fed269..f8efeba 100644
--- a/test/level.js
+++ b/test/level.js
@@ -1,6 +1,6 @@
import {fileURLToPath} from 'node:url';
import test from 'ava';
-import execa from 'execa';
+import {execaNode} from 'execa';
import chalk from '../source/index.js';
chalk.level = 1;
@@ -38,6 +38,6 @@ test('propagate enable/disable changes from child colors', t => {
});
test('disable colors if they are not supported', async t => {
- const {stdout} = await execa.node(fileURLToPath(new URL('./_fixture.js', import.meta.url)));
+ const {stdout} = await execaNode(fileURLToPath(new URL('./_fixture.js', import.meta.url)));
t.is(stdout, 'testout testerr');
});
From 04fdbd6d8d262ed8668cf3f2e94f647d2bc028d8 Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Fri, 26 Nov 2021 16:34:27 +0700
Subject: [PATCH 29/72] Bundle dependencies
---
package.json | 11 +-
source/index.d.ts | 7 +-
source/index.js | 8 +-
source/{util.js => utilities.js} | 0
source/vendor/ansi-styles/index.d.ts | 190 +++++++++++++++++++
source/vendor/ansi-styles/index.js | 219 ++++++++++++++++++++++
source/vendor/supports-color/browser.d.ts | 1 +
source/vendor/supports-color/browser.js | 17 ++
source/vendor/supports-color/index.d.ts | 55 ++++++
source/vendor/supports-color/index.js | 169 +++++++++++++++++
10 files changed, 667 insertions(+), 10 deletions(-)
rename source/{util.js => utilities.js} (100%)
create mode 100644 source/vendor/ansi-styles/index.d.ts
create mode 100644 source/vendor/ansi-styles/index.js
create mode 100644 source/vendor/supports-color/browser.d.ts
create mode 100644 source/vendor/supports-color/browser.js
create mode 100644 source/vendor/supports-color/index.d.ts
create mode 100644 source/vendor/supports-color/index.js
diff --git a/package.json b/package.json
index 412fdad..a9b7d79 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,13 @@
"funding": "https://github.com/chalk/chalk?sponsor=1",
"type": "module",
"exports": "./source/index.js",
+ "imports": {
+ "#ansi-styles": "./source/vendor/ansi-styles/index.js",
+ "#supports-color": {
+ "node": "./source/vendor/supports-color/index.js",
+ "default": "./source/vendor/supports-color/browser.js"
+ }
+ },
"engines": {
"node": "^12.17.0 || ^14.13 || >=16.0.0"
},
@@ -40,10 +47,6 @@
"command-line",
"text"
],
- "dependencies": {
- "ansi-styles": "^6.1.0",
- "supports-color": "^9.1.0"
- },
"devDependencies": {
"ava": "^3.15.0",
"color-convert": "^2.0.1",
diff --git a/source/index.d.ts b/source/index.d.ts
index cf6fb33..b2408c6 100644
--- a/source/index.d.ts
+++ b/source/index.d.ts
@@ -1,4 +1,6 @@
-import {ColorInfo, ColorSupportLevel} from 'supports-color';
+// TODO: Make it this when TS suports that.
+// import {ColorInfo, ColorSupportLevel} from '#supports-color';
+import {ColorInfo, ColorSupportLevel} from './vendor/supports-color/index.js';
/**
Basic foreground colors.
@@ -310,6 +312,7 @@ export {
ColorInfo,
ColorSupport,
ColorSupportLevel,
-} from 'supports-color';
+// } from '#supports-color';
+} from './vendor/supports-color/index.js';
export default chalk;
diff --git a/source/index.js b/source/index.js
index 6411672..302024b 100644
--- a/source/index.js
+++ b/source/index.js
@@ -1,9 +1,9 @@
-import ansiStyles from 'ansi-styles';
-import supportsColor from 'supports-color';
-import {
+import ansiStyles from '#ansi-styles';
+import supportsColor from '#supports-color';
+import { // eslint-disable-line import/order
stringReplaceAll,
stringEncaseCRLFWithFirstIndex,
-} from './util.js';
+} from './utilities.js';
const {stdout: stdoutColor, stderr: stderrColor} = supportsColor;
diff --git a/source/util.js b/source/utilities.js
similarity index 100%
rename from source/util.js
rename to source/utilities.js
diff --git a/source/vendor/ansi-styles/index.d.ts b/source/vendor/ansi-styles/index.d.ts
new file mode 100644
index 0000000..7518d2a
--- /dev/null
+++ b/source/vendor/ansi-styles/index.d.ts
@@ -0,0 +1,190 @@
+export interface CSPair { // eslint-disable-line @typescript-eslint/naming-convention
+ /**
+ The ANSI terminal control sequence for starting this style.
+ */
+ readonly open: string;
+
+ /**
+ The ANSI terminal control sequence for ending this style.
+ */
+ readonly close: string;
+}
+
+export interface ColorBase {
+ /**
+ The ANSI terminal control sequence for ending this color.
+ */
+ readonly close: string;
+
+ ansi(code: number): string;
+
+ ansi256(code: number): string;
+
+ ansi16m(red: number, green: number, blue: number): string;
+}
+
+export interface Modifier {
+ /**
+ Resets the current color chain.
+ */
+ readonly reset: CSPair;
+
+ /**
+ Make text bold.
+ */
+ readonly bold: CSPair;
+
+ /**
+ Emitting only a small amount of light.
+ */
+ readonly dim: CSPair;
+
+ /**
+ Make text italic. (Not widely supported)
+ */
+ readonly italic: CSPair;
+
+ /**
+ Make text underline. (Not widely supported)
+ */
+ readonly underline: CSPair;
+
+ /**
+ Make text overline.
+
+ Supported on VTE-based terminals, the GNOME terminal, mintty, and Git Bash.
+ */
+ readonly overline: CSPair;
+
+ /**
+ Inverse background and foreground colors.
+ */
+ readonly inverse: CSPair;
+
+ /**
+ Prints the text, but makes it invisible.
+ */
+ readonly hidden: CSPair;
+
+ /**
+ Puts a horizontal line through the center of the text. (Not widely supported)
+ */
+ readonly strikethrough: CSPair;
+}
+
+export interface ForegroundColor {
+ readonly black: CSPair;
+ readonly red: CSPair;
+ readonly green: CSPair;
+ readonly yellow: CSPair;
+ readonly blue: CSPair;
+ readonly cyan: CSPair;
+ readonly magenta: CSPair;
+ readonly white: CSPair;
+
+ /**
+ Alias for `blackBright`.
+ */
+ readonly gray: CSPair;
+
+ /**
+ Alias for `blackBright`.
+ */
+ readonly grey: CSPair;
+
+ readonly blackBright: CSPair;
+ readonly redBright: CSPair;
+ readonly greenBright: CSPair;
+ readonly yellowBright: CSPair;
+ readonly blueBright: CSPair;
+ readonly cyanBright: CSPair;
+ readonly magentaBright: CSPair;
+ readonly whiteBright: CSPair;
+}
+
+export interface BackgroundColor {
+ readonly bgBlack: CSPair;
+ readonly bgRed: CSPair;
+ readonly bgGreen: CSPair;
+ readonly bgYellow: CSPair;
+ readonly bgBlue: CSPair;
+ readonly bgCyan: CSPair;
+ readonly bgMagenta: CSPair;
+ readonly bgWhite: CSPair;
+
+ /**
+ Alias for `bgBlackBright`.
+ */
+ readonly bgGray: CSPair;
+
+ /**
+ Alias for `bgBlackBright`.
+ */
+ readonly bgGrey: CSPair;
+
+ readonly bgBlackBright: CSPair;
+ readonly bgRedBright: CSPair;
+ readonly bgGreenBright: CSPair;
+ readonly bgYellowBright: CSPair;
+ readonly bgBlueBright: CSPair;
+ readonly bgCyanBright: CSPair;
+ readonly bgMagentaBright: CSPair;
+ readonly bgWhiteBright: CSPair;
+}
+
+export interface ConvertColor {
+ /**
+ Convert from the RGB color space to the ANSI 256 color space.
+
+ @param red - (`0...255`)
+ @param green - (`0...255`)
+ @param blue - (`0...255`)
+ */
+ rgbToAnsi256(red: number, green: number, blue: number): number;
+
+ /**
+ Convert from the RGB HEX color space to the RGB color space.
+
+ @param hex - A hexadecimal string containing RGB data.
+ */
+ hexToRgb(hex: string): [red: number, green: number, blue: number];
+
+ /**
+ Convert from the RGB HEX color space to the ANSI 256 color space.
+
+ @param hex - A hexadecimal string containing RGB data.
+ */
+ hexToAnsi256(hex: string): number;
+
+ /**
+ Convert from the ANSI 256 color space to the ANSI 16 color space.
+
+ @param code - A number representing the ANSI 256 color.
+ */
+ ansi256ToAnsi(code: number): number;
+
+ /**
+ Convert from the RGB color space to the ANSI 16 color space.
+
+ @param red - (`0...255`)
+ @param green - (`0...255`)
+ @param blue - (`0...255`)
+ */
+ rgbToAnsi(red: number, green: number, blue: number): number;
+
+ /**
+ Convert from the RGB HEX color space to the ANSI 16 color space.
+
+ @param hex - A hexadecimal string containing RGB data.
+ */
+ hexToAnsi(hex: string): number;
+}
+
+declare const ansiStyles: {
+ readonly modifier: Modifier;
+ readonly color: ColorBase & ForegroundColor;
+ readonly bgColor: ColorBase & BackgroundColor;
+ readonly codes: ReadonlyMap;
+} & ForegroundColor & BackgroundColor & Modifier & ConvertColor;
+
+export default ansiStyles;
diff --git a/source/vendor/ansi-styles/index.js b/source/vendor/ansi-styles/index.js
new file mode 100644
index 0000000..5746537
--- /dev/null
+++ b/source/vendor/ansi-styles/index.js
@@ -0,0 +1,219 @@
+const ANSI_BACKGROUND_OFFSET = 10;
+
+const wrapAnsi16 = (offset = 0) => code => `\u001B[${code + offset}m`;
+
+const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`;
+
+const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
+
+function assembleStyles() {
+ const codes = new Map();
+ const styles = {
+ modifier: {
+ reset: [0, 0],
+ // 21 isn't widely supported and 22 does the same thing
+ bold: [1, 22],
+ dim: [2, 22],
+ italic: [3, 23],
+ underline: [4, 24],
+ overline: [53, 55],
+ inverse: [7, 27],
+ hidden: [8, 28],
+ strikethrough: [9, 29],
+ },
+ color: {
+ black: [30, 39],
+ red: [31, 39],
+ green: [32, 39],
+ yellow: [33, 39],
+ blue: [34, 39],
+ magenta: [35, 39],
+ cyan: [36, 39],
+ white: [37, 39],
+
+ // Bright color
+ blackBright: [90, 39],
+ redBright: [91, 39],
+ greenBright: [92, 39],
+ yellowBright: [93, 39],
+ blueBright: [94, 39],
+ magentaBright: [95, 39],
+ cyanBright: [96, 39],
+ whiteBright: [97, 39],
+ },
+ bgColor: {
+ bgBlack: [40, 49],
+ bgRed: [41, 49],
+ bgGreen: [42, 49],
+ bgYellow: [43, 49],
+ bgBlue: [44, 49],
+ bgMagenta: [45, 49],
+ bgCyan: [46, 49],
+ bgWhite: [47, 49],
+
+ // Bright color
+ bgBlackBright: [100, 49],
+ bgRedBright: [101, 49],
+ bgGreenBright: [102, 49],
+ bgYellowBright: [103, 49],
+ bgBlueBright: [104, 49],
+ bgMagentaBright: [105, 49],
+ bgCyanBright: [106, 49],
+ bgWhiteBright: [107, 49],
+ },
+ };
+
+ // Alias bright black as gray (and grey)
+ styles.color.gray = styles.color.blackBright;
+ styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
+ styles.color.grey = styles.color.blackBright;
+ styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
+
+ for (const [groupName, group] of Object.entries(styles)) {
+ for (const [styleName, style] of Object.entries(group)) {
+ styles[styleName] = {
+ open: `\u001B[${style[0]}m`,
+ close: `\u001B[${style[1]}m`,
+ };
+
+ group[styleName] = styles[styleName];
+
+ codes.set(style[0], style[1]);
+ }
+
+ Object.defineProperty(styles, groupName, {
+ value: group,
+ enumerable: false,
+ });
+ }
+
+ Object.defineProperty(styles, 'codes', {
+ value: codes,
+ enumerable: false,
+ });
+
+ styles.color.close = '\u001B[39m';
+ styles.bgColor.close = '\u001B[49m';
+
+ styles.color.ansi = wrapAnsi16();
+ styles.color.ansi256 = wrapAnsi256();
+ styles.color.ansi16m = wrapAnsi16m();
+ styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
+ styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
+ styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
+
+ // From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js
+ Object.defineProperties(styles, {
+ rgbToAnsi256: {
+ value: (red, green, blue) => {
+ // We use the extended greyscale palette here, with the exception of
+ // black and white. normal palette only has 4 greyscale shades.
+ if (red === green && green === blue) {
+ if (red < 8) {
+ return 16;
+ }
+
+ if (red > 248) {
+ return 231;
+ }
+
+ return Math.round(((red - 8) / 247) * 24) + 232;
+ }
+
+ return 16
+ + (36 * Math.round(red / 255 * 5))
+ + (6 * Math.round(green / 255 * 5))
+ + Math.round(blue / 255 * 5);
+ },
+ enumerable: false,
+ },
+ hexToRgb: {
+ value: hex => {
+ const matches = /(?[a-f\d]{6}|[a-f\d]{3})/i.exec(hex.toString(16));
+ if (!matches) {
+ return [0, 0, 0];
+ }
+
+ let {colorString} = matches.groups;
+
+ if (colorString.length === 3) {
+ colorString = [...colorString].map(character => character + character).join('');
+ }
+
+ const integer = Number.parseInt(colorString, 16);
+
+ return [
+ /* eslint-disable no-bitwise */
+ (integer >> 16) & 0xFF,
+ (integer >> 8) & 0xFF,
+ integer & 0xFF,
+ /* eslint-enable no-bitwise */
+ ];
+ },
+ enumerable: false,
+ },
+ hexToAnsi256: {
+ value: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
+ enumerable: false,
+ },
+ ansi256ToAnsi: {
+ value: code => {
+ if (code < 8) {
+ return 30 + code;
+ }
+
+ if (code < 16) {
+ return 90 + (code - 8);
+ }
+
+ let red;
+ let green;
+ let blue;
+
+ if (code >= 232) {
+ red = (((code - 232) * 10) + 8) / 255;
+ green = red;
+ blue = red;
+ } else {
+ code -= 16;
+
+ const remainder = code % 36;
+
+ red = Math.floor(code / 36) / 5;
+ green = Math.floor(remainder / 6) / 5;
+ blue = (remainder % 6) / 5;
+ }
+
+ const value = Math.max(red, green, blue) * 2;
+
+ if (value === 0) {
+ return 30;
+ }
+
+ // eslint-disable-next-line no-bitwise
+ let result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));
+
+ if (value === 2) {
+ result += 60;
+ }
+
+ return result;
+ },
+ enumerable: false,
+ },
+ rgbToAnsi: {
+ value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
+ enumerable: false,
+ },
+ hexToAnsi: {
+ value: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
+ enumerable: false,
+ },
+ });
+
+ return styles;
+}
+
+const ansiStyles = assembleStyles();
+
+export default ansiStyles;
diff --git a/source/vendor/supports-color/browser.d.ts b/source/vendor/supports-color/browser.d.ts
new file mode 100644
index 0000000..0e8a9cc
--- /dev/null
+++ b/source/vendor/supports-color/browser.d.ts
@@ -0,0 +1 @@
+export {default} from './index.js';
diff --git a/source/vendor/supports-color/browser.js b/source/vendor/supports-color/browser.js
new file mode 100644
index 0000000..f4e9acd
--- /dev/null
+++ b/source/vendor/supports-color/browser.js
@@ -0,0 +1,17 @@
+/* eslint-env browser */
+
+const isBlinkBasedBrowser = /\b(Chrome|Chromium)\//.test(navigator.userAgent);
+
+const colorSupport = isBlinkBasedBrowser ? {
+ level: 1,
+ hasBasic: true,
+ has256: false,
+ has16m: false,
+} : false;
+
+const supportsColor = {
+ stdout: colorSupport,
+ stderr: colorSupport,
+};
+
+export default supportsColor;
diff --git a/source/vendor/supports-color/index.d.ts b/source/vendor/supports-color/index.d.ts
new file mode 100644
index 0000000..98e3618
--- /dev/null
+++ b/source/vendor/supports-color/index.d.ts
@@ -0,0 +1,55 @@
+import {WriteStream} from 'node:tty';
+
+export interface Options {
+ /**
+ Whether `process.argv` should be sniffed for `--color` and `--no-color` flags.
+
+ @default true
+ */
+ readonly sniffFlags?: boolean;
+}
+
+/**
+Levels:
+- `0` - All colors disabled.
+- `1` - Basic 16 colors support.
+- `2` - ANSI 256 colors support.
+- `3` - Truecolor 16 million colors support.
+*/
+export type ColorSupportLevel = 0 | 1 | 2 | 3;
+
+/**
+Detect whether the terminal supports color.
+*/
+export interface ColorSupport {
+ /**
+ The color level.
+ */
+ level: ColorSupportLevel;
+
+ /**
+ Whether basic 16 colors are supported.
+ */
+ hasBasic: boolean;
+
+ /**
+ Whether ANSI 256 colors are supported.
+ */
+ has256: boolean;
+
+ /**
+ Whether Truecolor 16 million colors are supported.
+ */
+ has16m: boolean;
+}
+
+export type ColorInfo = ColorSupport | false;
+
+export function createSupportsColor(stream: WriteStream, options?: Options): ColorInfo;
+
+declare const supportsColor: {
+ stdout: ColorInfo;
+ stderr: ColorInfo;
+};
+
+export default supportsColor;
diff --git a/source/vendor/supports-color/index.js b/source/vendor/supports-color/index.js
new file mode 100644
index 0000000..55f813c
--- /dev/null
+++ b/source/vendor/supports-color/index.js
@@ -0,0 +1,169 @@
+import process from 'node:process';
+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 = process.argv) {
+ const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
+ const position = argv.indexOf(prefix + flag);
+ const terminatorPosition = argv.indexOf('--');
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
+}
+
+const {env} = process;
+
+let flagForceColor;
+if (
+ hasFlag('no-color')
+ || hasFlag('no-colors')
+ || hasFlag('color=false')
+ || hasFlag('color=never')
+) {
+ flagForceColor = 0;
+} else if (
+ hasFlag('color')
+ || hasFlag('colors')
+ || hasFlag('color=true')
+ || hasFlag('color=always')
+) {
+ flagForceColor = 1;
+}
+
+function envForceColor() {
+ if ('FORCE_COLOR' in env) {
+ if (env.FORCE_COLOR === 'true') {
+ return 1;
+ }
+
+ if (env.FORCE_COLOR === 'false') {
+ return 0;
+ }
+
+ return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
+ }
+}
+
+function translateLevel(level) {
+ if (level === 0) {
+ return false;
+ }
+
+ return {
+ level,
+ hasBasic: true,
+ has256: level >= 2,
+ has16m: level >= 3,
+ };
+}
+
+function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
+ const noFlagForceColor = envForceColor();
+ if (noFlagForceColor !== undefined) {
+ flagForceColor = noFlagForceColor;
+ }
+
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
+
+ if (forceColor === 0) {
+ return 0;
+ }
+
+ if (sniffFlags) {
+ if (hasFlag('color=16m')
+ || hasFlag('color=full')
+ || hasFlag('color=truecolor')) {
+ return 3;
+ }
+
+ if (hasFlag('color=256')) {
+ return 2;
+ }
+ }
+
+ if (haveStream && !streamIsTTY && forceColor === undefined) {
+ return 0;
+ }
+
+ const min = forceColor || 0;
+
+ if (env.TERM === 'dumb') {
+ return min;
+ }
+
+ if (process.platform === 'win32') {
+ // Windows 10 build 10586 is the first Windows release that supports 256 colors.
+ // Windows 10 build 14931 is the first release that supports 16m/TrueColor.
+ const osRelease = os.release().split('.');
+ if (
+ Number(osRelease[0]) >= 10
+ && Number(osRelease[2]) >= 10_586
+ ) {
+ return Number(osRelease[2]) >= 14_931 ? 3 : 2;
+ }
+
+ return 1;
+ }
+
+ if ('CI' in env) {
+ if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
+ return 1;
+ }
+
+ return min;
+ }
+
+ if ('TEAMCITY_VERSION' in env) {
+ 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 ('TERM_PROGRAM' in env) {
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
+
+ switch (env.TERM_PROGRAM) {
+ case 'iTerm.app':
+ return version >= 3 ? 3 : 2;
+ case 'Apple_Terminal':
+ return 2;
+ // No default
+ }
+ }
+
+ if (/-256(color)?$/i.test(env.TERM)) {
+ return 2;
+ }
+
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
+ return 1;
+ }
+
+ if ('COLORTERM' in env) {
+ return 1;
+ }
+
+ return min;
+}
+
+export function createSupportsColor(stream, options = {}) {
+ const level = _supportsColor(stream, {
+ streamIsTTY: stream && stream.isTTY,
+ ...options,
+ });
+
+ return translateLevel(level);
+}
+
+const supportsColor = {
+ stdout: createSupportsColor({isTTY: tty.isatty(1)}),
+ stderr: createSupportsColor({isTTY: tty.isatty(2)}),
+};
+
+export default supportsColor;
From 7a6893551d93ebe0bd031141b3e2b91d7e0676aa Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Fri, 26 Nov 2021 16:50:15 +0700
Subject: [PATCH 30/72] Fix code coverage
---
.github/workflows/main.yml | 5 +++++
package.json | 21 ++++++++++++++-------
readme.md | 5 ++++-
source/utilities.js | 1 +
4 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index d36e1a8..ef5d807 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -10,6 +10,7 @@ jobs:
fail-fast: false
matrix:
node-version:
+ - 16
- 14
- 12
steps:
@@ -19,3 +20,7 @@ jobs:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
+ - uses: codecov/codecov-action@v2
+ if: matrix.node-version == 16
+ with:
+ fail_ci_if_error: true
diff --git a/package.json b/package.json
index a9b7d79..fd72b27 100644
--- a/package.json
+++ b/package.json
@@ -14,11 +14,12 @@
"default": "./source/vendor/supports-color/browser.js"
}
},
+ "types": "./source/index.d.ts",
"engines": {
"node": "^12.17.0 || ^14.13 || >=16.0.0"
},
"scripts": {
- "test": "xo && nyc ava && tsd",
+ "test": "xo && c8 ava && tsd",
"bench": "matcha benchmark.js"
},
"files": [
@@ -48,23 +49,29 @@
"text"
],
"devDependencies": {
+ "@types/node": "^16.11.10",
"ava": "^3.15.0",
+ "c8": "^7.10.0",
"color-convert": "^2.0.1",
- "coveralls": "^3.1.1",
"execa": "^6.0.0",
"log-update": "^5.0.0",
"matcha": "^0.7.0",
- "nyc": "^15.1.0",
"tsd": "^0.19.0",
- "typescript": "^4.5.2",
"xo": "^0.47.0",
"yoctodelay": "^2.0.0"
},
- "types": "./source/index.d.ts",
"xo": {
"rules": {
- "unicorn/prefer-string-slice": "off",
- "unicorn/better-regex": "off"
+ "unicorn/prefer-string-slice": "off"
}
+ },
+ "c8": {
+ "reporter": [
+ "text",
+ "lcov"
+ ],
+ "exclude": [
+ "source/vendor"
+ ]
}
}
diff --git a/readme.md b/readme.md
index ed157bd..f6adc80 100644
--- a/readme.md
+++ b/readme.md
@@ -9,7 +9,7 @@
> Terminal string styling done right
-[](https://coveralls.io/github/chalk/chalk?branch=main)
+[](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)
[](https://stakes.social/0x44d871aebF0126Bf646753E2C976Aa7e68A66c15)
@@ -72,6 +72,7 @@
- Expressive API
- Highly performant
+- No dependencies
- Ability to nest styles
- [256/Truecolor color support](#256-and-truecolor-color-support)
- Auto-detects color support
@@ -86,6 +87,8 @@
npm install chalk
```
+**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)
+
## Usage
```js
diff --git a/source/utilities.js b/source/utilities.js
index 4d8bc4a..5d49dad 100644
--- a/source/utilities.js
+++ b/source/utilities.js
@@ -1,3 +1,4 @@
+// TODO: When targeting Node.js 16, use `String.prototype.replaceAll`.
export function stringReplaceAll(string, substring, replacer) {
let index = string.indexOf(substring);
if (index === -1) {
From 4d5c4795ad24c326ae16bfe0c39c826c732716a9 Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Fri, 26 Nov 2021 16:57:26 +0700
Subject: [PATCH 31/72] 5.0.0
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index fd72b27..f693c87 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "chalk",
- "version": "4.1.0",
+ "version": "5.0.0",
"description": "Terminal string styling done right",
"license": "MIT",
"repository": "chalk/chalk",
From 85f7e96f758e95dee5211b9bca1a173b8fb3abe9 Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Wed, 9 Mar 2022 01:42:04 +0700
Subject: [PATCH 32/72] Add `main` field to package.json for backwards
compatibiltiy
Fixes #536
---
package.json | 1 +
1 file changed, 1 insertion(+)
diff --git a/package.json b/package.json
index f693c87..d3d644b 100644
--- a/package.json
+++ b/package.json
@@ -6,6 +6,7 @@
"repository": "chalk/chalk",
"funding": "https://github.com/chalk/chalk?sponsor=1",
"type": "module",
+ "main": "./source/index.js",
"exports": "./source/index.js",
"imports": {
"#ansi-styles": "./source/vendor/ansi-styles/index.js",
From bccde97f8a1bb125d4fe99e8fd355182101ff4f2 Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Wed, 9 Mar 2022 01:43:33 +0700
Subject: [PATCH 33/72] 5.0.1
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index d3d644b..7daddb2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "chalk",
- "version": "5.0.0",
+ "version": "5.0.1",
"description": "Terminal string styling done right",
"license": "MIT",
"repository": "chalk/chalk",
From d28690e66b184dc19b9baaea1cce900737aa8ccc Mon Sep 17 00:00:00 2001
From: CommanderRoot
Date: Sun, 27 Mar 2022 20:11:02 +0200
Subject: [PATCH 34/72] Refactor: Replace deprecated `String#substr()` (#541)
---
source/utilities.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/source/utilities.js b/source/utilities.js
index 5d49dad..4366dee 100644
--- a/source/utilities.js
+++ b/source/utilities.js
@@ -9,7 +9,7 @@ export function stringReplaceAll(string, substring, replacer) {
let endIndex = 0;
let returnValue = '';
do {
- returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
+ returnValue += string.slice(endIndex, index) + substring + replacer;
endIndex = index + substringLength;
index = string.indexOf(substring, endIndex);
} while (index !== -1);
@@ -23,7 +23,7 @@ export function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
let returnValue = '';
do {
const gotCR = string[index - 1] === '\r';
- returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
+ returnValue += string.slice(endIndex, (gotCR ? index - 1 : index)) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
endIndex = index + 1;
index = string.indexOf('\n', endIndex);
} while (index !== -1);
From b17d862944f9efea1ee12aaf80fe19ed5063a34d Mon Sep 17 00:00:00 2001
From: Richie Bendall
Date: Wed, 30 Mar 2022 18:41:57 +1300
Subject: [PATCH 35/72] Improve browser detection (#542)
---
source/vendor/supports-color/browser.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/source/vendor/supports-color/browser.js b/source/vendor/supports-color/browser.js
index f4e9acd..4e75e86 100644
--- a/source/vendor/supports-color/browser.js
+++ b/source/vendor/supports-color/browser.js
@@ -1,6 +1,8 @@
/* eslint-env browser */
-const isBlinkBasedBrowser = /\b(Chrome|Chromium)\//.test(navigator.userAgent);
+const isBlinkBasedBrowser = navigator.userAgentData
+ ? navigator.userAgentData.brands.some(({brand}) => brand === 'Chromium')
+ : /\b(Chrome|Chromium)\//.test(navigator.userAgent);
const colorSupport = isBlinkBasedBrowser ? {
level: 1,
From 503b9d35cd0a1fe2ac80deadd06def00db8221a0 Mon Sep 17 00:00:00 2001
From: LitoMore
Date: Sun, 26 Jun 2022 20:58:46 +0800
Subject: [PATCH 36/72] Update Replit badge (#551)
---
readme.md | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/readme.md b/readme.md
index f6adc80..b57510e 100644
--- a/readme.md
+++ b/readme.md
@@ -10,8 +10,9 @@
> Terminal string styling done right
[](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)
+[](https://www.npmjs.com/package/chalk?activeTab=dependents)
+[](https://www.npmjs.com/package/chalk)
+[](https://repl.it/github/chalk/chalk)
[](https://stakes.social/0x44d871aebF0126Bf646753E2C976Aa7e68A66c15)
From ba5c385ecf6c2ad8a0fadb8b94e1ea515c8f9496 Mon Sep 17 00:00:00 2001
From: Sindre Sorhus
Date: Sun, 3 Jul 2022 00:36:34 +0200
Subject: [PATCH 37/72] Update screenshot
Fixes #554
---
examples/screenshot.js | 11 ++++++++++-
media/screenshot.png | Bin 0 -> 240871 bytes
readme.md | 2 +-
3 files changed, 11 insertions(+), 2 deletions(-)
create mode 100644 media/screenshot.png
diff --git a/examples/screenshot.js b/examples/screenshot.js
index 6f66b77..9ad164b 100644
--- a/examples/screenshot.js
+++ b/examples/screenshot.js
@@ -6,7 +6,16 @@ import chalk from '../source/index.js';
for (const key of Object.keys(styles)) {
let returnValue = key;
- if (key === 'reset' || key === 'hidden' || key === 'grey') {
+ // We skip `overline` as almost no terminal supports it so we cannot show it off.
+ if (
+ key === 'reset'
+ || key === 'hidden'
+ || key === 'grey'
+ || key === 'bgGray'
+ || key === 'bgGrey'
+ || key === 'overline'
+ || key.endsWith('Bright')
+ ) {
continue;
}
diff --git a/media/screenshot.png b/media/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