FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Require Node.js 22 · chalk/chalk@8a94e0e · GitHub

Repository navigation

Commit 8a94e0e

Browse files
committed
Require Node.js 22
1 parent fa5cff2 commit 8a94e0e

14 files changed

Lines changed: 113 additions & 283 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
matrix:
1212
node-version:
1313
- 26
14-
- 14
14+
- 22
1515
steps:
1616
- uses: actions/checkout@v7
1717
- uses: actions/setup-node@v6

‎examples/rainbow.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import convertColor from 'color-convert';
33
import updateLog from 'log-update';
44
import chalk from '../source/index.js';
55

6-
const ignoreCharacters = /[^\u{0021}-\u{007E}]/gu;
6+
const ignoreCharacters = /[^\u{0021}-\u{007E}]/gv;
77

88
function rainbow(string, offset) {
99
if (!string || string.length === 0) {

‎examples/screenshot.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ for (const key of Object.keys(styles)) {
1919
continue;
2020
}
2121

22-
if (/^bg[^B]/.test(key)) {
22+
if (/^bg[^B]/v.test(key)) {
2323
returnValue = chalk.black(returnValue);
2424
}
2525

‎package.json‎

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@
66
"repository": "chalk/chalk",
77
"funding": "https://github.com/chalk/chalk?sponsor=1",
88
"type": "module",
9-
"main": "./source/index.js",
10-
"exports": "./source/index.js",
9+
"exports": {
10+
"types": "./source/index.d.ts",
11+
"default": "./source/index.js"
12+
},
1113
"imports": {
1214
"#ansi-styles": "./source/vendor/ansi-styles/index.js",
1315
"#supports-color": {
1416
"node": "./source/vendor/supports-color/index.js",
1517
"default": "./source/vendor/supports-color/browser.js"
1618
}
1719
},
18-
"types": "./source/index.d.ts",
1920
"sideEffects": false,
2021
"engines": {
21-
"node": "^12.17.0 || ^14.13 || >=16.0.0"
22+
"node": ">=22"
2223
},
2324
"scripts": {
24-
"test": "xo && c8 ava && tsd",
25+
"test": "xo && c8 ava && tsc --noEmit --types node source/index.d.ts",
2526
"bench": "matcha benchmark.js"
2627
},
2728
"files": [
28-
"source",
29-
"!source/index.test-d.ts"
29+
"source"
3030
],
3131
"keywords": [
3232
"color",
@@ -51,31 +51,35 @@
5151
"text"
5252
],
5353
"devDependencies": {
54-
"@types/node": "^16.11.10",
54+
"@types/node": "^26.1.1",
5555
"ansi-styles": "^6.2.3",
56-
"ava": "^3.15.0",
57-
"c8": "^7.10.0",
58-
"color-convert": "^2.0.1",
59-
"execa": "^6.0.0",
60-
"log-update": "^5.0.0",
56+
"ava": "^8.0.1",
57+
"c8": "^12.0.0",
58+
"color-convert": "^3.1.3",
59+
"execa": "^10.0.0",
60+
"log-update": "^8.0.0",
6161
"matcha": "^0.7.0",
62-
"tsd": "^0.19.0",
63-
"xo": "^0.54.2",
62+
"typescript": "^6.0.3",
63+
"xo": "^4.0.0",
6464
"yoctodelay": "^2.0.0"
6565
},
66-
"xo": {
67-
"ignores": [
68-
"source/vendor"
69-
],
70-
"rules": {
71-
"unicorn/prefer-string-slice": "off",
72-
"@typescript-eslint/consistent-type-imports": "off",
73-
"@typescript-eslint/consistent-type-exports": "off",
74-
"@typescript-eslint/consistent-type-definitions": "off",
75-
"unicorn/expiring-todo-comments": "off",
76-
"no-warning-comments": "off"
66+
"xo": [
67+
{
68+
"ignores": [
69+
"source/vendor"
70+
]
71+
},
72+
{
73+
"rules": {
74+
"unicorn/prefer-string-slice": "off",
75+
"@typescript-eslint/consistent-type-imports": "off",
76+
"@typescript-eslint/consistent-type-exports": "off",
77+
"@typescript-eslint/consistent-type-definitions": "off",
78+
"unicorn/expiring-todo-comments": "off",
79+
"no-warning-comments": "off"
80+
}
7781
}
78-
},
82+
],
7983
"c8": {
8084
"reporter": [
8185
"text",

‎source/index.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const levelMapping = [
2222
const styles = Object.create(null);
2323

2424
const applyOptions = (object, options = {}) => {
25-
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
25+
if (options.level && !(Number.isSafeInteger(options.level) && options.level >= 0 && options.level <= 3)) {
2626
throw new Error('The `level` option should be an integer from 0 to 3');
2727
}
2828

@@ -51,6 +51,7 @@ function createChalk(options) {
5151
return chalkFactory(options);
5252
}
5353

54+
// eslint-disable-next-line unicorn/no-top-level-side-effects -- The prototype chain must be set up at module load.
5455
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
5556

5657
for (const [styleName, style] of Object.entries(ansiStyles)) {
@@ -185,6 +186,7 @@ const createBuilder = (self, _styler, _isEmpty) => {
185186
const applyStyle = (self, string) => {
186187
// Read the level directly off the generator to skip the `level` getter dispatch on this hot path
187188
if (self[GENERATOR].level <= 0 || !string) {
189+
// eslint-disable-next-line unicorn/no-computed-property-existence-check -- Reads the boolean value, not a property existence check.
188190
return self[IS_EMPTY] ? '' : string;
189191
}
190192

@@ -195,7 +197,7 @@ const applyStyle = (self, string) => {
195197
}
196198

197199
const {openAll, closeAll} = styler;
198-
if (string.includes('\u001B')) {
200+
if (string.includes('\u{1B}')) {
199201
while (styler !== undefined) {
200202
// Replace any instances already present with a re-opening code
201203
// otherwise only the part of the string until said closing code
@@ -217,6 +219,7 @@ const applyStyle = (self, string) => {
217219
return openAll + string + closeAll;
218220
};
219221

222+
// eslint-disable-next-line unicorn/no-top-level-side-effects -- The style getters must be installed at module load.
220223
Object.defineProperties(createChalk.prototype, styles);
221224

222225
const chalk = createChalk();

‎source/index.test-d.ts‎

Lines changed: 0 additions & 179 deletions
This file was deleted.

‎source/utilities.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
2222
let endIndex = 0;
2323
let returnValue = '';
2424
do {
25-
const gotCR = string[index - 1] === '\r';
26-
returnValue += string.slice(endIndex, (gotCR ? index - 1 : index)) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
25+
const isGotCR = string[index - 1] === '\r';
26+
returnValue += string.slice(endIndex, (isGotCR ? index - 1 : index)) + prefix + (isGotCR ? '\r\n' : '\n') + postfix;
2727
endIndex = index + 1;
2828
index = string.indexOf('\n', endIndex);
2929
} while (index !== -1);

‎source/vendor/ansi-styles/index.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const ANSI_BACKGROUND_OFFSET = 10;
22

3-
const wrapAnsi16 = (offset = 0) => code => `\u001B[${code + offset}m`;
3+
const wrapAnsi16 = (offset = 0) => code => `\u{1B}[${code + offset}m`;
44

5-
const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`;
5+
const wrapAnsi256 = (offset = 0) => code => `\u{1B}[${38 + offset};5;${code}m`;
66

7-
const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
7+
const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u{1B}[${38 + offset};2;${red};${green};${blue}m`;
88

99
const styles = {
1010
modifier: {
@@ -76,8 +76,8 @@ function assembleStyles() {
7676
for (const [groupName, group] of Object.entries(styles)) {
7777
for (const [styleName, style] of Object.entries(group)) {
7878
styles[styleName] = {
79-
open: `\u001B[${style[0]}m`,
80-
close: `\u001B[${style[1]}m`,
79+
open: `\u{1B}[${style[0]}m`,
80+
close: `\u{1B}[${style[1]}m`,
8181
};
8282

8383
group[styleName] = styles[styleName];
@@ -96,8 +96,8 @@ function assembleStyles() {
9696
enumerable: false,
9797
});
9898

99-
styles.color.close = '\u001B[39m';
100-
styles.bgColor.close = '\u001B[49m';
99+
styles.color.close = '\u{1B}[39m';
100+
styles.bgColor.close = '\u{1B}[49m';
101101

102102
styles.color.ansi = wrapAnsi16();
103103
styles.color.ansi256 = wrapAnsi256();

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL