ansi-styles 1.1.0 → 2.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 (3) hide show
  1. package/index.js +49 -33
  2. package/package.json +1 -1
  3. package/readme.md +19 -3
package/index.js CHANGED
@@ -1,40 +1,56 @@
1
1
  'use strict';
2
- var styles = module.exports;
3
2
 
4
- var codes = {
5
- reset: [0, 0],
3
+ var styles = module.exports = {
4
+ modifiers: {
5
+ reset: [0, 0],
6
+ bold: [1, 22], // 21 isn't widely supported and 22 does the same thing
7
+ dim: [2, 22],
8
+ italic: [3, 23],
9
+ underline: [4, 24],
10
+ inverse: [7, 27],
11
+ hidden: [8, 28],
12
+ strikethrough: [9, 29]
13
+ },
14
+ colors: {
15
+ black: [30, 39],
16
+ red: [31, 39],
17
+ green: [32, 39],
18
+ yellow: [33, 39],
19
+ blue: [34, 39],
20
+ magenta: [35, 39],
21
+ cyan: [36, 39],
22
+ white: [37, 39],
23
+ gray: [90, 39]
24
+ },
25
+ bgColors: {
26
+ bgBlack: [40, 49],
27
+ bgRed: [41, 49],
28
+ bgGreen: [42, 49],
29
+ bgYellow: [43, 49],
30
+ bgBlue: [44, 49],
31
+ bgMagenta: [45, 49],
32
+ bgCyan: [46, 49],
33
+ bgWhite: [47, 49]
34
+ }
35
+ };
6
36
 
7
- bold: [1, 22], // 21 isn't widely supported and 22 does the same thing
8
- dim: [2, 22],
9
- italic: [3, 23],
10
- underline: [4, 24],
11
- inverse: [7, 27],
12
- hidden: [8, 28],
13
- strikethrough: [9, 29],
37
+ // fix humans
38
+ styles.colors.grey = styles.colors.gray;
14
39
 
15
- black: [30, 39],
16
- red: [31, 39],
17
- green: [32, 39],
18
- yellow: [33, 39],
19
- blue: [34, 39],
20
- magenta: [35, 39],
21
- cyan: [36, 39],
22
- white: [37, 39],
23
- gray: [90, 39],
40
+ Object.keys(styles).forEach(function (groupName) {
41
+ var group = styles[groupName];
24
42
 
25
- bgBlack: [40, 49],
26
- bgRed: [41, 49],
27
- bgGreen: [42, 49],
28
- bgYellow: [43, 49],
29
- bgBlue: [44, 49],
30
- bgMagenta: [45, 49],
31
- bgCyan: [46, 49],
32
- bgWhite: [47, 49]
33
- };
43
+ Object.keys(group).forEach(function (styleName) {
44
+ var style = group[styleName];
45
+
46
+ styles[styleName] = group[styleName] = {
47
+ open: '\u001b[' + style[0] + 'm',
48
+ close: '\u001b[' + style[1] + 'm'
49
+ };
50
+ });
34
51
 
35
- Object.keys(codes).forEach(function (key) {
36
- var val = codes[key];
37
- var style = styles[key] = {};
38
- style.open = '\u001b[' + val[0] + 'm';
39
- style.close = '\u001b[' + val[1] + 'm';
52
+ Object.defineProperty(styles, groupName, {
53
+ value: group,
54
+ enumerable: false
55
+ });
40
56
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ansi-styles",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "ANSI escape codes for styling strings in the terminal",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/ansi-styles",
package/readme.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  You probably want the higher-level [chalk](https://github.com/sindresorhus/chalk) module for styling your strings.
6
6
 
7
- ![screenshot](screenshot.png)
7
+ ![](screenshot.png)
8
8
 
9
9
 
10
10
  ## Install
@@ -30,7 +30,7 @@ Each style has an `open` and `close` property.
30
30
 
31
31
  ## Styles
32
32
 
33
- ### General
33
+ ### Modifiers
34
34
 
35
35
  - `reset`
36
36
  - `bold`
@@ -41,7 +41,7 @@ Each style has an `open` and `close` property.
41
41
  - `hidden`
42
42
  - `strikethrough` *(not widely supported)*
43
43
 
44
- ### Text colors
44
+ ### Colors
45
45
 
46
46
  - `black`
47
47
  - `red`
@@ -65,6 +65,22 @@ Each style has an `open` and `close` property.
65
65
  - `bgWhite`
66
66
 
67
67
 
68
+ ## Advanced usage
69
+
70
+ By default you get a map of styles, but the styles are also available as groups. They are non-enumerable so they don't show up unless you access them explicitly. This makes it easier to expose only a subset in a higher-level module.
71
+
72
+ - `ansi.modifiers`
73
+ - `ansi.colors`
74
+ - `ansi.bgColors`
75
+
76
+
77
+ ###### Example
78
+
79
+ ```js
80
+ console.log(ansi.colors.green.open);
81
+ ```
82
+
83
+
68
84
  ## License
69
85
 
70
86
  MIT © [Sindre Sorhus](http://sindresorhus.com)