chalk 0.3.0 → 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.
- package/{chalk.js → index.js} +10 -11
- package/package.json +21 -26
- package/readme.md +41 -17
package/{chalk.js → index.js}
RENAMED
|
@@ -1,12 +1,15 @@
|
|
|
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;
|
|
4
|
-
|
|
5
|
-
ansi.grey = ansi.gray;
|
|
6
|
+
var chalk = module.exports;
|
|
6
7
|
|
|
7
8
|
var styles = (function () {
|
|
8
9
|
var ret = {};
|
|
9
10
|
|
|
11
|
+
ansi.grey = ansi.gray;
|
|
12
|
+
|
|
10
13
|
Object.keys(ansi).forEach(function (key) {
|
|
11
14
|
ret[key] = {
|
|
12
15
|
get: function () {
|
|
@@ -19,8 +22,6 @@ 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
|
|
|
@@ -36,7 +37,7 @@ function init() {
|
|
|
36
37
|
|
|
37
38
|
return self._styles.reduce(function (str, name) {
|
|
38
39
|
var code = ansi[name];
|
|
39
|
-
return code
|
|
40
|
+
return str ? code.open + str + code.close : '';
|
|
40
41
|
}, str);
|
|
41
42
|
}, styles);
|
|
42
43
|
|
|
@@ -50,13 +51,11 @@ function init() {
|
|
|
50
51
|
return ret;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
chalk
|
|
54
|
-
|
|
55
|
-
chalk.stripColor = function (str) {
|
|
56
|
-
return typeof str === 'string' ? str.replace(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/g, '') : str;
|
|
57
|
-
};
|
|
54
|
+
defineProps(chalk, init());
|
|
58
55
|
|
|
59
|
-
chalk.
|
|
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.
|
|
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.
|
|
44
|
+
"ansi-styles": "~1.0.0",
|
|
45
|
+
"strip-ansi": "~0.1.0"
|
|
48
46
|
},
|
|
49
47
|
"devDependencies": {
|
|
50
|
-
"mocha": "~1.
|
|
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
|
-
#
|
|
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
|
-
[
|
|
5
|
+
[](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
|
|
|
@@ -16,6 +18,7 @@
|
|
|
16
18
|
- Clean and focused
|
|
17
19
|
- Auto-detects color support
|
|
18
20
|
- Actively maintained
|
|
21
|
+
- [Used by 150+ modules](https://npmjs.org/browse/depended/chalk)
|
|
19
22
|
|
|
20
23
|
|
|
21
24
|
## Install
|
|
@@ -25,25 +28,25 @@ Install with [npm](https://npmjs.org/package/chalk): `npm install --save chalk`
|
|
|
25
28
|
|
|
26
29
|
## Example
|
|
27
30
|
|
|
28
|
-
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.
|
|
29
32
|
|
|
30
33
|
```js
|
|
31
34
|
var chalk = require('chalk');
|
|
32
35
|
|
|
33
36
|
// style a string
|
|
34
|
-
console.log(chalk.blue('Hello world!'));
|
|
37
|
+
console.log( chalk.blue('Hello world!') );
|
|
35
38
|
|
|
36
39
|
// combine styled and normal strings
|
|
37
|
-
console.log(chalk.blue('Hello'), 'World' + chalk.red('!'));
|
|
40
|
+
console.log( chalk.blue('Hello'), 'World' + chalk.red('!') );
|
|
38
41
|
|
|
39
42
|
// compose multiple styles using the chainable API
|
|
40
|
-
console.log(chalk.blue.bgRed.bold('Hello world!'));
|
|
43
|
+
console.log( chalk.blue.bgRed.bold('Hello world!') );
|
|
41
44
|
|
|
42
45
|
// nest styles
|
|
43
|
-
chalk.red('Hello', chalk.underline.bgBlue('world') + '!');
|
|
46
|
+
console.log( chalk.red('Hello', chalk.underline.bgBlue('world') + '!') );
|
|
44
47
|
|
|
45
48
|
// pass in multiple arguments
|
|
46
|
-
console.log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'))
|
|
49
|
+
console.log( chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz') );
|
|
47
50
|
```
|
|
48
51
|
|
|
49
52
|
You can easily define your own themes.
|
|
@@ -57,11 +60,13 @@ console.log(error('Error!'));
|
|
|
57
60
|
|
|
58
61
|
## API
|
|
59
62
|
|
|
60
|
-
### chalk
|
|
63
|
+
### chalk.`<style>[.<style>...](string, [string...])`
|
|
64
|
+
|
|
65
|
+
Example: `chalk.red.bold.underline('Hello', 'world');`
|
|
61
66
|
|
|
62
|
-
Chain [styles](#styles) and call the last one as a method with a string argument.
|
|
67
|
+
Chain [styles](#styles) and call the last one as a method with a string argument. Order doesn't matter.
|
|
63
68
|
|
|
64
|
-
Multiple arguments
|
|
69
|
+
Multiple arguments will be separated by space.
|
|
65
70
|
|
|
66
71
|
### chalk.enabled
|
|
67
72
|
|
|
@@ -79,19 +84,33 @@ Used internally and handled for you, but exposed for convenience.
|
|
|
79
84
|
|
|
80
85
|
Exposes the styles as [ANSI escape codes](https://github.com/sindresorhus/ansi-styles).
|
|
81
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
|
+
|
|
82
89
|
```js
|
|
83
90
|
var chalk = require('chalk');
|
|
84
91
|
|
|
85
92
|
console.log(chalk.styles.red);
|
|
86
|
-
//=>
|
|
93
|
+
//=> {open: '\x1b[31m', close: '\x1b[39m'}
|
|
87
94
|
|
|
88
|
-
console.log(chalk.styles.red
|
|
89
|
-
// first item is the style escape code and second is the reset escape code
|
|
95
|
+
console.log(chalk.styles.red.open + 'Hello' + chalk.styles.red.close);
|
|
90
96
|
```
|
|
91
97
|
|
|
92
98
|
### chalk.stripColor(string)
|
|
93
99
|
|
|
94
|
-
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
|
+
```
|
|
95
114
|
|
|
96
115
|
|
|
97
116
|
## Styles
|
|
@@ -131,4 +150,9 @@ Strip color from a string.
|
|
|
131
150
|
|
|
132
151
|
## License
|
|
133
152
|
|
|
134
|
-
MIT
|
|
153
|
+
MIT © [Sindre Sorhus](http://sindresorhus.com)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
-
|
|
157
|
+
|
|
158
|
+
[](https://bitdeli.com/free "Bitdeli Badge")
|