This recipe migrates from the external kleur package to Node.js built-in util.styleText API. It transforms kleur style calls and kleur/colors named style functions to the native Node.js styling functionality.
- import kleur from 'kleur'; + import { styleText } from 'node:util'; - console.log(kleur.red('Error')); + console.log(styleText('red', 'Error')); - console.log(kleur.bold().red('Failure')); + console.log(styleText(['bold', 'red'], 'Failure'));
- import { green, dim } from 'kleur/colors'; + import { styleText } from 'node:util'; - console.log(green('OK') + ' ' + dim(name)); + console.log(styleText('green', 'OK') + ' ' + styleText('dim', name));
- import { bgRed, white } from 'kleur/colors'; + import { styleText } from 'node:util'; - console.log(bgRed(white('FAIL'))); + console.log(styleText(['bgRed', 'white'], 'FAIL'));
- Removes the
kleurdependency from package.json automatically - Supports default, namespace, and CommonJS
kleurimports - Supports named imports and destructured requires from
kleur/colors - Leaves unsupported APIs such as
kleur.enabledand$fromkleur/colorsunchanged
- Manual migration is required for
kleur.enabled,$fromkleur/colors, and other APIs that are not direct style functions