supports-color
Advanced tools
Comparing version 4.5.0 to 5.0.0
26
index.js
@@ -7,3 +7,3 @@ 'use strict'; | ||
const support = level => { | ||
function translateLevel(level) { | ||
if (level === 0) { | ||
@@ -19,5 +19,5 @@ return false; | ||
}; | ||
}; | ||
} | ||
let supportLevel = (() => { | ||
function supportsColor(stream) { | ||
if (hasFlag('no-color') || | ||
@@ -46,3 +46,3 @@ hasFlag('no-colors') || | ||
if (process.stdout && !process.stdout.isTTY) { | ||
if (stream && !stream.isTTY) { | ||
return 0; | ||
@@ -112,8 +112,18 @@ } | ||
return 0; | ||
})(); | ||
} | ||
if ('FORCE_COLOR' in env) { | ||
supportLevel = parseInt(env.FORCE_COLOR, 10) === 0 ? 0 : (supportLevel || 1); | ||
function getSupportLevel(stream) { | ||
let level = supportsColor(stream); | ||
if ('FORCE_COLOR' in env) { | ||
level = (env.FORCE_COLOR.length > 0 && parseInt(env.FORCE_COLOR, 10) === 0) ? 0 : (level || 1); | ||
} | ||
return translateLevel(level); | ||
} | ||
module.exports = process && support(supportLevel); | ||
module.exports = { | ||
supportsColor: getSupportLevel, | ||
stdout: getSupportLevel(process.stdout), | ||
stderr: getSupportLevel(process.stderr) | ||
}; |
{ | ||
"name": "supports-color", | ||
"version": "4.5.0", | ||
"version": "5.0.0", | ||
"description": "Detect whether a terminal supports color", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -18,12 +18,12 @@ # supports-color [![Build Status](https://travis-ci.org/chalk/supports-color.svg?branch=master)](https://travis-ci.org/chalk/supports-color) | ||
if (supportsColor) { | ||
console.log('Terminal supports color'); | ||
if (supportsColor.stdout) { | ||
console.log('Terminal stdout supports color'); | ||
} | ||
if (supportsColor.has256) { | ||
console.log('Terminal supports 256 colors'); | ||
if (supportsColor.stdout.has256) { | ||
console.log('Terminal stdout supports 256 colors'); | ||
} | ||
if (supportsColor.has16m) { | ||
console.log('Terminal supports 16 million colors (truecolor)'); | ||
if (supportsColor.stderr.has16m) { | ||
console.log('Terminal stderr supports 16 million colors (truecolor)'); | ||
} | ||
@@ -35,5 +35,5 @@ ``` | ||
Returns an `Object`, or `false` if color is not supported. | ||
Returns an `Object` with a `stdout` and `stderr` property for testing either streams. Each property is an `Object`, or `false` if color is not supported. | ||
The returned object specifies a level of support for color through a `.level` property and a corresponding flag: | ||
The `stdout`/`stderr` objects specifies a level of support for color through a `.level` property and a corresponding flag: | ||
@@ -40,0 +40,0 @@ - `.level = 1` and `.hasBasic = true`: Basic color support (16 colors) |
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
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
6408
103