Chalk to Node.js util styleText
R
richiemccoll
Migrate from Chalk to Node.js util styleText
chalk-to-util-styletext
This codemod aims to help you reduce external dependencies by transforming chalk method calls to use the native Node.js styling functionality. It will also handle automatic removal of the chalk package from the package.json.
Compatible Features:
- Basic colors (red, green, blue, yellow, etc.)
- Bright colors (redBright, greenBright, etc.)
- Background colors (bgRed, bgGreen, etc.)
- Text modifiers (bold, dim, italic, underline, strikethrough, etc.)
- Style chaining via array syntax
- Environment variable support (NO_COLOR, NODE_DISABLE_COLORS, FORCE_COLOR)
Non-Compatible Features:
- Custom RGB colors (chalk.rgb(), chalk.hex())
- 256-color palette (chalk.ansi256())
- Template literal syntax (chalk...``)
- Advanced modifiers with limited terminal support (overline, blink, etc.)
The source code for this codemod can be found in the chalk-to-util-styletext directory.
You can find this codemod in the Codemod Registry.
npx codemod @nodejs/chalk-to-util-styletext
Example:
import from 'chalk';
.(.red('Error message'));
.(.red.bold('Important error'));
const = .red;
.(('Error'));
const = .blue.bold;
.(('Info'));