normalize
normalize(
colorConfig?
):undefined
|Partial
<ColorConfig
>
Convert a user-supplied color configuration into a set of ready-to-use colorizer functions, so the printer can apply colors without having to re-check types or re-parse strings every time.
- If you pass strings like
"red bold"
, they’re parsed once into functions. - If you pass functions directly, they’re used as-is.
- Keys without a value are skipped.
Parameters
Section titled “Parameters”colorConfig?
Section titled “colorConfig?”Partial
<ColorConfig
>
An object whose values are either style strings (e.g. "cyan underline"
)
or existing Colorizer functions.
Returns
Section titled “Returns”undefined
| Partial
<ColorConfig
>
A new object where each key maps to a Colorizer function, or undefined
if no config was provided.
Example
Section titled “Example”// User gives style strings and a functionconst userSpec = { error: 'red bold', info: 'green',};
// normalize() turns both into functions:const norm = normalize(userSpec);console.log(typeof norm.error); // "function"console.log(typeof norm.info); // "function"
// Printer can now do:console.log(norm.error('Oops!')); // bold red text