From 4a4fe6464f821aed9261431921e5f8c94a43677d Mon Sep 17 00:00:00 2001 From: Eric Cornelissen Date: Sun, 8 Sep 2024 14:40:08 +0200 Subject: [PATCH] Respect the NO_COLOR environment variable Update the implementation of the coloring logic in this project to respect the NO_COLOR environment variable name to allow users to use the tool without colored output. This can be useful when, e.g., saving the result to a file. --- src/utils/color.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/color.ts b/src/utils/color.ts index efd40d3..6c3f9ed 100644 --- a/src/utils/color.ts +++ b/src/utils/color.ts @@ -49,6 +49,10 @@ const COLORS = { * @return {String} Message */ export function color(message: string, fgColor?: Color, bgColor?: Color): string { + if ('NO_COLOR' in process.env) { + return message; + } + return [ get(COLORS, `${fgColor}.fg`, ''), get(COLORS, `${bgColor}.bg`, ''),