chalk 0.1.1 → 0.4.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.
@@ -1,16 +1,19 @@
1
1
  'use strict';
2
2
  var ansi = require('ansi-styles');
3
+ var stripAnsi = require('strip-ansi');
4
+ var hasColor = require('has-color');
3
5
  var defineProps = Object.defineProperties;
6
+ var chalk = module.exports;
4
7
 
5
8
  var styles = (function () {
6
9
  var ret = {};
7
10
 
11
+ ansi.grey = ansi.gray;
12
+
8
13
  Object.keys(ansi).forEach(function (key) {
9
- var code = ansi[key];
10
14
  ret[key] = {
11
- enumerable: true,
12
15
  get: function () {
13
- this._styles.push(code);
16
+ this._styles.push(key);
14
17
  return this;
15
18
  }
16
19
  };
@@ -19,25 +22,23 @@ var styles = (function () {
19
22
  return ret;
20
23
  })();
21
24
 
22
- var chalk = module.exports = defineProps({}, init());
23
-
24
25
  function init() {
25
26
  var ret = {};
26
27
 
27
28
  Object.keys(styles).forEach(function (name) {
28
- var code = styles[name];
29
-
30
29
  ret[name] = {
31
- enumerable: true,
32
30
  get: function () {
33
- var obj = defineProps(function self(str) {
31
+ var obj = defineProps(function self() {
32
+ var str = [].slice.call(arguments).join(' ');
33
+
34
34
  if (!chalk.enabled) {
35
35
  return str;
36
36
  }
37
37
 
38
- return self._styles.reduce(function (str, code) {
39
- return code + (str || '');
40
- }, str) + ansi['reset'];
38
+ return self._styles.reduce(function (str, name) {
39
+ var code = ansi[name];
40
+ return str ? code.open + str + code.close : '';
41
+ }, str);
41
42
  }, styles);
42
43
 
43
44
  obj._styles = [];
@@ -50,13 +51,11 @@ function init() {
50
51
  return ret;
51
52
  }
52
53
 
53
- chalk.styles = ansi;
54
-
55
- chalk.stripColor = function (str) {
56
- return str.replace(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/g, '');
57
- };
54
+ defineProps(chalk, init());
58
55
 
59
- chalk.supportsColor = require('has-color');
56
+ chalk.styles = ansi;
57
+ chalk.stripColor = stripAnsi;
58
+ chalk.supportsColor = hasColor;
60
59
 
61
60
  // detect mode if not set manually
62
61
  if (chalk.enabled === undefined) {
package/package.json CHANGED
@@ -1,7 +1,23 @@
1
1
  {
2
2
  "name": "chalk",
3
- "version": "0.1.1",
4
- "description": "Terminal string styling done right",
3
+ "version": "0.4.0",
4
+ "description": "Terminal string styling done right. Created because the `colors` module does some really horrible things.",
5
+ "license": "MIT",
6
+ "repository": "sindresorhus/chalk",
7
+ "author": {
8
+ "name": "Sindre Sorhus",
9
+ "email": "sindresorhus@gmail.com",
10
+ "url": "http://sindresorhus.com"
11
+ },
12
+ "engines": {
13
+ "node": ">=0.8.0"
14
+ },
15
+ "scripts": {
16
+ "test": "mocha"
17
+ },
18
+ "files": [
19
+ "index.js"
20
+ ],
5
21
  "keywords": [
6
22
  "color",
7
23
  "colour",
@@ -23,33 +39,12 @@
23
39
  "command-line",
24
40
  "text"
25
41
  ],
26
- "homepage": "https://github.com/sindresorhus/chalk",
27
- "bugs": "https://github.com/sindresorhus/chalk/issues",
28
- "license": "MIT",
29
- "author": {
30
- "name": "Sindre Sorhus",
31
- "email": "sindresorhus@gmail.com",
32
- "url": "http://sindresorhus.com"
33
- },
34
- "files": [
35
- "chalk.js"
36
- ],
37
- "main": "chalk",
38
- "repository": {
39
- "type": "git",
40
- "url": "git://github.com/sindresorhus/chalk.git"
41
- },
42
- "scripts": {
43
- "test": "mocha"
44
- },
45
42
  "dependencies": {
46
43
  "has-color": "~0.1.0",
47
- "ansi-styles": "~0.1.0"
44
+ "ansi-styles": "~1.0.0",
45
+ "strip-ansi": "~0.1.0"
48
46
  },
49
47
  "devDependencies": {
50
- "mocha": "~1.12.0"
51
- },
52
- "engines": {
53
- "node": ">=0.8.0"
48
+ "mocha": "~1.x"
54
49
  }
55
50
  }
package/readme.md CHANGED
@@ -1,8 +1,10 @@
1
- # chalk [![Build Status](https://secure.travis-ci.org/sindresorhus/chalk.png?branch=master)](http://travis-ci.org/sindresorhus/chalk)
1
+ # <img width="250" src="logo.png" alt="chalk">
2
2
 
3
- > Terminal string styling done right.
3
+ > Terminal string styling done right
4
4
 
5
- [colors.js](https://github.com/Marak/colors.js) is currently the most popular coloring module, but it has serious deficiencies like extending String.prototype which causes all kinds of problems. Although there are other ones, they either do too much or not enough.
5
+ [![Build Status](https://secure.travis-ci.org/sindresorhus/chalk.png?branch=master)](http://travis-ci.org/sindresorhus/chalk)
6
+
7
+ [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.
6
8
 
7
9
  **Chalk is a clean and focused alternative.**
8
10
 
@@ -13,8 +15,10 @@
13
15
 
14
16
  - **Doesn't extend String.prototype**
15
17
  - Expressive API
18
+ - Clean and focused
16
19
  - Auto-detects color support
17
20
  - Actively maintained
21
+ - [Used by 150+ modules](https://npmjs.org/browse/depended/chalk)
18
22
 
19
23
 
20
24
  ## Install
@@ -24,19 +28,25 @@ Install with [npm](https://npmjs.org/package/chalk): `npm install --save chalk`
24
28
 
25
29
  ## Example
26
30
 
27
- Chalk comes with an easy to use composable API where you just chain the styles you want.
31
+ Chalk comes with an easy to use composable API where you just chain and nest the styles you want.
28
32
 
29
33
  ```js
30
34
  var chalk = require('chalk');
31
35
 
32
36
  // style a string
33
- console.log(chalk.blue('Hello world!'));
37
+ console.log( chalk.blue('Hello world!') );
34
38
 
35
39
  // combine styled and normal strings
36
- console.log(chalk.blue('Hello') + 'World' + chalk.red('!'));
40
+ console.log( chalk.blue('Hello'), 'World' + chalk.red('!') );
37
41
 
38
42
  // compose multiple styles using the chainable API
39
- console.log(chalk.blue.bgRed.bold('Hello world!'));
43
+ console.log( chalk.blue.bgRed.bold('Hello world!') );
44
+
45
+ // nest styles
46
+ console.log( chalk.red('Hello', chalk.underline.bgBlue('world') + '!') );
47
+
48
+ // pass in multiple arguments
49
+ console.log( chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz') );
40
50
  ```
41
51
 
42
52
  You can easily define your own themes.
@@ -50,10 +60,13 @@ console.log(error('Error!'));
50
60
 
51
61
  ## API
52
62
 
53
- ### chalk.\<style\>\[.\<style\>...\](*string*)
63
+ ### chalk.`<style>[.<style>...](string, [string...])`
54
64
 
55
- Chain [styles](#styles) and call the last one as a method with a string argument.
65
+ Example: `chalk.red.bold.underline('Hello', 'world');`
56
66
 
67
+ Chain [styles](#styles) and call the last one as a method with a string argument. Order doesn't matter.
68
+
69
+ Multiple arguments will be separated by space.
57
70
 
58
71
  ### chalk.enabled
59
72
 
@@ -71,15 +84,33 @@ Used internally and handled for you, but exposed for convenience.
71
84
 
72
85
  Exposes the styles as [ANSI escape codes](https://github.com/sindresorhus/ansi-styles).
73
86
 
87
+ Generally not useful, but you might need just the `.open` or `.close` escape code if you're mixing externally styled strings with yours.
88
+
74
89
  ```js
75
90
  var chalk = require('chalk');
91
+
76
92
  console.log(chalk.styles.red);
77
- //=> \x1b[31m
93
+ //=> {open: '\x1b[31m', close: '\x1b[39m'}
94
+
95
+ console.log(chalk.styles.red.open + 'Hello' + chalk.styles.red.close);
78
96
  ```
79
97
 
80
- ### chalk.stripColor(*string*)
98
+ ### chalk.stripColor(string)
81
99
 
82
- Strip color from a string.
100
+ [Strip color](https://github.com/sindresorhus/strip-ansi) from a string.
101
+
102
+ Can be useful in combination with `.supportsColor` to strip color on externally styled text when it's not supported.
103
+
104
+ Example:
105
+
106
+ ```js
107
+ var chalk = require('chalk');
108
+ var styledString = fromExternal();
109
+
110
+ if (!chalk.supportsColor) {
111
+ chalk.stripColor(styledString);
112
+ }
113
+ ```
83
114
 
84
115
 
85
116
  ## Styles
@@ -90,7 +121,6 @@ Strip color from a string.
90
121
  - bold
91
122
  - italic
92
123
  - underline
93
- - blink
94
124
  - inverse
95
125
  - strikethrough
96
126
 
@@ -104,7 +134,6 @@ Strip color from a string.
104
134
  - magenta
105
135
  - cyan
106
136
  - white
107
- - default
108
137
  - gray
109
138
 
110
139
  ### Background colors
@@ -117,9 +146,13 @@ Strip color from a string.
117
146
  - bgMagenta
118
147
  - bgCyan
119
148
  - bgWhite
120
- - bgDefault
121
149
 
122
150
 
123
151
  ## License
124
152
 
125
- MIT License • © [Sindre Sorhus](http://sindresorhus.com)
153
+ MIT © [Sindre Sorhus](http://sindresorhus.com)
154
+
155
+
156
+ -
157
+
158
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/sindresorhus/chalk/trend.png)](https://bitdeli.com/free "Bitdeli Badge")