colors 1.2.0 → 1.2.4

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,34 +1,36 @@
1
1
  var colors = require('../lib/index');
2
2
 
3
- console.log("First some yellow text".yellow);
3
+ console.log('First some yellow text'.yellow);
4
4
 
5
- console.log("Underline that text".yellow.underline);
5
+ console.log('Underline that text'.yellow.underline);
6
6
 
7
- console.log("Make it bold and red".red.bold);
7
+ console.log('Make it bold and red'.red.bold);
8
8
 
9
- console.log(("Double Raindows All Day Long").rainbow)
9
+ console.log(('Double Raindows All Day Long').rainbow);
10
10
 
11
- console.log("Drop the bass".trap)
11
+ console.log('Drop the bass'.trap);
12
12
 
13
- console.log("DROP THE RAINBOW BASS".trap.rainbow)
13
+ console.log('DROP THE RAINBOW BASS'.trap.rainbow);
14
14
 
15
+ // styles not widely supported
16
+ console.log('Chains are also cool.'.bold.italic.underline.red);
15
17
 
16
- console.log('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported
17
-
18
- console.log('So '.green + 'are'.underline + ' ' + 'inverse'.inverse + ' styles! '.yellow.bold); // styles not widely supported
19
- console.log("Zebras are so fun!".zebra);
18
+ // styles not widely supported
19
+ console.log('So '.green + 'are'.underline + ' ' + 'inverse'.inverse
20
+ + ' styles! '.yellow.bold);
21
+ console.log('Zebras are so fun!'.zebra);
20
22
 
21
23
  //
22
24
  // Remark: .strikethrough may not work with Mac OS Terminal App
23
25
  //
24
- console.log("This is " + "not".strikethrough + " fun.");
26
+ console.log('This is ' + 'not'.strikethrough + ' fun.');
25
27
 
26
- console.log('Background color attack!'.black.bgWhite)
27
- console.log('Use random styles on everything!'.random)
28
- console.log('America, Heck Yeah!'.america)
28
+ console.log('Background color attack!'.black.bgWhite);
29
+ console.log('Use random styles on everything!'.random);
30
+ console.log('America, Heck Yeah!'.america);
29
31
 
30
32
 
31
- console.log('Setting themes is useful')
33
+ console.log('Setting themes is useful');
32
34
 
33
35
  //
34
36
  // Custom themes
@@ -45,17 +47,17 @@ colors.setTheme({
45
47
  help: 'cyan',
46
48
  warn: 'yellow',
47
49
  debug: 'blue',
48
- error: 'red'
50
+ error: 'red',
49
51
  });
50
52
 
51
53
  // outputs red text
52
- console.log("this is an error".error);
54
+ console.log('this is an error'.error);
53
55
 
54
56
  // outputs yellow text
55
- console.log("this is a warning".warn);
57
+ console.log('this is a warning'.warn);
56
58
 
57
59
  // outputs grey text
58
- console.log("this is an input".input);
60
+ console.log('this is an input'.input);
59
61
 
60
62
  console.log('Generic logging theme as file'.green.bold.underline);
61
63
 
@@ -67,12 +69,13 @@ try {
67
69
  }
68
70
 
69
71
  // outputs red text
70
- console.log("this is an error".error);
72
+ console.log('this is an error'.error);
71
73
 
72
74
  // outputs yellow text
73
- console.log("this is a warning".warn);
75
+ console.log('this is a warning'.warn);
74
76
 
75
77
  // outputs grey text
76
- console.log("this is an input".input);
78
+ console.log('this is an input'.input);
79
+
80
+ // console.log("Don't summon".zalgo)
77
81
 
78
- //console.log("Don't summon".zalgo)
@@ -1,37 +1,39 @@
1
1
  var colors = require('../safe');
2
2
 
3
- console.log(colors.yellow("First some yellow text"));
3
+ console.log(colors.yellow('First some yellow text'));
4
4
 
5
- console.log(colors.yellow.underline("Underline that text"));
5
+ console.log(colors.yellow.underline('Underline that text'));
6
6
 
7
- console.log(colors.red.bold("Make it bold and red"));
7
+ console.log(colors.red.bold('Make it bold and red'));
8
8
 
9
- console.log(colors.rainbow("Double Raindows All Day Long"))
9
+ console.log(colors.rainbow('Double Raindows All Day Long'));
10
10
 
11
- console.log(colors.trap("Drop the bass"))
11
+ console.log(colors.trap('Drop the bass'));
12
12
 
13
- console.log(colors.rainbow(colors.trap("DROP THE RAINBOW BASS")));
13
+ console.log(colors.rainbow(colors.trap('DROP THE RAINBOW BASS')));
14
14
 
15
- console.log(colors.bold.italic.underline.red('Chains are also cool.')); // styles not widely supported
15
+ // styles not widely supported
16
+ console.log(colors.bold.italic.underline.red('Chains are also cool.'));
16
17
 
18
+ // styles not widely supported
19
+ console.log(colors.green('So ') + colors.underline('are') + ' '
20
+ + colors.inverse('inverse') + colors.yellow.bold(' styles! '));
17
21
 
18
- console.log(colors.green('So ') + colors.underline('are') + ' ' + colors.inverse('inverse') + colors.yellow.bold(' styles! ')); // styles not widely supported
22
+ console.log(colors.zebra('Zebras are so fun!'));
19
23
 
20
- console.log(colors.zebra("Zebras are so fun!"));
21
-
22
- console.log("This is " + colors.strikethrough("not") + " fun.");
24
+ console.log('This is ' + colors.strikethrough('not') + ' fun.');
23
25
 
24
26
 
25
27
  console.log(colors.black.bgWhite('Background color attack!'));
26
- console.log(colors.random('Use random styles on everything!'))
28
+ console.log(colors.random('Use random styles on everything!'));
27
29
  console.log(colors.america('America, Heck Yeah!'));
28
30
 
29
- console.log('Setting themes is useful')
31
+ console.log('Setting themes is useful');
30
32
 
31
33
  //
32
34
  // Custom themes
33
35
  //
34
- //console.log('Generic logging theme as JSON'.green.bold.underline);
36
+ // console.log('Generic logging theme as JSON'.green.bold.underline);
35
37
  // Load theme with JSON literal
36
38
  colors.setTheme({
37
39
  silly: 'rainbow',
@@ -43,17 +45,17 @@ colors.setTheme({
43
45
  help: 'cyan',
44
46
  warn: 'yellow',
45
47
  debug: 'blue',
46
- error: 'red'
48
+ error: 'red',
47
49
  });
48
50
 
49
51
  // outputs red text
50
- console.log(colors.error("this is an error"));
52
+ console.log(colors.error('this is an error'));
51
53
 
52
54
  // outputs yellow text
53
- console.log(colors.warn("this is a warning"));
55
+ console.log(colors.warn('this is a warning'));
54
56
 
55
57
  // outputs grey text
56
- console.log(colors.input("this is an input"));
58
+ console.log(colors.input('this is an input'));
57
59
 
58
60
 
59
61
  // console.log('Generic logging theme as file'.green.bold.underline);
@@ -62,15 +64,14 @@ console.log(colors.input("this is an input"));
62
64
  colors.setTheme(__dirname + '/../themes/generic-logging.js');
63
65
 
64
66
  // outputs red text
65
- console.log(colors.error("this is an error"));
67
+ console.log(colors.error('this is an error'));
66
68
 
67
69
  // outputs yellow text
68
- console.log(colors.warn("this is a warning"));
70
+ console.log(colors.warn('this is a warning'));
69
71
 
70
72
  // outputs grey text
71
- console.log(colors.input("this is an input"));
73
+ console.log(colors.input('this is an input'));
72
74
 
73
75
  // console.log(colors.zalgo("Don't summon him"))
74
76
 
75
77
 
76
-
package/index.d.ts ADDED
@@ -0,0 +1,136 @@
1
+ // Type definitions for Colors.js 1.2
2
+ // Project: https://github.com/Marak/colors.js
3
+ // Definitions by: Bart van der Schoor <https://github.com/Bartvds>, Staffan Eketorp <https://github.com/staeke>
4
+ // Definitions: https://github.com/Marak/colors.js
5
+
6
+ export interface Color {
7
+ (text: string): string;
8
+
9
+ strip: Color;
10
+ stripColors: Color;
11
+
12
+ black: Color;
13
+ red: Color;
14
+ green: Color;
15
+ yellow: Color;
16
+ blue: Color;
17
+ magenta: Color;
18
+ cyan: Color;
19
+ white: Color;
20
+ gray: Color;
21
+ grey: Color;
22
+
23
+ bgBlack: Color;
24
+ bgRed: Color;
25
+ bgGreen: Color;
26
+ bgYellow: Color;
27
+ bgBlue: Color;
28
+ bgMagenta: Color;
29
+ bgCyan: Color;
30
+ bgWhite: Color;
31
+
32
+ reset: Color;
33
+ bold: Color;
34
+ dim: Color;
35
+ italic: Color;
36
+ underline: Color;
37
+ inverse: Color;
38
+ hidden: Color;
39
+ strikethrough: Color;
40
+
41
+ rainbow: Color;
42
+ zebra: Color;
43
+ america: Color;
44
+ trap: Color;
45
+ random: Color;
46
+ zalgo: Color;
47
+ }
48
+
49
+ export function enable(): void;
50
+ export function disable(): void;
51
+ export function setTheme(theme: any): void;
52
+
53
+ export let enabled: boolean;
54
+
55
+ export const strip: Color;
56
+ export const stripColors: Color;
57
+
58
+ export const black: Color;
59
+ export const red: Color;
60
+ export const green: Color;
61
+ export const yellow: Color;
62
+ export const blue: Color;
63
+ export const magenta: Color;
64
+ export const cyan: Color;
65
+ export const white: Color;
66
+ export const gray: Color;
67
+ export const grey: Color;
68
+
69
+ export const bgBlack: Color;
70
+ export const bgRed: Color;
71
+ export const bgGreen: Color;
72
+ export const bgYellow: Color;
73
+ export const bgBlue: Color;
74
+ export const bgMagenta: Color;
75
+ export const bgCyan: Color;
76
+ export const bgWhite: Color;
77
+
78
+ export const reset: Color;
79
+ export const bold: Color;
80
+ export const dim: Color;
81
+ export const italic: Color;
82
+ export const underline: Color;
83
+ export const inverse: Color;
84
+ export const hidden: Color;
85
+ export const strikethrough: Color;
86
+
87
+ export const rainbow: Color;
88
+ export const zebra: Color;
89
+ export const america: Color;
90
+ export const trap: Color;
91
+ export const random: Color;
92
+ export const zalgo: Color;
93
+
94
+ declare global {
95
+ interface String {
96
+ strip: string;
97
+ stripColors: string;
98
+
99
+ black: string;
100
+ red: string;
101
+ green: string;
102
+ yellow: string;
103
+ blue: string;
104
+ magenta: string;
105
+ cyan: string;
106
+ white: string;
107
+ gray: string;
108
+ grey: string;
109
+
110
+ bgBlack: string;
111
+ bgRed: string;
112
+ bgGreen: string;
113
+ bgYellow: string;
114
+ bgBlue: string;
115
+ bgMagenta: string;
116
+ bgCyan: string;
117
+ bgWhite: string;
118
+
119
+ reset: string;
120
+ // @ts-ignore
121
+ bold: string;
122
+ dim: string;
123
+ italic: string;
124
+ underline: string;
125
+ inverse: string;
126
+ hidden: string;
127
+ strikethrough: string;
128
+
129
+ rainbow: string;
130
+ zebra: string;
131
+ america: string;
132
+ trap: string;
133
+ random: string;
134
+ zalgo: string;
135
+ }
136
+ }
package/lib/colors.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The MIT License (MIT)
4
4
 
5
- Original Library
5
+ Original Library
6
6
  - Copyright (c) Marak Squires
7
7
 
8
8
  Additional functionality
@@ -33,35 +33,45 @@ module['exports'] = colors;
33
33
 
34
34
  colors.themes = {};
35
35
 
36
+ var util = require('util');
36
37
  var ansiStyles = colors.styles = require('./styles');
37
38
  var defineProps = Object.defineProperties;
39
+ var newLineRegex = new RegExp(/[\r\n]+/g);
38
40
 
39
41
  colors.supportsColor = require('./system/supports-colors').supportsColor;
40
42
 
41
- if (typeof colors.enabled === "undefined") {
43
+ if (typeof colors.enabled === 'undefined') {
42
44
  colors.enabled = colors.supportsColor() !== false;
43
45
  }
44
46
 
45
- colors.stripColors = colors.strip = function(str){
46
- return ("" + str).replace(/\x1B\[\d+m/g, '');
47
+ colors.enable = function() {
48
+ colors.enabled = true;
47
49
  };
48
50
 
51
+ colors.disable = function() {
52
+ colors.enabled = false;
53
+ };
54
+
55
+ colors.stripColors = colors.strip = function(str) {
56
+ return ('' + str).replace(/\x1B\[\d+m/g, '');
57
+ };
49
58
 
50
- var stylize = colors.stylize = function stylize (str, style) {
59
+ // eslint-disable-next-line no-unused-vars
60
+ var stylize = colors.stylize = function stylize(str, style) {
51
61
  if (!colors.enabled) {
52
62
  return str+'';
53
63
  }
54
64
 
55
65
  return ansiStyles[style].open + str + ansiStyles[style].close;
56
- }
66
+ };
57
67
 
58
68
  var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
59
- var escapeStringRegexp = function (str) {
69
+ var escapeStringRegexp = function(str) {
60
70
  if (typeof str !== 'string') {
61
71
  throw new TypeError('Expected a string');
62
72
  }
63
- return str.replace(matchOperatorsRe, '\\$&');
64
- }
73
+ return str.replace(matchOperatorsRe, '\\$&');
74
+ };
65
75
 
66
76
  function build(_styles) {
67
77
  var builder = function builder() {
@@ -74,15 +84,16 @@ function build(_styles) {
74
84
  return builder;
75
85
  }
76
86
 
77
- var styles = (function () {
87
+ var styles = (function() {
78
88
  var ret = {};
79
89
  ansiStyles.grey = ansiStyles.gray;
80
- Object.keys(ansiStyles).forEach(function (key) {
81
- ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
90
+ Object.keys(ansiStyles).forEach(function(key) {
91
+ ansiStyles[key].closeRe =
92
+ new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
82
93
  ret[key] = {
83
- get: function () {
94
+ get: function() {
84
95
  return build(this._styles.concat(key));
85
- }
96
+ },
86
97
  };
87
98
  });
88
99
  return ret;
@@ -91,70 +102,75 @@ var styles = (function () {
91
102
  var proto = defineProps(function colors() {}, styles);
92
103
 
93
104
  function applyStyle() {
94
- var args = arguments;
95
- var argsLen = args.length;
96
- var str = argsLen !== 0 && String(arguments[0]);
97
- if (argsLen > 1) {
98
- for (var a = 1; a < argsLen; a++) {
99
- str += ' ' + args[a];
100
- }
101
- }
105
+ var args = Array.prototype.slice.call(arguments);
106
+
107
+ var str = args.map(function(arg) {
108
+ return arg.constructor === String ? arg : util.inspect(arg);
109
+ }).join(' ');
102
110
 
103
111
  if (!colors.enabled || !str) {
104
112
  return str;
105
113
  }
106
114
 
115
+ var newLinesPresent = str.indexOf('\n') != -1;
116
+
107
117
  var nestedStyles = this._styles;
108
118
 
109
119
  var i = nestedStyles.length;
110
120
  while (i--) {
111
121
  var code = ansiStyles[nestedStyles[i]];
112
122
  str = code.open + str.replace(code.closeRe, code.open) + code.close;
123
+ if (newLinesPresent) {
124
+ str = str.replace(newLineRegex, code.close + '\n' + code.open);
125
+ }
113
126
  }
114
127
 
115
128
  return str;
116
129
  }
117
130
 
118
- colors.setTheme = function (theme) {
131
+ colors.setTheme = function(theme) {
119
132
  if (typeof theme === 'string') {
120
133
  console.log('colors.setTheme now only accepts an object, not a string. ' +
121
- 'If you are trying to set a theme from a file, it is now your (the caller\'s) responsibility to require the file. ' +
122
- 'The old syntax looked like colors.setTheme(__dirname + \'/../themes/generic-logging.js\'); ' +
123
- 'The new syntax looks like colors.setTheme(require(__dirname + \'/../themes/generic-logging.js\'));');
134
+ 'If you are trying to set a theme from a file, it is now your (the ' +
135
+ 'caller\'s) responsibility to require the file. The old syntax ' +
136
+ 'looked like colors.setTheme(__dirname + ' +
137
+ '\'/../themes/generic-logging.js\'); The new syntax looks like '+
138
+ 'colors.setTheme(require(__dirname + ' +
139
+ '\'/../themes/generic-logging.js\'));');
124
140
  return;
125
141
  }
126
142
  for (var style in theme) {
127
- (function(style){
128
- colors[style] = function(str){
129
- if (typeof theme[style] === 'object'){
143
+ (function(style) {
144
+ colors[style] = function(str) {
145
+ if (typeof theme[style] === 'object') {
130
146
  var out = str;
131
- for (var i in theme[style]){
147
+ for (var i in theme[style]) {
132
148
  out = colors[theme[style][i]](out);
133
149
  }
134
150
  return out;
135
151
  }
136
152
  return colors[theme[style]](str);
137
153
  };
138
- })(style)
154
+ })(style);
139
155
  }
140
- }
156
+ };
141
157
 
142
158
  function init() {
143
159
  var ret = {};
144
- Object.keys(styles).forEach(function (name) {
160
+ Object.keys(styles).forEach(function(name) {
145
161
  ret[name] = {
146
- get: function () {
162
+ get: function() {
147
163
  return build([name]);
148
- }
164
+ },
149
165
  };
150
166
  });
151
167
  return ret;
152
168
  }
153
169
 
154
- var sequencer = function sequencer (map, str) {
155
- var exploded = str.split(""), i = 0;
170
+ var sequencer = function sequencer(map, str) {
171
+ var exploded = str.split('');
156
172
  exploded = exploded.map(map);
157
- return exploded.join("");
173
+ return exploded.join('');
158
174
  };
159
175
 
160
176
  // custom formatter methods
@@ -166,14 +182,14 @@ colors.maps = {};
166
182
  colors.maps.america = require('./maps/america');
167
183
  colors.maps.zebra = require('./maps/zebra');
168
184
  colors.maps.rainbow = require('./maps/rainbow');
169
- colors.maps.random = require('./maps/random')
185
+ colors.maps.random = require('./maps/random');
170
186
 
171
187
  for (var map in colors.maps) {
172
- (function(map){
173
- colors[map] = function (str) {
188
+ (function(map) {
189
+ colors[map] = function(str) {
174
190
  return sequencer(colors.maps[map], str);
175
- }
176
- })(map)
191
+ };
192
+ })(map);
177
193
  }
178
194
 
179
195
  defineProps(colors, init());
@@ -1,45 +1,46 @@
1
- module['exports'] = function runTheTrap (text, options) {
2
- var result = "";
3
- text = text || "Run the trap, drop the bass";
1
+ module['exports'] = function runTheTrap(text, options) {
2
+ var result = '';
3
+ text = text || 'Run the trap, drop the bass';
4
4
  text = text.split('');
5
5
  var trap = {
6
- a: ["\u0040", "\u0104", "\u023a", "\u0245", "\u0394", "\u039b", "\u0414"],
7
- b: ["\u00df", "\u0181", "\u0243", "\u026e", "\u03b2", "\u0e3f"],
8
- c: ["\u00a9", "\u023b", "\u03fe"],
9
- d: ["\u00d0", "\u018a", "\u0500" , "\u0501" ,"\u0502", "\u0503"],
10
- e: ["\u00cb", "\u0115", "\u018e", "\u0258", "\u03a3", "\u03be", "\u04bc", "\u0a6c"],
11
- f: ["\u04fa"],
12
- g: ["\u0262"],
13
- h: ["\u0126", "\u0195", "\u04a2", "\u04ba", "\u04c7", "\u050a"],
14
- i: ["\u0f0f"],
15
- j: ["\u0134"],
16
- k: ["\u0138", "\u04a0", "\u04c3", "\u051e"],
17
- l: ["\u0139"],
18
- m: ["\u028d", "\u04cd", "\u04ce", "\u0520", "\u0521", "\u0d69"],
19
- n: ["\u00d1", "\u014b", "\u019d", "\u0376", "\u03a0", "\u048a"],
20
- o: ["\u00d8", "\u00f5", "\u00f8", "\u01fe", "\u0298", "\u047a", "\u05dd", "\u06dd", "\u0e4f"],
21
- p: ["\u01f7", "\u048e"],
22
- q: ["\u09cd"],
23
- r: ["\u00ae", "\u01a6", "\u0210", "\u024c", "\u0280", "\u042f"],
24
- s: ["\u00a7", "\u03de", "\u03df", "\u03e8"],
25
- t: ["\u0141", "\u0166", "\u0373"],
26
- u: ["\u01b1", "\u054d"],
27
- v: ["\u05d8"],
28
- w: ["\u0428", "\u0460", "\u047c", "\u0d70"],
29
- x: ["\u04b2", "\u04fe", "\u04fc", "\u04fd"],
30
- y: ["\u00a5", "\u04b0", "\u04cb"],
31
- z: ["\u01b5", "\u0240"]
32
- }
33
- text.forEach(function(c){
6
+ a: ['\u0040', '\u0104', '\u023a', '\u0245', '\u0394', '\u039b', '\u0414'],
7
+ b: ['\u00df', '\u0181', '\u0243', '\u026e', '\u03b2', '\u0e3f'],
8
+ c: ['\u00a9', '\u023b', '\u03fe'],
9
+ d: ['\u00d0', '\u018a', '\u0500', '\u0501', '\u0502', '\u0503'],
10
+ e: ['\u00cb', '\u0115', '\u018e', '\u0258', '\u03a3', '\u03be', '\u04bc',
11
+ '\u0a6c'],
12
+ f: ['\u04fa'],
13
+ g: ['\u0262'],
14
+ h: ['\u0126', '\u0195', '\u04a2', '\u04ba', '\u04c7', '\u050a'],
15
+ i: ['\u0f0f'],
16
+ j: ['\u0134'],
17
+ k: ['\u0138', '\u04a0', '\u04c3', '\u051e'],
18
+ l: ['\u0139'],
19
+ m: ['\u028d', '\u04cd', '\u04ce', '\u0520', '\u0521', '\u0d69'],
20
+ n: ['\u00d1', '\u014b', '\u019d', '\u0376', '\u03a0', '\u048a'],
21
+ o: ['\u00d8', '\u00f5', '\u00f8', '\u01fe', '\u0298', '\u047a', '\u05dd',
22
+ '\u06dd', '\u0e4f'],
23
+ p: ['\u01f7', '\u048e'],
24
+ q: ['\u09cd'],
25
+ r: ['\u00ae', '\u01a6', '\u0210', '\u024c', '\u0280', '\u042f'],
26
+ s: ['\u00a7', '\u03de', '\u03df', '\u03e8'],
27
+ t: ['\u0141', '\u0166', '\u0373'],
28
+ u: ['\u01b1', '\u054d'],
29
+ v: ['\u05d8'],
30
+ w: ['\u0428', '\u0460', '\u047c', '\u0d70'],
31
+ x: ['\u04b2', '\u04fe', '\u04fc', '\u04fd'],
32
+ y: ['\u00a5', '\u04b0', '\u04cb'],
33
+ z: ['\u01b5', '\u0240'],
34
+ };
35
+ text.forEach(function(c) {
34
36
  c = c.toLowerCase();
35
- var chars = trap[c] || [" "];
37
+ var chars = trap[c] || [' '];
36
38
  var rand = Math.floor(Math.random() * chars.length);
37
- if (typeof trap[c] !== "undefined") {
39
+ if (typeof trap[c] !== 'undefined') {
38
40
  result += trap[c][rand];
39
41
  } else {
40
42
  result += c;
41
43
  }
42
44
  });
43
45
  return result;
44
-
45
- }
46
+ };