@buzuli/color
Advanced tools
Comparing version 2.3.2 to 2.4.0
@@ -26,2 +26,29 @@ const chalk = require('chalk') | ||
function isTruthyString (text) { | ||
if (!text) | ||
return false | ||
const truthyStrings = [ | ||
'1', | ||
'enabled', | ||
'on', | ||
't', | ||
'true', | ||
'y', | ||
'yes', | ||
] | ||
return truthyStrings.includes(text.toLowerCase()) | ||
} | ||
function coerceNumber (text) { | ||
if (text == null) | ||
return undefined | ||
if (isNaN(text)) | ||
return undefined | ||
return Number(text) | ||
} | ||
function getColorLevel () { | ||
@@ -32,4 +59,9 @@ return context.level | ||
function initColor (ignoreTTY=false) { | ||
const desiredColorLevel = process.env.BUZULI_COLOR_LEVEL | ||
const forceColorOff = !process.stdout.isTTY && !ignoreTTY | ||
const envIgnoreTTY = isTruthyString(process.env.BUZULI_COLOR_IGNORE_TTY) | ||
const desiredColorLevel = coerceNumber(process.env.BUZULI_COLOR_LEVEL) | ||
const stdoutIsNotTTY = !process.stdout.isTTY | ||
const shouldHonorTTY = !ignoreTTY && !envIgnoreTTY | ||
const forceColorOff = stdoutIsNotTTY && shouldHonorTTY | ||
const resolvedColorLevel = forceColorOff ? 0 : desiredColorLevel | ||
@@ -42,4 +74,4 @@ | ||
const light = process.env.BUZULI_COLOR_LIGHT | ||
const dark = process.env.BUZULI_COLOR_DARK | ||
const light = isTruthyString(process.env.BUZULI_COLOR_LIGHT) | ||
const dark = isTruthyString(process.env.BUZULI_COLOR_DARK) | ||
@@ -46,0 +78,0 @@ const codeRed = process.env.BUZULI_COLOR_RED || (light ? 'a10' : dark ? 'd43' : 'b21') |
{ | ||
"name": "@buzuli/color", | ||
"version": "2.3.2", | ||
"version": "2.4.0", | ||
"description": "Preferred colors for @buzuli's projects", | ||
@@ -5,0 +5,0 @@ "main": "lib/color.js", |
@@ -59,4 +59,4 @@ # color | ||
- `BUZULI_COLOR_LIGHT` : optimized for light backgrounds (enabled,on,true,1,yes all work) | ||
- `BUZULI_COLOR_DARK` : optimized for dark backgrounds (enabled,on,true,1,yes all work) | ||
- `BUZULI_COLOR_LIGHT` : optimized for light backgrounds (1,enabled,on,t,true,y,yes all work) | ||
- `BUZULI_COLOR_DARK` : optimized for dark backgrounds (1,enabled,on,t,true,y,yes all work) | ||
@@ -81,1 +81,5 @@ If both `_LIGHT` and `_DARK` are specified, `_LIGHT` wins 🔦. | ||
- 3 : 16 million (Truecolor) | ||
Normally no color will be applied if it is determined that stdout is not a TTY, even if `BUZULI_COLOR_LEVEL` is set. | ||
However, you can override this via `BUZULI_COLOR_IGNORE_TTY` (1,enabled,on,t,true,y,yes all work). | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12398
302
84
24