supports-color 3.2.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/index.js +35 -11
  2. package/license +4 -16
  3. package/package.json +8 -21
  4. package/readme.md +11 -5
package/index.js CHANGED
@@ -1,20 +1,22 @@
1
1
  'use strict';
2
- var hasFlag = require('has-flag');
2
+ const hasFlag = require('has-flag');
3
3
 
4
- var support = function (level) {
4
+ const env = process.env;
5
+
6
+ const support = level => {
5
7
  if (level === 0) {
6
8
  return false;
7
9
  }
8
10
 
9
11
  return {
10
- level: level,
12
+ level,
11
13
  hasBasic: true,
12
14
  has256: level >= 2,
13
15
  has16m: level >= 3
14
16
  };
15
17
  };
16
18
 
17
- var supportLevel = (function () {
19
+ let supportLevel = (() => {
18
20
  if (hasFlag('no-color') ||
19
21
  hasFlag('no-colors') ||
20
22
  hasFlag('color=false')) {
@@ -46,31 +48,53 @@ var supportLevel = (function () {
46
48
  return 1;
47
49
  }
48
50
 
49
- if ('CI' in process.env || 'TEAMCITY_VERSION' in process.env) {
51
+ if ('CI' in env) {
52
+ if ('TRAVIS' in env || env.CI === 'Travis') {
53
+ return 1;
54
+ }
55
+
50
56
  return 0;
51
57
  }
52
58
 
53
- if (/^xterm-256(?:color)?/.test(process.env.TERM)) {
59
+ if ('TEAMCITY_VERSION' in env) {
60
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
61
+ }
62
+
63
+ if ('TERM_PROGRAM' in env) {
64
+ const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
65
+
66
+ switch (env.TERM_PROGRAM) {
67
+ case 'iTerm.app':
68
+ return version >= 3 ? 3 : 2;
69
+ case 'Hyper':
70
+ return 3;
71
+ case 'Apple_Terminal':
72
+ return 2;
73
+ // No default
74
+ }
75
+ }
76
+
77
+ if (/^(screen|xterm)-256(?:color)?/.test(env.TERM)) {
54
78
  return 2;
55
79
  }
56
80
 
57
- if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)) {
81
+ if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(env.TERM)) {
58
82
  return 1;
59
83
  }
60
84
 
61
- if ('COLORTERM' in process.env) {
85
+ if ('COLORTERM' in env) {
62
86
  return 1;
63
87
  }
64
88
 
65
- if (process.env.TERM === 'dumb') {
89
+ if (env.TERM === 'dumb') {
66
90
  return 0;
67
91
  }
68
92
 
69
93
  return 0;
70
94
  })();
71
95
 
72
- if (supportLevel === 0 && 'FORCE_COLOR' in process.env) {
73
- supportLevel = 1;
96
+ if ('FORCE_COLOR' in env) {
97
+ supportLevel = parseInt(env.FORCE_COLOR, 10) === 0 ? 0 : (supportLevel || 1);
74
98
  }
75
99
 
76
100
  module.exports = process && support(supportLevel);
package/license CHANGED
@@ -1,21 +1,9 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
3
  Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
6
 
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14
8
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supports-color",
3
- "version": "3.2.0",
3
+ "version": "4.0.0",
4
4
  "description": "Detect whether a terminal supports color",
5
5
  "license": "MIT",
6
6
  "repository": "chalk/supports-color",
@@ -9,18 +9,11 @@
9
9
  "email": "sindresorhus@gmail.com",
10
10
  "url": "sindresorhus.com"
11
11
  },
12
- "maintainers": [
13
- "Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)",
14
- "Joshua Boy Nicolai Appelman <joshua@jbna.nl> (jbna.nl)",
15
- "JD Ballard <i.am.qix@gmail.com> (github.com/qix-)"
16
- ],
17
- "browser": "browser.js",
18
12
  "engines": {
19
- "node": ">=0.8.0"
13
+ "node": ">=4"
20
14
  },
21
15
  "scripts": {
22
- "test": "xo && mocha",
23
- "travis": "mocha"
16
+ "test": "xo && ava"
24
17
  },
25
18
  "files": [
26
19
  "index.js",
@@ -46,21 +39,15 @@
46
39
  "capability",
47
40
  "detect",
48
41
  "truecolor",
49
- "16m",
50
- "million"
42
+ "16m"
51
43
  ],
52
44
  "dependencies": {
53
- "has-flag": "^1.0.0"
45
+ "has-flag": "^2.0.0"
54
46
  },
55
47
  "devDependencies": {
56
- "mocha": "*",
57
- "require-uncached": "^1.0.2",
48
+ "ava": "*",
49
+ "import-fresh": "^2.0.0",
58
50
  "xo": "*"
59
51
  },
60
- "xo": {
61
- "envs": [
62
- "node",
63
- "mocha"
64
- ]
65
- }
52
+ "browser": "browser.js"
66
53
  }
package/readme.md CHANGED
@@ -6,14 +6,14 @@
6
6
  ## Install
7
7
 
8
8
  ```
9
- $ npm install --save supports-color
9
+ $ npm install supports-color
10
10
  ```
11
11
 
12
12
 
13
13
  ## Usage
14
14
 
15
15
  ```js
16
- var supportsColor = require('supports-color');
16
+ const supportsColor = require('supports-color');
17
17
 
18
18
  if (supportsColor) {
19
19
  console.log('Terminal supports color');
@@ -31,7 +31,7 @@ if (supportsColor.has16m) {
31
31
 
32
32
  ## API
33
33
 
34
- Returns an `object`, or `false` if color is not supported.
34
+ Returns an `Object`, or `false` if color is not supported.
35
35
 
36
36
  The returned object specifies a level of support for color through a `.level` property and a corresponding flag:
37
37
 
@@ -44,7 +44,7 @@ The returned object specifies a level of support for color through a `.level` pr
44
44
 
45
45
  It obeys the `--color` and `--no-color` CLI flags.
46
46
 
47
- For situations where using `--color` is not possible, add an environment variable `FORCE_COLOR` with any value to force color. Trumps `--no-color`.
47
+ For situations where using `--color` is not possible, add an environment variable `FORCE_COLOR=1` to forcefully enable color and `FORCE_COLOR=0` forcefully disable. The use of `FORCE_COLOR` overrides all other color checks performed by this module.
48
48
 
49
49
  Explicit 256/truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
50
50
 
@@ -55,6 +55,12 @@ Explicit 256/truecolor mode can be enabled using the `--color=256` and `--color=
55
55
  - [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
56
56
 
57
57
 
58
+ ## Maintainers
59
+
60
+ - [Sindre Sorhus](https://github.com/sindresorhus)
61
+ - [Josh Junon](https://github.com/qix-)
62
+
63
+
58
64
  ## License
59
65
 
60
- MIT © [Sindre Sorhus](http://sindresorhus.com)
66
+ MIT