New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

colorful

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

colorful - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

.travis.yml

8

index.js

@@ -1,4 +0,4 @@

exports.color = require('./lib/color')
exports.colorful = exports.color.colorful
exports.program = require('./lib/program')
exports.Logging = require('./lib/logging')
exports.color = require('./lib/color');
exports.colorful = exports.color.colorful;
exports.program = require('./lib/program');
exports.Logging = require('./lib/logging');
/*
* Color supports in terminal
* @author: Hsiaoming Yang <lepture@me.com>
*
*
* Thanks to: https://github.com/lepture/terminal

@@ -10,3 +10,3 @@ *

//var tty = require('tty')
var codes = {}
var codes = {};

@@ -19,9 +19,9 @@ function isColorSupported() {

var term = process.env['TERM'].toLowerCase()
var term = process.env.TERM.toLowerCase();
if (term.indexOf('color') != -1) return true;
return term === 'xterm' || term === 'linux'
return term === 'xterm' || term === 'linux';
}
function esc(code) {
return '\x1b[' + code + 'm'
return '\x1b[' + code + 'm';
}

@@ -31,9 +31,9 @@

if (!isColorSupported()) {
return text
return text;
}
var code = codes[name]
var code = codes[name];
if (!code) {
return text
return text;
}
return code[0] + text + code[1]
return code[0] + text + code[1];
}

@@ -44,4 +44,4 @@

exports[name] = function(text) {
return colorize(name, text)
}
return colorize(name, text);
};
}

@@ -56,7 +56,7 @@

strike: [9, 29]
}
};
for (var name in styles) {
var code = styles[name]
codes[name] = [esc(code[0]), esc(code[1])]
var code = styles[name];
codes[name] = [esc(code[0]), esc(code[1])];
}

@@ -67,15 +67,15 @@

'magenta', 'cyan', 'white'
]
];
for (var i = 0; i < colors.length; i++) {
codes[colors[i]] = [esc(i + 30), esc(39)]
codes[colors[i] + '_bg'] = [esc(i + 40), esc(49)]
codes[colors[i]] = [esc(i + 30), esc(39)];
codes[colors[i] + '_bg'] = [esc(i + 40), esc(49)];
}
codes['gray'] = codes['grey'] = [esc(90), esc(39)]
codes['gray_bg'] = codes['grey_bg'] = [esc(40), esc(49)]
codes.gray = codes.grey = [esc(90), esc(39)];
codes.gray_bg = codes.grey_bg = [esc(40), esc(49)];
for (var name in codes) {
// this is exports
createColorFunc(name)
createColorFunc(name);
}

@@ -87,24 +87,26 @@

Object.defineProperty(String.prototype, 'to', {
get: function() { return new To(this.valueOf()) }
})
get: function() { return new To(this.valueOf()); }
});
function To(obj) {
this.string = obj
this.color = obj
}
var To = function(obj) {
this.string = obj;
this.color = obj;
};
var stylish = function(style) {
Object.defineProperty(To.prototype, style, {
get: function() {
this.color = colorize(style, this.color);
return this;
}
});
};
for (var style in codes) {
(function(style) {
Object.defineProperty(To.prototype, style, {
get: function() {
this.color = colorize(style, this.color)
return this
}
})
})(style)
stylish(style);
}
}
};
Object.defineProperty(exports, 'isSupported', {
get: isColorSupported
})
});
/*
* Nested color logging support for terminal
* @author: Hsiaoming Yang <lepture@me.com>
*
*
* Thanks to: https://github.com/lepture/terminal

@@ -9,7 +9,7 @@ *

var util = require('util')
var os = require('os')
var EventEmitter = require('events').EventEmitter
var color = require('./color')
var count = 0
var util = require('util');
var os = require('os');
var EventEmitter = require('events').EventEmitter;
var color = require('./color');
var count = 0;

@@ -22,3 +22,3 @@ var levels = {

'log': 50
}
};

@@ -29,4 +29,4 @@ var colors = {

warn: color.yellow,
error:color.red
}
error: color.red
};
var icons = {

@@ -36,100 +36,103 @@ logIcon: color.cyan('➠ '),

endIcon: color.cyan('➥ ')
}
};
function log(context, level, args) {
if (levels[context.level] > levels[level]) return
if (levels[context.level] > levels[level]) return;
var text = ''
var stream = process.stdout
text += Array(count + 1).join(' ')
var text = '';
var stream = process.stdout;
text += Array(count + 1).join(' ');
if (count) {
text += icons.logIcon
text += icons.logIcon;
}
if (level === 'warn') {
text += color.yellow_bg(' WARN ') + ' '
text += color.yellow_bg(' WARN ') + ' ';
} else if (level === 'error') {
text += color.red_bg(' ERROR ') + ' '
stream = process.stderr
text += color.red_bg(' ERROR ') + ' ';
stream = process.stderr;
}
var colorize = colors[level]
var colorize = colors[level];
if (colorize) {
text += colorize(util.format.apply(context, args)) + os.EOL
text += colorize(util.format.apply(context, args)) + os.EOL;
} else {
text += util.format.apply(context, args) + os.EOL
text += util.format.apply(context, args) + os.EOL;
}
stream.write(text)
stream.write(text);
}
function Logging(level) {
this.level = level || 'info'
this.level = level || 'info';
}
Logging.prototype.__proto__ = EventEmitter.prototype
Logging.prototype.__proto__ = EventEmitter.prototype;
Logging.prototype.start = function() {
if (levels[this.level] > 25) return;
var text = Array(count + 1).join(' ')
text += icons.startIcon
text += color.bold(util.format.apply(this, arguments)) + os.EOL
process.stdout.write(text)
count += 1
this.emit('logging-start')
}
var text = Array(count + 1).join(' ');
text += icons.startIcon;
text += color.bold(util.format.apply(this, arguments)) + os.EOL;
process.stdout.write(text);
count += 1;
this.emit('logging-start');
};
Logging.prototype.end = function() {
if (levels[this.level] > 25) return;
var text = ''
text += Array(count + 1).join(' ')
var text = '';
text += Array(count + 1).join(' ');
if (count) {
text += icons.endIcon
text += icons.endIcon;
}
text += util.format.apply(this, arguments) + os.EOL
process.stdout.write(text)
count -= 1
this.emit('logging-end')
}
text += util.format.apply(this, arguments) + os.EOL;
process.stdout.write(text);
count -= 1;
this.emit('logging-end');
};
Logging.prototype.log = function() {
log(this, 'log', arguments)
}
log(this, 'log', arguments);
};
Logging.prototype.debug = function() {
log(this, 'debug', arguments)
}
log(this, 'debug', arguments);
};
Logging.prototype.info = function() {
log(this, 'info', arguments)
}
log(this, 'info', arguments);
};
Logging.prototype.warn = function() {
log(this, 'warn', arguments)
this.emit('logging-warn')
}
log(this, 'warn', arguments);
this.emit('logging-warn');
};
Logging.prototype.error = function() {
log(this, 'error', arguments)
this.emit('logging-error')
}
log(this, 'error', arguments);
this.emit('logging-error');
};
Logging.prototype.config = function(obj) {
if (obj.verbose) {
this.level = 'debug'
this.level = 'debug';
}
if (obj.quiet) {
this.level = 'warn'
this.level = 'warn';
}
if (obj.level) {
this.level = obj.level
this.level = obj.level;
}
if (obj in colors) {
this.level = obj
this.level = obj;
}
var key;
var stylish = function(key) {
colors[key] = obj.colors[key];
};
if (obj.colors) {
for (var key in obj.colors) {
(function(key) {
colors[key] = obj.colors[key]
})(key)
for (key in obj.colors) {
stylish(key);
}
}
var iconit = function(key) {
icons[key] = obj.icons[key];
};
if (obj.icons) {
for (var key in obj.icons) {
(function(key) {
icons[key] = obj.icons[key]
})(key)
for (key in obj.icons) {
iconit(key);
}
}
}
};
module.exports = Logging
module.exports = Logging;

@@ -7,3 +7,3 @@ /*

var color = require('./color')
var color = require('./color');

@@ -13,67 +13,67 @@

if (!(this instanceof Command)) {
return new Command(name, executable, description)
return new Command(name, executable, description);
}
if (typeof name === 'object') {
var obj = name
this.name = obj.name
this.executable = obj.executable || obj.name
this.description = obj.description
this.version = obj.version
this.group = obj.group
this.color = obj.color
return this
var obj = name;
this.name = obj.name;
this.executable = obj.executable || obj.name;
this.description = obj.description;
this.version = obj.version;
this.group = obj.group;
this.color = obj.color;
return this;
}
this.name = name
this.name = name;
if (!description) {
description = executable
executable = name
description = executable;
executable = name;
}
this.executable = executable
this.description = description
this.version = undefined
this.group = undefined
this.color = undefined
return this
this.executable = executable;
this.description = description;
this.version = undefined;
this.group = undefined;
this.color = undefined;
return this;
}
Command.prototype.executable = function(executable) {
this.executable = executable
}
this.executable = executable;
};
Command.prototype.description = function(description) {
this.description = description
}
this.description = description;
};
exports.Command = Command
exports.Command = Command;
exports.printHelp = function(cmd) {
var colorfunc = null
var colorfunc = null;
if (typeof cmd.color === 'string') {
colorfunc = color[cmd.color]
colorfunc = color[cmd.color];
} else if (typeof cmd.color === 'function') {
colorfunc = cmd.color
colorfunc = cmd.color;
}
var name = cmd.name
var name = cmd.name;
if (colorfunc) {
var name = colorfunc(name)
name = colorfunc(name);
}
var text = ' ' + pad(name, 15, cmd.name.length)
var text = ' ' + pad(name, 15, cmd.name.length);
if (cmd.description.length > 60) {
text += cmd.description.slice(0, 58)
text += cmd.description.slice(0, 58);
if (cmd.description.slice(58, 59) !== ' ') {
text += '-'
text += '-';
}
text += '\n'
text += Array(21).join(' ')
text += cmd.description.slice(58)
text += '\n';
text += Array(21).join(' ');
text += cmd.description.slice(58);
} else {
text += cmd.description
text += cmd.description;
}
console.log(text)
}
console.log(text);
};
function pad(str, width, strWidth) {
var len = Math.max(0, width - (strWidth || str.length))
return str + Array(len + 1).join(' ')
var len = Math.max(0, width - (strWidth || str.length));
return str + Array(len + 1).join(' ');
}
{
"name": "colorful",
"version": "1.0.0",
"version": "1.0.1",
"description": "colorful if a terminal tool for color, logging and command",

@@ -21,2 +21,3 @@ "keywords": [

"devDependencies": {
"jshint": "*",
"mocha": "*",

@@ -26,4 +27,4 @@ "should": "*"

"scripts": {
"test": "./node_modules/.bin/mocha --reporter spec"
"test": "make test"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc