diff --git a/.gitignore b/.gitignore index 8b16100..8dd563f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ package-lock.json node_modules -coverage \ No newline at end of file +coverage +/.idea/ diff --git a/index.js b/index.js index d3f7713..fcdfacf 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,21 @@ +const env = process.env; + +const isDisabled = "NO_COLOR" in env +const isForced = "FORCE_COLOR" in env +const isWindows = process.platform === "win32" + +const isCompatibleTerminal = + process.stdout != null && + process.stdout.isTTY && + env.TERM && + env.TERM !== "dumb" + +const isCI = + "CI" in env && + ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env) + let enabled = - !("NO_COLOR" in process.env) && - ("FORCE_COLOR" in process.env || - process.platform === "win32" || - (process.stdout != null && - process.stdout.isTTY && - process.env.TERM && - process.env.TERM !== "dumb")) + !isDisabled && (isForced || isWindows || isCompatibleTerminal || isCI) const raw = (open, close, searchRegex, replaceValue) => (s) => enabled