supports-color
Advanced tools
Comparing version 9.0.2 to 9.1.0
@@ -9,3 +9,3 @@ /* eslint-env browser */ | ||
has256: false, | ||
has16m: false | ||
has16m: false, | ||
} : false; | ||
@@ -15,5 +15,5 @@ | ||
stdout: colorSupport, | ||
stderr: colorSupport | ||
stderr: colorSupport, | ||
}; | ||
export default supportsColor; |
53
index.js
@@ -1,18 +0,29 @@ | ||
import process from 'process'; // eslint-disable-line node/prefer-global/process | ||
import os from 'os'; | ||
import tty from 'tty'; | ||
import hasFlag from 'has-flag'; | ||
import process from 'node:process'; | ||
import os from 'node:os'; | ||
import tty from 'node:tty'; | ||
// From: https://github.com/sindresorhus/has-flag/blob/main/index.js | ||
function hasFlag(flag, argv = process.argv) { | ||
const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--'); | ||
const position = argv.indexOf(prefix + flag); | ||
const terminatorPosition = argv.indexOf('--'); | ||
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition); | ||
} | ||
const {env} = process; | ||
let flagForceColor; | ||
if (hasFlag('no-color') || | ||
hasFlag('no-colors') || | ||
hasFlag('color=false') || | ||
hasFlag('color=never')) { | ||
if ( | ||
hasFlag('no-color') | ||
|| hasFlag('no-colors') | ||
|| hasFlag('color=false') | ||
|| hasFlag('color=never') | ||
) { | ||
flagForceColor = 0; | ||
} else if (hasFlag('color') || | ||
hasFlag('colors') || | ||
hasFlag('color=true') || | ||
hasFlag('color=always')) { | ||
} else if ( | ||
hasFlag('color') | ||
|| hasFlag('colors') | ||
|| hasFlag('color=true') | ||
|| hasFlag('color=always') | ||
) { | ||
flagForceColor = 1; | ||
@@ -44,3 +55,3 @@ } | ||
has256: level >= 2, | ||
has16m: level >= 3 | ||
has16m: level >= 3, | ||
}; | ||
@@ -62,5 +73,5 @@ } | ||
if (sniffFlags) { | ||
if (hasFlag('color=16m') || | ||
hasFlag('color=full') || | ||
hasFlag('color=truecolor')) { | ||
if (hasFlag('color=16m') | ||
|| hasFlag('color=full') | ||
|| hasFlag('color=truecolor')) { | ||
return 3; | ||
@@ -89,6 +100,6 @@ } | ||
if ( | ||
Number(osRelease[0]) >= 10 && | ||
Number(osRelease[2]) >= 10586 | ||
Number(osRelease[0]) >= 10 | ||
&& Number(osRelease[2]) >= 10_586 | ||
) { | ||
return Number(osRelease[2]) >= 14931 ? 3 : 2; | ||
return Number(osRelease[2]) >= 14_931 ? 3 : 2; | ||
} | ||
@@ -145,3 +156,3 @@ | ||
streamIsTTY: stream && stream.isTTY, | ||
...options | ||
...options, | ||
}); | ||
@@ -154,5 +165,5 @@ | ||
stdout: createSupportsColor({isTTY: tty.isatty(1)}), | ||
stderr: createSupportsColor({isTTY: tty.isatty(2)}) | ||
stderr: createSupportsColor({isTTY: tty.isatty(2)}), | ||
}; | ||
export default supportsColor; |
{ | ||
"name": "supports-color", | ||
"version": "9.0.2", | ||
"version": "9.1.0", | ||
"description": "Detect whether a terminal supports color", | ||
@@ -22,7 +22,8 @@ "license": "MIT", | ||
"scripts": { | ||
"//test": "xo && ava", | ||
"test": "xo" | ||
"//test": "xo && ava && tsd", | ||
"test": "xo && tsd" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"browser.js" | ||
@@ -52,10 +53,10 @@ ], | ||
], | ||
"dependencies": { | ||
"has-flag": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^16.11.7", | ||
"ava": "^3.15.0", | ||
"import-fresh": "^3.3.0", | ||
"xo": "^0.38.2" | ||
"tsd": "^0.18.0", | ||
"typescript": "^4.4.3", | ||
"xo": "^0.44.0" | ||
} | ||
} |
10151
0
6
189
6
- Removedhas-flag@^5.0.0
- Removedhas-flag@5.0.1(transitive)