supports-color
Advanced tools
Comparing version 2.0.0 to 3.0.0
56
index.js
'use strict'; | ||
var argv = process.argv; | ||
var hasFlag = require('has-flag'); | ||
var terminator = argv.indexOf('--'); | ||
var hasFlag = function (flag) { | ||
flag = '--' + flag; | ||
var pos = argv.indexOf(flag); | ||
return pos !== -1 && (terminator !== -1 ? pos < terminator : true); | ||
var support = function (level) { | ||
if (level === 0) { | ||
return false; | ||
} | ||
return { | ||
level: level, | ||
hasBasic: true, | ||
has256: level >= 2, | ||
has16m: level >= 3 | ||
}; | ||
}; | ||
module.exports = (function () { | ||
if ('FORCE_COLOR' in process.env) { | ||
return true; | ||
var supportLevel = (function () { | ||
if (hasFlag('color=16m') || | ||
hasFlag('color=full') || | ||
hasFlag('color=truecolor')) { | ||
return 3; | ||
} | ||
if (hasFlag('no-color') || | ||
hasFlag('no-colors') || | ||
hasFlag('color=false')) { | ||
return false; | ||
if (hasFlag('color=256')) { | ||
return 2; | ||
} | ||
@@ -26,26 +32,36 @@ | ||
hasFlag('color=always')) { | ||
return true; | ||
return 1; | ||
} | ||
if (process.stdout && !process.stdout.isTTY) { | ||
return false; | ||
return 0; | ||
} | ||
if (process.platform === 'win32') { | ||
return true; | ||
return 1; | ||
} | ||
if ('COLORTERM' in process.env) { | ||
return true; | ||
return 1; | ||
} | ||
if (process.env.TERM === 'dumb') { | ||
return false; | ||
return 0; | ||
} | ||
if (/^xterm-256(?:color)?/.test(process.env.TERM)) { | ||
return 2; | ||
} | ||
if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)) { | ||
return true; | ||
return 1; | ||
} | ||
return false; | ||
return 0; | ||
})(); | ||
if (supportLevel === 0 && 'FORCE_COLOR' in process.env) { | ||
supportLevel = 1; | ||
} | ||
module.exports = support(supportLevel); |
{ | ||
"name": "supports-color", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Detect whether a terminal supports color", | ||
@@ -14,3 +14,4 @@ "license": "MIT", | ||
"Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)", | ||
"Joshua Appelman <jappelman@xebia.com> (jbnicolai.com)" | ||
"Joshua Appelman <jappelman@xebia.com> (jbnicolai.com)", | ||
"JD Ballard <i.am.qix@gmail.com> (github.com/qix-)" | ||
], | ||
@@ -46,2 +47,5 @@ "engines": { | ||
], | ||
"dependencies": { | ||
"has-flag": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
@@ -48,0 +52,0 @@ "mocha": "*", |
@@ -21,4 +21,26 @@ # supports-color [![Build Status](https://travis-ci.org/chalk/supports-color.svg?branch=master)](https://travis-ci.org/chalk/supports-color) | ||
} | ||
if (supportsColor.has256) { | ||
console.log('Terminal supports 256 colors'); | ||
} | ||
if (supportsColor.has16m) { | ||
console.log('Terminal supports 16 million colors (truecolor)'); | ||
} | ||
``` | ||
## API | ||
Returns 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: | ||
- `.level = 1` and `.hasBasic = true`: Basic color support (16 colors) | ||
- `.level = 2` and `.has256 = true`: 256 color support | ||
- `.level = 3` and `.has16m = true`: 16 million (truecolor) support | ||
## Info | ||
It obeys the `--color` and `--no-color` CLI flags. | ||
@@ -28,3 +50,5 @@ | ||
Explicit 256/truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively. | ||
## Related | ||
@@ -31,0 +55,0 @@ |
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 2 instances 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
4667
52
61
1
6
+ Addedhas-flag@^1.0.0
+ Addedhas-flag@1.0.0(transitive)