chalk 0.1.0 → 0.3.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 (3) hide show
  1. package/chalk.js +11 -11
  2. package/package.json +2 -2
  3. package/readme.md +17 -8
package/chalk.js CHANGED
@@ -2,15 +2,15 @@
2
2
  var ansi = require('ansi-styles');
3
3
  var defineProps = Object.defineProperties;
4
4
 
5
+ ansi.grey = ansi.gray;
6
+
5
7
  var styles = (function () {
6
8
  var ret = {};
7
9
 
8
10
  Object.keys(ansi).forEach(function (key) {
9
- var code = ansi[key];
10
11
  ret[key] = {
11
- enumerable: true,
12
12
  get: function () {
13
- this._styles.push(code);
13
+ this._styles.push(key);
14
14
  return this;
15
15
  }
16
16
  };
@@ -25,19 +25,19 @@ function init() {
25
25
  var ret = {};
26
26
 
27
27
  Object.keys(styles).forEach(function (name) {
28
- var code = styles[name];
29
-
30
28
  ret[name] = {
31
- enumerable: true,
32
29
  get: function () {
33
- var obj = defineProps(function self(str) {
30
+ var obj = defineProps(function self() {
31
+ var str = [].slice.call(arguments).join(' ');
32
+
34
33
  if (!chalk.enabled) {
35
34
  return str;
36
35
  }
37
36
 
38
- return self._styles.reduce(function (str, code) {
39
- return code + (str || '');
40
- }, str) + ansi['reset'];
37
+ return self._styles.reduce(function (str, name) {
38
+ var code = ansi[name];
39
+ return code[0] + (str || '') + code[1];
40
+ }, str);
41
41
  }, styles);
42
42
 
43
43
  obj._styles = [];
@@ -53,7 +53,7 @@ function init() {
53
53
  chalk.styles = ansi;
54
54
 
55
55
  chalk.stripColor = function (str) {
56
- return str.replace(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/g, '');
56
+ return typeof str === 'string' ? str.replace(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/g, '') : str;
57
57
  };
58
58
 
59
59
  chalk.supportsColor = require('has-color');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chalk",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Terminal string styling done right",
5
5
  "keywords": [
6
6
  "color",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "has-color": "~0.1.0",
47
- "ansi-styles": "~0.1.0"
47
+ "ansi-styles": "~0.2.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "mocha": "~1.12.0"
package/readme.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
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
+ [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. Although there are other ones, they either do too much or not enough.
6
6
 
7
7
  **Chalk is a clean and focused alternative.**
8
8
 
@@ -13,6 +13,7 @@
13
13
 
14
14
  - **Doesn't extend String.prototype**
15
15
  - Expressive API
16
+ - Clean and focused
16
17
  - Auto-detects color support
17
18
  - Actively maintained
18
19
 
@@ -33,10 +34,16 @@ var chalk = require('chalk');
33
34
  console.log(chalk.blue('Hello world!'));
34
35
 
35
36
  // combine styled and normal strings
36
- console.log(chalk.blue('Hello') + 'World' + chalk.red('!'));
37
+ console.log(chalk.blue('Hello'), 'World' + chalk.red('!'));
37
38
 
38
39
  // compose multiple styles using the chainable API
39
40
  console.log(chalk.blue.bgRed.bold('Hello world!'));
41
+
42
+ // nest styles
43
+ chalk.red('Hello', chalk.underline.bgBlue('world') + '!');
44
+
45
+ // pass in multiple arguments
46
+ console.log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'))
40
47
  ```
41
48
 
42
49
  You can easily define your own themes.
@@ -50,10 +57,11 @@ console.log(error('Error!'));
50
57
 
51
58
  ## API
52
59
 
53
- ### chalk.\<style\>\[.\<style\>...\](string)
60
+ ### chalk.\<style>\[.\<style>...](string)
54
61
 
55
- Chain [styles](#Styles) and call the last one as a method with a string argument.
62
+ Chain [styles](#styles) and call the last one as a method with a string argument.
56
63
 
64
+ Multiple arguments are also supported. Chalk will add a space between each one.
57
65
 
58
66
  ### chalk.enabled
59
67
 
@@ -73,8 +81,12 @@ Exposes the styles as [ANSI escape codes](https://github.com/sindresorhus/ansi-s
73
81
 
74
82
  ```js
75
83
  var chalk = require('chalk');
84
+
76
85
  console.log(chalk.styles.red);
77
- //=> \x1b[31m
86
+ //=> ['\x1b[31m', '\x1b[39m']
87
+
88
+ console.log(chalk.styles.red[0] + 'Hello' + chalk.styles.red[1]);
89
+ // first item is the style escape code and second is the reset escape code
78
90
  ```
79
91
 
80
92
  ### chalk.stripColor(string)
@@ -90,7 +102,6 @@ Strip color from a string.
90
102
  - bold
91
103
  - italic
92
104
  - underline
93
- - blink
94
105
  - inverse
95
106
  - strikethrough
96
107
 
@@ -104,7 +115,6 @@ Strip color from a string.
104
115
  - magenta
105
116
  - cyan
106
117
  - white
107
- - default
108
118
  - gray
109
119
 
110
120
  ### Background colors
@@ -117,7 +127,6 @@ Strip color from a string.
117
127
  - bgMagenta
118
128
  - bgCyan
119
129
  - bgWhite
120
- - bgDefault
121
130
 
122
131
 
123
132
  ## License