chalk 1.1.2 → 1.1.3

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 (3) hide show
  1. package/index.js +32 -15
  2. package/package.json +8 -6
  3. package/readme.md +34 -26
package/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
  var escapeStringRegexp = require('escape-string-regexp');
3
3
  var ansiStyles = require('ansi-styles');
4
+ var stripAnsi = require('strip-ansi');
5
+ var hasAnsi = require('has-ansi');
4
6
  var supportsColor = require('supports-color');
5
7
  var defineProps = Object.defineProperties;
6
8
  var isSimpleWindowsTerm = process.platform === 'win32' && !/^xterm/i.test(process.env.TERM);
@@ -15,17 +17,21 @@ if (isSimpleWindowsTerm) {
15
17
  ansiStyles.blue.open = '\u001b[94m';
16
18
  }
17
19
 
18
- var styles = {};
20
+ var styles = (function () {
21
+ var ret = {};
19
22
 
20
- Object.keys(ansiStyles).forEach(function (key) {
21
- ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
23
+ Object.keys(ansiStyles).forEach(function (key) {
24
+ ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
22
25
 
23
- styles[key] = {
24
- get: function () {
25
- return build.call(this, this._styles ? this._styles.concat(key) : [key]);
26
- }
27
- };
28
- });
26
+ ret[key] = {
27
+ get: function () {
28
+ return build.call(this, this._styles.concat(key));
29
+ }
30
+ };
31
+ });
32
+
33
+ return ret;
34
+ })();
29
35
 
30
36
  var proto = defineProps(function chalk() {}, styles);
31
37
 
@@ -79,11 +85,6 @@ function applyStyle() {
79
85
  // otherwise only the part of the string until said closing code
80
86
  // will be colored, and the rest will simply be 'plain'.
81
87
  str = code.open + str.replace(code.closeRe, code.open) + code.close;
82
-
83
- // Close the styling before a linebreak and reopen
84
- // after next line to fix a bleed issue on OS X
85
- // https://github.com/chalk/chalk/pull/92
86
- str = str.replace(/\r?\n/g, code.close + '$&' + code.open);
87
88
  }
88
89
 
89
90
  // Reset the original 'dim' if we changed it to work around the Windows dimmed gray issue.
@@ -92,8 +93,24 @@ function applyStyle() {
92
93
  return str;
93
94
  }
94
95
 
95
- defineProps(Chalk.prototype, styles);
96
+ function init() {
97
+ var ret = {};
98
+
99
+ Object.keys(styles).forEach(function (name) {
100
+ ret[name] = {
101
+ get: function () {
102
+ return build.call(this, [name]);
103
+ }
104
+ };
105
+ });
106
+
107
+ return ret;
108
+ }
109
+
110
+ defineProps(Chalk.prototype, init());
96
111
 
97
112
  module.exports = new Chalk();
98
113
  module.exports.styles = ansiStyles;
114
+ module.exports.hasColor = hasAnsi;
115
+ module.exports.stripColor = stripAnsi;
99
116
  module.exports.supportsColor = supportsColor;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "chalk",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Terminal string styling done right. Much color.",
5
5
  "license": "MIT",
6
6
  "repository": "chalk/chalk",
7
7
  "maintainers": [
8
8
  "Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)",
9
- "Joshua Boy Nicolai Appelman <joshua@jbna.nl> (jbna.nl)",
9
+ "Joshua Appelman <jappelman@xebia.com> (jbnicolai.com)",
10
10
  "JD Ballard <i.am.qix@gmail.com> (github.com/qix-)"
11
11
  ],
12
12
  "engines": {
@@ -47,16 +47,18 @@
47
47
  "dependencies": {
48
48
  "ansi-styles": "^2.2.1",
49
49
  "escape-string-regexp": "^1.0.2",
50
- "supports-color": "^3.1.2"
50
+ "has-ansi": "^2.0.0",
51
+ "strip-ansi": "^3.0.0",
52
+ "supports-color": "^2.0.0"
51
53
  },
52
54
  "devDependencies": {
53
55
  "coveralls": "^2.11.2",
54
56
  "matcha": "^0.6.0",
55
57
  "mocha": "*",
56
- "nyc": "^5.2.0",
58
+ "nyc": "^3.0.0",
57
59
  "require-uncached": "^1.0.2",
58
- "resolve-from": "^2.0.0",
59
- "semver": "^5.1.0",
60
+ "resolve-from": "^1.0.0",
61
+ "semver": "^4.3.3",
60
62
  "xo": "*"
61
63
  },
62
64
  "xo": {
package/readme.md CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  [![Build Status](https://travis-ci.org/chalk/chalk.svg?branch=master)](https://travis-ci.org/chalk/chalk)
13
13
  [![Coverage Status](https://coveralls.io/repos/chalk/chalk/badge.svg?branch=master)](https://coveralls.io/r/chalk/chalk?branch=master)
14
- [![](https://img.shields.io/badge/unicorn-approved-ff69b4.svg)](https://www.youtube.com/watch?v=9auOCbH5Ns4)
14
+ [![](http://img.shields.io/badge/unicorn-approved-ff69b4.svg)](https://www.youtube.com/watch?v=9auOCbH5Ns4)
15
15
 
16
16
 
17
17
  [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.
@@ -30,7 +30,7 @@
30
30
  - Clean and focused
31
31
  - Auto-detects color support
32
32
  - Actively maintained
33
- - [Used by ~7700 modules](https://www.npmjs.com/browse/depended/chalk) as of March 15, 2016
33
+ - [Used by ~4500 modules](https://www.npmjs.com/browse/depended/chalk) as of July 15, 2015
34
34
 
35
35
 
36
36
  ## Install
@@ -42,18 +42,13 @@ $ npm install --save chalk
42
42
 
43
43
  ## Usage
44
44
 
45
- ```js
46
- const chalk = require('chalk');
47
-
48
- console.log(chalk.blue('Hello world!'));
49
- ```
50
-
51
45
  Chalk comes with an easy to use composable API where you just chain and nest the styles you want.
52
46
 
53
- Here without `console.log` for purity.
54
-
55
47
  ```js
56
- const chalk = require('chalk');
48
+ var chalk = require('chalk');
49
+
50
+ // style a string
51
+ chalk.blue('Hello world!');
57
52
 
58
53
  // combine styled and normal strings
59
54
  chalk.blue('Hello') + 'World' + chalk.red('!');
@@ -73,29 +68,22 @@ chalk.green(
73
68
  chalk.blue.underline.bold('with a blue substring') +
74
69
  ' that becomes green again!'
75
70
  );
76
-
77
- // ES2015 template literal
78
- const systemStats = `
79
- CPU: ${chalk.red('90%')}
80
- RAM: ${chalk.green('40%')}
81
- DISK: ${chalk.yellow('70%')}
82
- `;
83
71
  ```
84
72
 
85
73
  Easily define your own themes.
86
74
 
87
75
  ```js
88
- const chalk = require('chalk');
89
- const error = chalk.bold.red;
76
+ var chalk = require('chalk');
77
+ var error = chalk.bold.red;
90
78
  console.log(error('Error!'));
91
79
  ```
92
80
 
93
81
  Take advantage of console.log [string substitution](http://nodejs.org/docs/latest/api/console.html#console_console_log_data).
94
82
 
95
83
  ```js
96
- const name = 'Sindre';
84
+ var name = 'Sindre';
97
85
  console.log(chalk.green('Hello %s'), name);
98
- //=> 'Hello Sindre'
86
+ //=> Hello Sindre
99
87
  ```
100
88
 
101
89
 
@@ -116,7 +104,7 @@ Color support is automatically detected, but you can override it by setting the
116
104
  If you need to change this in a reusable module create a new instance:
117
105
 
118
106
  ```js
119
- const ctx = new chalk.constructor({enabled: false});
107
+ var ctx = new chalk.constructor({enabled: false});
120
108
  ```
121
109
 
122
110
  ### chalk.supportsColor
@@ -132,7 +120,7 @@ Exposes the styles as [ANSI escape codes](https://github.com/chalk/ansi-styles).
132
120
  Generally not useful, but you might need just the `.open` or `.close` escape code if you're mixing externally styled strings with your own.
133
121
 
134
122
  ```js
135
- const chalk = require('chalk');
123
+ var chalk = require('chalk');
136
124
 
137
125
  console.log(chalk.styles.red);
138
126
  //=> {open: '\u001b[31m', close: '\u001b[39m'}
@@ -140,6 +128,27 @@ console.log(chalk.styles.red);
140
128
  console.log(chalk.styles.red.open + 'Hello' + chalk.styles.red.close);
141
129
  ```
142
130
 
131
+ ### chalk.hasColor(string)
132
+
133
+ Check whether a string [has color](https://github.com/chalk/has-ansi).
134
+
135
+ ### chalk.stripColor(string)
136
+
137
+ [Strip color](https://github.com/chalk/strip-ansi) from a string.
138
+
139
+ Can be useful in combination with `.supportsColor` to strip color on externally styled text when it's not supported.
140
+
141
+ Example:
142
+
143
+ ```js
144
+ var chalk = require('chalk');
145
+ var styledString = getText();
146
+
147
+ if (!chalk.supportsColor) {
148
+ styledString = chalk.stripColor(styledString);
149
+ }
150
+ ```
151
+
143
152
 
144
153
  ## Styles
145
154
 
@@ -185,7 +194,7 @@ Chalk does not support anything other than the base eight colors, which guarante
185
194
 
186
195
  ## Windows
187
196
 
188
- If you're on Windows, do yourself a favor and use [`cmder`](http://cmder.net/) instead of `cmd.exe`.
197
+ If you're on Windows, do yourself a favor and use [`cmder`](http://bliker.github.io/cmder/) instead of `cmd.exe`.
189
198
 
190
199
 
191
200
  ## Related
@@ -197,7 +206,6 @@ If you're on Windows, do yourself a favor and use [`cmder`](http://cmder.net/) i
197
206
  - [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes
198
207
  - [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
199
208
  - [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes
200
- - [slice-ansi](https://github.com/chalk/slice-ansi) - Slice a string with ANSI escape codes
201
209
 
202
210
 
203
211
  ## License