ansiWrap()function
ansiWrap(input: string, ...wrappers: ImmutableArray<string>): void
| Param | Type | |
|---|---|---|
input | string | The string to wrap in ANSI codes. required |
wrappers | ImmutableArray<string> |
| Return | |
|---|---|
unknown | The wrapped string, or input unchanged when the NO_COLOR environment variable is set. |
Wrap a string in the ANSI color/style codes (at the start), and ANSI_RESET at the end.
- The
NO_COLORenvironment variable is read live on every call, so runtimes that populateprocess.envlate (e.g. Cloudflare Workers, where[vars]bindings are only reliably available within the request scope) are honoured rather than baking in whateverNO_COLORwas at module-load time.
Examples
ansiWrap("hello", ANSI_RED, ANSI_BOLD) // "\x1b[31m\x1b[1mhello\x1b[0m"