chalk 0.5.1 → 1.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 +23 -18
  2. package/license +21 -0
  3. package/package.json +9 -9
  4. package/readme.md +45 -23
package/index.js CHANGED
@@ -5,13 +5,23 @@ var stripAnsi = require('strip-ansi');
5
5
  var hasAnsi = require('has-ansi');
6
6
  var supportsColor = require('supports-color');
7
7
  var defineProps = Object.defineProperties;
8
- var chalk = module.exports;
8
+
9
+ function Chalk(options) {
10
+ // detect mode if not set manually
11
+ this.enabled = !options || options.enabled === undefined ? supportsColor : options.enabled;
12
+ }
13
+
14
+ // use bright blue on Windows as the normal blue color is illegible
15
+ if (process.platform === 'win32') {
16
+ ansiStyles.blue.open = '\u001b[94m';
17
+ }
9
18
 
10
19
  function build(_styles) {
11
20
  var builder = function builder() {
12
21
  return applyStyle.apply(builder, arguments);
13
22
  };
14
23
  builder._styles = _styles;
24
+ builder.enabled = this.enabled;
15
25
  // __proto__ is used because we must return a function, but there is
16
26
  // no way to create a function with a different prototype.
17
27
  builder.__proto__ = proto;
@@ -21,14 +31,12 @@ function build(_styles) {
21
31
  var styles = (function () {
22
32
  var ret = {};
23
33
 
24
- ansiStyles.grey = ansiStyles.gray;
25
-
26
34
  Object.keys(ansiStyles).forEach(function (key) {
27
35
  ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
28
36
 
29
37
  ret[key] = {
30
38
  get: function () {
31
- return build(this._styles.concat(key));
39
+ return build.call(this, this._styles.concat(key));
32
40
  }
33
41
  };
34
42
  });
@@ -50,14 +58,15 @@ function applyStyle() {
50
58
  }
51
59
  }
52
60
 
53
- if (!chalk.enabled || !str) {
61
+ if (!this.enabled || !str) {
54
62
  return str;
55
63
  }
56
64
 
57
- /*jshint validthis: true*/
65
+ /*jshint validthis: true */
58
66
  var nestedStyles = this._styles;
59
67
 
60
- for (var i = 0; i < nestedStyles.length; i++) {
68
+ var i = nestedStyles.length;
69
+ while (i--) {
61
70
  var code = ansiStyles[nestedStyles[i]];
62
71
  // Replace any instances already present with a re-opening code
63
72
  // otherwise only the part of the string until said closing code
@@ -74,7 +83,7 @@ function init() {
74
83
  Object.keys(styles).forEach(function (name) {
75
84
  ret[name] = {
76
85
  get: function () {
77
- return build([name]);
86
+ return build.call(this, [name]);
78
87
  }
79
88
  };
80
89
  });
@@ -82,14 +91,10 @@ function init() {
82
91
  return ret;
83
92
  }
84
93
 
85
- defineProps(chalk, init());
86
-
87
- chalk.styles = ansiStyles;
88
- chalk.hasColor = hasAnsi;
89
- chalk.stripColor = stripAnsi;
90
- chalk.supportsColor = supportsColor;
94
+ defineProps(Chalk.prototype, init());
91
95
 
92
- // detect mode if not set manually
93
- if (chalk.enabled === undefined) {
94
- chalk.enabled = chalk.supportsColor;
95
- }
96
+ module.exports = new Chalk();
97
+ module.exports.styles = ansiStyles;
98
+ module.exports.hasColor = hasAnsi;
99
+ module.exports.stripColor = stripAnsi;
100
+ module.exports.supportsColor = supportsColor;
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,12 +1,12 @@
1
1
  {
2
2
  "name": "chalk",
3
- "version": "0.5.1",
4
- "description": "Terminal string styling done right. Created because the `colors` module does some really horrible things.",
3
+ "version": "1.0.0",
4
+ "description": "Terminal string styling done right. Much color.",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/chalk",
7
7
  "maintainers": [
8
8
  "Sindre Sorhus <sindresorhus@gmail.com> (http://sindresorhus.com)",
9
- "Joshua Appelman <joshua@jbna.nl>"
9
+ "Joshua Appelman <jappelman@xebia.com> (http://jbnicolai.com)"
10
10
  ],
11
11
  "engines": {
12
12
  "node": ">=0.10.0"
@@ -40,14 +40,14 @@
40
40
  "text"
41
41
  ],
42
42
  "dependencies": {
43
- "ansi-styles": "^1.1.0",
44
- "escape-string-regexp": "^1.0.0",
45
- "has-ansi": "^0.1.0",
46
- "strip-ansi": "^0.3.0",
47
- "supports-color": "^0.2.0"
43
+ "ansi-styles": "^2.0.1",
44
+ "escape-string-regexp": "^1.0.2",
45
+ "has-ansi": "^1.0.3",
46
+ "strip-ansi": "^2.0.1",
47
+ "supports-color": "^1.3.0"
48
48
  },
49
49
  "devDependencies": {
50
- "matcha": "^0.5.0",
50
+ "matcha": "^0.6.0",
51
51
  "mocha": "*"
52
52
  }
53
53
  }
package/readme.md CHANGED
@@ -1,11 +1,15 @@
1
- # <img width="300" src="https://cdn.rawgit.com/sindresorhus/chalk/77ae94f63ab1ac61389b190e5a59866569d1a376/logo.svg" alt="chalk">
1
+ <h1 align="center">
2
+ <br>
3
+ <img width="360" src="https://cdn.rawgit.com/sindresorhus/chalk/19935d6484811c5e468817f846b7b3d417d7bf4a/logo.svg" alt="chalk">
4
+ <br>
5
+ <br>
6
+ </h1>
2
7
 
3
8
  > Terminal string styling done right
4
9
 
5
- [![Build Status](https://travis-ci.org/sindresorhus/chalk.svg?branch=master)](https://travis-ci.org/sindresorhus/chalk)
6
- ![](http://img.shields.io/badge/unicorn-approved-ff69b4.svg)
10
+ [![Build Status](https://travis-ci.org/sindresorhus/chalk.svg?branch=master)](https://travis-ci.org/sindresorhus/chalk) [![](http://img.shields.io/badge/unicorn-approved-ff69b4.svg?style=flat)](https://www.youtube.com/watch?v=Sm368W0OsHo)
7
11
 
8
- [colors.js](https://github.com/Marak/colors.js) is currently the most popular string styling module, but it has serious deficiencies like extending String.prototype which causes all kinds of [problems](https://github.com/yeoman/yo/issues/68). Although there are other ones, they either do too much or not enough.
12
+ [colors.js](https://github.com/Marak/colors.js) used to be the most popular string styling module, but it has serious deficiencies like extending `String.prototype` which causes all kinds of [problems](https://github.com/yeoman/yo/issues/68). Although there are other ones, they either do too much or not enough.
9
13
 
10
14
  **Chalk is a clean and focused alternative.**
11
15
 
@@ -15,18 +19,18 @@
15
19
  ## Why
16
20
 
17
21
  - Highly performant
18
- - Doesn't extend String.prototype
22
+ - Doesn't extend `String.prototype`
19
23
  - Expressive API
20
24
  - Ability to nest styles
21
25
  - Clean and focused
22
26
  - Auto-detects color support
23
27
  - Actively maintained
24
- - [Used by 1000+ modules](https://npmjs.org/browse/depended/chalk)
28
+ - [Used by ~3000 modules](https://www.npmjs.com/browse/depended/chalk)
25
29
 
26
30
 
27
31
  ## Install
28
32
 
29
- ```sh
33
+ ```
30
34
  $ npm install --save chalk
31
35
  ```
32
36
 
@@ -39,22 +43,26 @@ Chalk comes with an easy to use composable API where you just chain and nest the
39
43
  var chalk = require('chalk');
40
44
 
41
45
  // style a string
42
- console.log( chalk.blue('Hello world!') );
46
+ chalk.blue('Hello world!');
43
47
 
44
48
  // combine styled and normal strings
45
- console.log( chalk.blue('Hello'), 'World' + chalk.red('!') );
49
+ chalk.blue('Hello') + 'World' + chalk.red('!');
46
50
 
47
51
  // compose multiple styles using the chainable API
48
- console.log( chalk.blue.bgRed.bold('Hello world!') );
52
+ chalk.blue.bgRed.bold('Hello world!');
49
53
 
50
54
  // pass in multiple arguments
51
- console.log( chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz') );
55
+ chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz');
52
56
 
53
57
  // nest styles
54
- console.log( chalk.red('Hello', chalk.underline.bgBlue('world') + '!') );
58
+ chalk.red('Hello', chalk.underline.bgBlue('world') + '!');
55
59
 
56
60
  // nest styles of the same type even (color, underline, background)
57
- console.log( chalk.green('I am a green line ' + chalk.blue('with a blue substring') + ' that becomes green again!') );
61
+ chalk.green(
62
+ 'I am a green line ' +
63
+ chalk.blue.underline.bold('with a blue substring') +
64
+ ' that becomes green again!'
65
+ );
58
66
  ```
59
67
 
60
68
  Easily define your own themes.
@@ -80,27 +88,31 @@ console.log(chalk.green('Hello %s'), name);
80
88
 
81
89
  Example: `chalk.red.bold.underline('Hello', 'world');`
82
90
 
83
- Chain [styles](#styles) and call the last one as a method with a string argument. Order doesn't matter.
91
+ Chain [styles](#styles) and call the last one as a method with a string argument. Order doesn't matter, and later styles take precedent in case of a conflict. This simply means that `Chalk.red.yellow.green` is equivalent to `Chalk.green`.
84
92
 
85
93
  Multiple arguments will be separated by space.
86
94
 
87
95
  ### chalk.enabled
88
96
 
89
- Color support is automatically detected, but you can override it.
97
+ Color support is automatically detected, but you can override it by setting the `enabled` property. You should however only do this in your own code as it applies globally to all chalk consumers.
90
98
 
91
- ### chalk.supportsColor
99
+ If you need to change this in a reusable module create a new instance:
100
+
101
+ ```js
102
+ var ctx = new chalk.constructor({enabled: false});
103
+ ```
92
104
 
93
- Detect whether the terminal [supports color](https://github.com/sindresorhus/supports-color).
105
+ ### chalk.supportsColor
94
106
 
95
- Can be overridden by the user with the flags `--color` and `--no-color`.
107
+ Detect whether the terminal [supports color](https://github.com/sindresorhus/supports-color). Used internally and handled for you, but exposed for convenience.
96
108
 
97
- Used internally and handled for you, but exposed for convenience.
109
+ Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, add an environment variable `FORCE_COLOR` with any value to force color. Trumps `--no-color`.
98
110
 
99
111
  ### chalk.styles
100
112
 
101
113
  Exposes the styles as [ANSI escape codes](https://github.com/sindresorhus/ansi-styles).
102
114
 
103
- Generally not useful, but you might need just the `.open` or `.close` escape code if you're mixing externally styled strings with yours.
115
+ Generally not useful, but you might need just the `.open` or `.close` escape code if you're mixing externally styled strings with your own.
104
116
 
105
117
  ```js
106
118
  var chalk = require('chalk');
@@ -135,7 +147,7 @@ if (!chalk.supportsColor) {
135
147
 
136
148
  ## Styles
137
149
 
138
- ### General
150
+ ### Modifiers
139
151
 
140
152
  - `reset`
141
153
  - `bold`
@@ -146,13 +158,13 @@ if (!chalk.supportsColor) {
146
158
  - `hidden`
147
159
  - `strikethrough` *(not widely supported)*
148
160
 
149
- ### Text colors
161
+ ### Colors
150
162
 
151
163
  - `black`
152
164
  - `red`
153
165
  - `green`
154
166
  - `yellow`
155
- - `blue`
167
+ - `blue` *(on Windows the bright version is used as normal blue is illegible)*
156
168
  - `magenta`
157
169
  - `cyan`
158
170
  - `white`
@@ -170,6 +182,16 @@ if (!chalk.supportsColor) {
170
182
  - `bgWhite`
171
183
 
172
184
 
185
+ ## 256-colors
186
+
187
+ Chalk does not support support anything other than the base eight colors, which guarantees it will work on all terminals and systems. Some terminals, specifically `xterm` compliant ones, will support the full range of 8-bit colors. For this the lower level [ansi-256-colors](https://github.com/jbnicolai/ansi-256-colors) package can be used.
188
+
189
+
190
+ ## Windows
191
+
192
+ If you're on Windows, do yourself a favor and use [`cmder`](http://bliker.github.io/cmder/) instead of `cmd.exe`.
193
+
194
+
173
195
  ## License
174
196
 
175
197
  MIT © [Sindre Sorhus](http://sindresorhus.com)