summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/colors/lib/colors.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/colors/lib/colors.js')
-rw-r--r--deps/npm/node_modules/colors/lib/colors.js122
1 files changed, 55 insertions, 67 deletions
diff --git a/deps/npm/node_modules/colors/lib/colors.js b/deps/npm/node_modules/colors/lib/colors.js
index bbc5ac1262..823e3ddd0d 100644
--- a/deps/npm/node_modules/colors/lib/colors.js
+++ b/deps/npm/node_modules/colors/lib/colors.js
@@ -33,45 +33,35 @@ module['exports'] = colors;
colors.themes = {};
-var util = require('util');
var ansiStyles = colors.styles = require('./styles');
var defineProps = Object.defineProperties;
-var newLineRegex = new RegExp(/[\r\n]+/g);
-colors.supportsColor = require('./system/supports-colors').supportsColor;
+colors.supportsColor = require('./system/supports-colors');
-if (typeof colors.enabled === 'undefined') {
- colors.enabled = colors.supportsColor() !== false;
+if (typeof colors.enabled === "undefined") {
+ colors.enabled = colors.supportsColor;
}
-colors.enable = function() {
- colors.enabled = true;
+colors.stripColors = colors.strip = function(str){
+ return ("" + str).replace(/\x1B\[\d+m/g, '');
};
-colors.disable = function() {
- colors.enabled = false;
-};
-
-colors.stripColors = colors.strip = function(str) {
- return ('' + str).replace(/\x1B\[\d+m/g, '');
-};
-// eslint-disable-next-line no-unused-vars
-var stylize = colors.stylize = function stylize(str, style) {
+var stylize = colors.stylize = function stylize (str, style) {
if (!colors.enabled) {
return str+'';
}
return ansiStyles[style].open + str + ansiStyles[style].close;
-};
+}
var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
-var escapeStringRegexp = function(str) {
+var escapeStringRegexp = function (str) {
if (typeof str !== 'string') {
throw new TypeError('Expected a string');
}
- return str.replace(matchOperatorsRe, '\\$&');
-};
+ return str.replace(matchOperatorsRe, '\\$&');
+}
function build(_styles) {
var builder = function builder() {
@@ -84,16 +74,15 @@ function build(_styles) {
return builder;
}
-var styles = (function() {
+var styles = (function () {
var ret = {};
ansiStyles.grey = ansiStyles.gray;
- Object.keys(ansiStyles).forEach(function(key) {
- ansiStyles[key].closeRe =
- new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
+ Object.keys(ansiStyles).forEach(function (key) {
+ ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
ret[key] = {
- get: function() {
+ get: function () {
return build(this._styles.concat(key));
- },
+ }
};
});
return ret;
@@ -102,79 +91,78 @@ var styles = (function() {
var proto = defineProps(function colors() {}, styles);
function applyStyle() {
- var args = Array.prototype.slice.call(arguments);
-
- var str = args.map(function(arg) {
- if (arg !== undefined && arg.constructor === String) {
- return arg;
- } else {
- return util.inspect(arg);
+ var args = arguments;
+ var argsLen = args.length;
+ var str = argsLen !== 0 && String(arguments[0]);
+ if (argsLen > 1) {
+ for (var a = 1; a < argsLen; a++) {
+ str += ' ' + args[a];
}
- }).join(' ');
+ }
if (!colors.enabled || !str) {
return str;
}
- var newLinesPresent = str.indexOf('\n') != -1;
-
var nestedStyles = this._styles;
var i = nestedStyles.length;
while (i--) {
var code = ansiStyles[nestedStyles[i]];
str = code.open + str.replace(code.closeRe, code.open) + code.close;
- if (newLinesPresent) {
- str = str.replace(newLineRegex, code.close + '\n' + code.open);
- }
}
return str;
}
-colors.setTheme = function(theme) {
- if (typeof theme === 'string') {
- console.log('colors.setTheme now only accepts an object, not a string. ' +
- 'If you are trying to set a theme from a file, it is now your (the ' +
- 'caller\'s) responsibility to require the file. The old syntax ' +
- 'looked like colors.setTheme(__dirname + ' +
- '\'/../themes/generic-logging.js\'); The new syntax looks like '+
- 'colors.setTheme(require(__dirname + ' +
- '\'/../themes/generic-logging.js\'));');
- return;
- }
+function applyTheme (theme) {
for (var style in theme) {
- (function(style) {
- colors[style] = function(str) {
- if (typeof theme[style] === 'object') {
+ (function(style){
+ colors[style] = function(str){
+ if (typeof theme[style] === 'object'){
var out = str;
- for (var i in theme[style]) {
+ for (var i in theme[style]){
out = colors[theme[style][i]](out);
}
return out;
}
return colors[theme[style]](str);
};
- })(style);
+ })(style)
+ }
+}
+
+colors.setTheme = function (theme) {
+ if (typeof theme === 'string') {
+ try {
+ colors.themes[theme] = require(theme);
+ applyTheme(colors.themes[theme]);
+ return colors.themes[theme];
+ } catch (err) {
+ console.log(err);
+ return err;
+ }
+ } else {
+ applyTheme(theme);
}
};
function init() {
var ret = {};
- Object.keys(styles).forEach(function(name) {
+ Object.keys(styles).forEach(function (name) {
ret[name] = {
- get: function() {
+ get: function () {
return build([name]);
- },
+ }
};
});
return ret;
}
-var sequencer = function sequencer(map, str) {
- var exploded = str.split('');
+var sequencer = function sequencer (map, str) {
+ var exploded = str.split(""), i = 0;
exploded = exploded.map(map);
- return exploded.join('');
+ return exploded.join("");
};
// custom formatter methods
@@ -186,14 +174,14 @@ colors.maps = {};
colors.maps.america = require('./maps/america');
colors.maps.zebra = require('./maps/zebra');
colors.maps.rainbow = require('./maps/rainbow');
-colors.maps.random = require('./maps/random');
+colors.maps.random = require('./maps/random')
for (var map in colors.maps) {
- (function(map) {
- colors[map] = function(str) {
+ (function(map){
+ colors[map] = function (str) {
return sequencer(colors.maps[map], str);
- };
- })(map);
+ }
+ })(map)
}
-defineProps(colors, init());
+defineProps(colors, init()); \ No newline at end of file