Huge News!Announcing our $40M Series B led by Abstract Ventures.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.2 to 1.1.0

nico.json

8

index.js

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

exports.color = require('./lib/color');
exports.colorful = exports.color.colorful;
var color = require('./lib/color');
exports = module.exports = color;
exports.program = require('./lib/program');
exports.Logging = require('./lib/logging').Logging;
var logging = require('./lib/logging');
exports.logging = logging;
exports.Logging = logging.Logging;

@@ -44,9 +44,2 @@ /*

function createColorFunc(name) {
// exports here
exports[name] = function(text) {
return colorize(name, text);
};
}
var styles = {

@@ -79,7 +72,33 @@ bold: [1, 22],

for (var name in codes) {
// this is exports
createColorFunc(name);
function Color(obj) {
this.string = obj;
this.color = obj;
}
Color.prototype.valueOf = function() {
return this.color;
};
exports.color = {};
Object.keys(codes).forEach(function(style) {
Object.defineProperty(Color.prototype, style, {
get: function() {
this.color = colorize(style, this.color);
return this;
}
});
exports.color[style] = function(text) {
return colorize(style, text);
};
});
Object.defineProperty(Color.prototype, 'style', {
get: function() {
return this.color;
}
});
exports.paint = function(text) {
return new Color(text);
};
exports.colorful = function() {

@@ -89,22 +108,4 @@ if (String.prototype.to) return;

Object.defineProperty(String.prototype, 'to', {
get: function() { return new To(this.valueOf()); }
get: function() { return new Color(this.valueOf()); }
});
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) {
stylish(style);
}
};

@@ -111,0 +112,0 @@

@@ -13,5 +13,6 @@ /*

var color = require('./color');
var paint = color.paint;
var count = 0;
var levels = {
var _levels = {
'debug': 10,

@@ -24,16 +25,16 @@ 'info': 20,

var colors = {
debug: color.grey,
info: color.green,
warn: color.yellow,
error: color.red
function colorize(name, text) {
var func;
if (typeof name === 'string') {
func = color.color[name]
} else if (typeof name === 'function') {
func = name;
}
if (!func) return text;
return func(text);
};
var icons = {
logIcon: color.cyan('➠ '),
startIcon: color.bold(color.magenta('⚑ ')),
endIcon: color.cyan('➥ ')
};
function log(context, level, args) {
if (levels[context.level] > levels[level]) return;
if (_levels[context.level] > _levels[level]) return;

@@ -44,16 +45,12 @@ var text = '';

if (count) {
text += icons.logIcon;
text += context.icons.logIcon;
}
if (level === 'warn') {
text += color.yellow_bg(' WARN ') + ' ';
text += paint(' WARN ').yellow_bg.color + ' ';
} else if (level === 'error') {
text += color.red_bg(' ERROR ') + ' ';
text += paint(' ERROR ').red_bg.color + ' ';
stream = process.stderr;
}
var colorize = colors[level];
if (colorize) {
text += colorize(util.format.apply(context, args)) + os.EOL;
} else {
text += util.format.apply(context, args) + os.EOL;
}
var name = context.colors[level];
text += colorize(name, util.format.apply(context, args)) + os.EOL;
stream.write(text);

@@ -66,71 +63,77 @@ }

Logging.prototype.__proto__ = EventEmitter.prototype;
Logging.prototype.icons = {
logIcon: paint('➠ ').cyan.color,
startIcon: paint('⚑ ').bold.magenta.color,
endIcon: paint('➥ ').cyan.color
};
Logging.prototype.colors = {
debug: 'grey',
info: 'green',
warn: 'yellow',
error: 'red'
};
Logging.prototype.start = function() {
if (levels[this.level] > 25) return;
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 += this.icons.startIcon;
text += paint(util.format.apply(this, arguments)).bold.color + 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(' ');
if (count) {
text += icons.endIcon;
}
text += util.format.apply(this, arguments) + os.EOL;
process.stdout.write(text);
count -= 1;
this.emit('logging-end');
if (_levels[this.level] > 25) return;
var text = '';
text += Array(count + 1).join(' ');
if (count) {
text += this.icons.endIcon;
}
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';
}
if (obj.quiet) {
this.level = 'warn';
}
if (obj.level) {
this.level = obj.level;
}
if (obj in colors) {
this.level = obj;
}
var key;
var stylish = function(key) {
colors[key] = obj.colors[key];
};
if (obj.colors) {
for (key in obj.colors) {
stylish(key);
}
}
var iconit = function(key) {
icons[key] = obj.icons[key];
};
if (obj.icons) {
for (key in obj.icons) {
iconit(key);
}
}
var self = this;
if (obj.verbose) {
self.level = 'debug';
}
if (obj.quiet) {
self.level = 'warn';
}
if (obj.level) {
self.level = obj.level;
}
if (obj in _levels) {
self.level = obj;
}
if (obj.colors) {
Object.keys(obj.colors).forEach(function(key) {
self.colors[key] = obj.colors[key];
});
}
if (obj.icons) {
Object.keys(obj.icons).forEach(function(key) {
self.icons[key] = obj.icons[key];
});
}
};

@@ -137,0 +140,0 @@

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

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

@@ -10,0 +10,0 @@

{
"name": "colorful",
"version": "1.0.2",
"version": "1.1.0",
"description": "colorful if a terminal tool for color, logging and command",

@@ -5,0 +5,0 @@ "keywords": [

@@ -1,9 +0,15 @@

# Colorful support for terminal
# Colorful
It's not just color, it's everything colorful in terminal.
---------------------
## Color
# Color
color as function:
Color in terminal and only terminal.
## Programmer
As a programmer, you think they are functions:
```javascript

@@ -13,38 +19,79 @@ var color = require('colorful').color

color.underline('hello')
color.red(color.underline('hello'))
```
color as human:
## Human
As a human, you think you are a painter:
```javascript
var paint = require('colorful').paint
paint('hello').red.color
paint('hello').bold.underline.red.color
```
**WTF**, is bold, underline a color? If you don't like the idea, try:
```javascript
paint('hello').bold.underline.red.style
```
## Alien
As an alien, you are from outer space, you think it should be:
```javascript
require('colorful').colorful()
'hello'.to.red.color
'hello'.to.underline.bold.red.color
'hello'.to.underline.bold.red.style
```
color and style supports:
## Detective
- `black` `black_bg`
- `red` `red_bg`
- `green` `green_bg`
- `yellow` `yellow_bg`
- `blue` `blue_bg`
- `magenta` `magenta_bg`
- `cyan` `cyan_bg`
- `white` `white_bg`
- `gray` `grey` `gray_bg` `grey_bg`
- bold
- italic
- underline
- blink
- inverse
- strike
As a detective, you think we should detect if color is supported:
and detect is color supported:
```javascript
require('colorful').isSupported
```
------
# Logging
Colorful and nested logging in terminal.
[![nico](http://lab.lepture.com/nico/nico-look.png)](http://lab.lepture.com/nico/)
## Favorite
Default is my favorite, we should do nothing:
```javascript
require('colorful').color.isSupported
var logging = require('colorful').logging;
// start a nested logging
logging.start('Start Application')
logging.info('send an info message')
// start another nested logging
logging.start('Start subprocess')
logging.warn('send a warn message')
logging.end('End subprocess')
logging.error('send an error message')
logging.debug('send a debug message')
logging.end('End Application')
```
## Logging
## Config
Colorful and nested logging support.
I want to show debug message:
```javascript
logging.config('debug')
// or
logging.config({level: 'debug'})
logging.config({verbose: true})
```
## Customize
var color = require('../lib/color');
var paint = color.paint;
var should = require('should');

@@ -9,3 +10,4 @@

it('should be red hello', function() {
color.red('hello').should.equal('\x1b[31mhello\x1b[39m');
paint('hello').red.color.should.equal('\x1b[31mhello\x1b[39m');
paint('hello').red.style.should.equal('\x1b[31mhello\x1b[39m');
});

@@ -12,0 +14,0 @@ it('should be colorful string', function() {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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