Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

supports-color

Package Overview
Dependencies
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

supports-color - npm Package Compare versions

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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc