supports-color 1.2.0 → 2.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 (5) hide show
  1. package/index.js +18 -7
  2. package/license +21 -0
  3. package/package.json +9 -11
  4. package/readme.md +6 -14
  5. package/cli.js +0 -29
package/index.js CHANGED
@@ -1,17 +1,28 @@
1
1
  'use strict';
2
2
  var argv = process.argv;
3
3
 
4
+ var terminator = argv.indexOf('--');
5
+ var hasFlag = function (flag) {
6
+ flag = '--' + flag;
7
+ var pos = argv.indexOf(flag);
8
+ return pos !== -1 && (terminator !== -1 ? pos < terminator : true);
9
+ };
10
+
4
11
  module.exports = (function () {
5
- if (argv.indexOf('--no-color') !== -1 ||
6
- argv.indexOf('--no-colors') !== -1 ||
7
- argv.indexOf('--color=false') !== -1) {
12
+ if ('FORCE_COLOR' in process.env) {
13
+ return true;
14
+ }
15
+
16
+ if (hasFlag('no-color') ||
17
+ hasFlag('no-colors') ||
18
+ hasFlag('color=false')) {
8
19
  return false;
9
20
  }
10
21
 
11
- if (argv.indexOf('--color') !== -1 ||
12
- argv.indexOf('--colors') !== -1 ||
13
- argv.indexOf('--color=true') !== -1 ||
14
- argv.indexOf('--color=always') !== -1) {
22
+ if (hasFlag('color') ||
23
+ hasFlag('colors') ||
24
+ hasFlag('color=true') ||
25
+ hasFlag('color=always')) {
15
26
  return true;
16
27
  }
17
28
 
package/license ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
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:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
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.
package/package.json CHANGED
@@ -1,30 +1,28 @@
1
1
  {
2
2
  "name": "supports-color",
3
- "version": "1.2.0",
3
+ "version": "2.0.0",
4
4
  "description": "Detect whether a terminal supports color",
5
5
  "license": "MIT",
6
- "repository": "sindresorhus/supports-color",
6
+ "repository": "chalk/supports-color",
7
7
  "author": {
8
8
  "name": "Sindre Sorhus",
9
9
  "email": "sindresorhus@gmail.com",
10
- "url": "http://sindresorhus.com"
11
- },
12
- "bin": {
13
- "supports-color": "cli.js"
10
+ "url": "sindresorhus.com"
14
11
  },
12
+ "maintainers": [
13
+ "Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)",
14
+ "Joshua Appelman <jappelman@xebia.com> (jbnicolai.com)"
15
+ ],
15
16
  "engines": {
16
- "node": ">=0.10.0"
17
+ "node": ">=0.8.0"
17
18
  },
18
19
  "scripts": {
19
20
  "test": "mocha"
20
21
  },
21
22
  "files": [
22
- "index.js",
23
- "cli.js"
23
+ "index.js"
24
24
  ],
25
25
  "keywords": [
26
- "cli",
27
- "bin",
28
26
  "color",
29
27
  "colour",
30
28
  "colors",
package/readme.md CHANGED
@@ -1,11 +1,11 @@
1
- # supports-color [![Build Status](https://travis-ci.org/sindresorhus/supports-color.svg?branch=master)](https://travis-ci.org/sindresorhus/supports-color)
1
+ # supports-color [![Build Status](https://travis-ci.org/chalk/supports-color.svg?branch=master)](https://travis-ci.org/chalk/supports-color)
2
2
 
3
3
  > Detect whether a terminal supports color
4
4
 
5
5
 
6
6
  ## Install
7
7
 
8
- ```sh
8
+ ```
9
9
  $ npm install --save supports-color
10
10
  ```
11
11
 
@@ -22,21 +22,13 @@ if (supportsColor) {
22
22
 
23
23
  It obeys the `--color` and `--no-color` CLI flags.
24
24
 
25
+ For situations where using `--color` is not possible, add an environment variable `FORCE_COLOR` with any value to force color. Trumps `--no-color`.
25
26
 
26
- ## CLI
27
-
28
- ```sh
29
- $ npm install --global supports-color
30
- ```
31
-
32
- ```
33
- $ supports-color --help
34
27
 
35
- Usage
36
- supports-color
28
+ ## Related
37
29
 
38
- Exits with code 0 if color is supported and 1 if not
39
- ```
30
+ - [supports-color-cli](https://github.com/chalk/supports-color-cli) - CLI for this module
31
+ - [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
40
32
 
41
33
 
42
34
  ## License
package/cli.js DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
- var pkg = require('./package.json');
4
- var supportsColor = require('./');
5
- var argv = process.argv.slice(2);
6
-
7
- function help() {
8
- console.log([
9
- '',
10
- ' ' + pkg.description,
11
- '',
12
- ' Usage',
13
- ' supports-color',
14
- '',
15
- ' Exits with code 0 if color is supported and 1 if not'
16
- ].join('\n'));
17
- }
18
-
19
- if (argv.indexOf('--help') !== -1) {
20
- help();
21
- return;
22
- }
23
-
24
- if (argv.indexOf('--version') !== -1) {
25
- console.log(pkg.version);
26
- return;
27
- }
28
-
29
- process.exit(supportsColor ? 0 : 1);