Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chip

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chip - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

97

lib/console.js

@@ -1,18 +0,50 @@

require('colors');
/**
* The "console" logger writes to stdout in color.
*/
module.exports = function createConsoleLogger() {
module.exports = function() {
// TODO: Determine whether this works on more than just Mac OS.
var bash = '\u001b[39m';
var magenta = '\u001b[35m';
var cyan = '\u001b[36m';
var grey = '\u001b[90m';
var green = '\u001b[32m';
var red = '\u001b[31m';
var yellow = '\u001b[33m';
var prefixes = {
trace: '\u271A '.cyan,
debug: '\u2756 '.magenta,
log: '\u279C '.grey,
info: '\u2714 '.green,
warn: '\u2731 '.yellow,
error: '\u2716 '.red
debug: magenta + '\u2756 ' + bash,
trace: cyan + '\u271A ' + bash,
log: grey + '\u279C ' + bash,
info: green + '\u2714 ' + bash,
error: red + '\u2716 ' + bash,
warn: yellow + '\u2731 ' + bash
};
var breakIndent = '\n ';
var specialPattern = /(\.\?\*\+\(\)\[\]\{\}\\)/g;
var escCwd = process.cwd().replace(specialPattern, '\\$1') + '/';
var stackPattern = new RegExp(
'( at [^\n]*)' + escCwd + '([^\\):\n]*?):([\\d]+):([\\d]*)([^\n]*)',
'g'
);
var format = function (string, prefix) {
return prefix + string.replace(/\n/g, breakIndent);
var format = function (string, prefix, type) {
if (type == 'error') {
string = red + string + bash;
string = string.replace(
stackPattern,
function (match, start, path, line, char, end) {
return start + bash + path + red + ':' +
bash + line + red + ':' + bash + char + red + end;
}
);
}
else if (type == 'warn') {
string = yellow + string + bash;
}
else {
string = string.replace(/\n/, breakIndent);
}
return prefix + string;
};

@@ -29,3 +61,3 @@

logger.setLevel = function setLevel(level) {
var numbers = {trace: 0, debug: 1, log: 2, info: 3, warn: 4, error: 5};
var numbers = {debug: 0, trace: 1, log: 2, info: 3, warn: 4, error: 5};
var number = numbers[level];

@@ -40,4 +72,4 @@ if (typeof number == 'undefined') {

logger.level = level;
logger.trace = number < 1 ? trace : meh;
logger.debug = number < 2 ? debug : meh;
logger.debug = number < 1 ? debug : meh;
logger.trace = number < 2 ? trace : meh;
logger.log = number < 3 ? log : meh;

@@ -58,6 +90,19 @@ logger.info = number < 4 ? info : meh;

logger.setFormat = function setFormat(value) {
format = value;
logger.setFormat = function setFormat(value, type) {
if (type) {
format[type] = value;
}
else {
format = value;
format.debug = value;
format.trace = value;
format.log = value;
format.info = value;
format.warn = value;
format.error = value;
}
};
logger.setFormat(format);
logger.setJsonSpace = function setJsonSpace(value) {

@@ -67,16 +112,16 @@ jsonSpace = value;

var trace = logger.trace = function trace(message) {
var debug = logger.debug = function error(message) {
if (typeof message != 'string') {
message = JSON.stringify(message, null, jsonSpace);
}
var prefix = prefixes.trace;
process.stdout.write(format(message, prefix) + '\n');
var prefix = prefixes.debug;
process.stdout.write(format.debug(message, prefix, 'debug') + '\n');
};
var debug = logger.debug = function error(message) {
var trace = logger.trace = function trace(message) {
if (typeof message != 'string') {
message = JSON.stringify(message, null, jsonSpace);
}
var prefix = prefixes.debug;
process.stdout.write(format(message, prefix) + '\n');
var prefix = prefixes.trace;
process.stdout.write(format.trace(message, prefix, 'trace') + '\n');
};

@@ -89,3 +134,3 @@

var prefix = prefixes.log;
process.stdout.write(format(message, prefix) + '\n');
process.stdout.write(format.log(message, prefix, 'log') + '\n');
};

@@ -98,3 +143,3 @@

var prefix = prefixes.info;
process.stdout.write(format(message, prefix) + '\n');
process.stdout.write(format.info(message, prefix, 'info') + '\n');
};

@@ -107,3 +152,3 @@

var prefix = prefixes.warn;
process.stdout.write(format(message, prefix).yellow + '\n');
process.stdout.write(format.warn(message, prefix, 'warn') + '\n');
};

@@ -116,6 +161,6 @@

var prefix = prefixes.error;
process.stdout.write(format(message, prefix).red + '\n');
process.stdout.write(format.error(message, prefix, 'error') + '\n');
};
return logger;
}
}

@@ -15,3 +15,3 @@ {

],
"version": "0.0.3",
"version": "0.0.4",
"main": "chip.js",

@@ -49,5 +49,3 @@ "homepage": "http://github.com/zerious/chip",

},
"dependencies": {
"colors": "0.6.2"
},
"dependencies": {},
"devDependencies": {

@@ -54,0 +52,0 @@ "zeriousify": "0.1.3",

@@ -30,4 +30,4 @@ # Chip

log.debug('This will be preceded by a magenta diamond thingy.');
log.trace('This will be preceded by a cyan plus.');
log.debug('This will be preceded by a magenta diamond thingy.');
log.log('This will be preceded by a grey arrow, as above.');

@@ -41,3 +41,3 @@ log.info('This will be preceded by a green check mark.');

#### log.setFormat
#### log.setFormat(function callback[, string type])

@@ -47,3 +47,3 @@ Customize the message format.

var log = require('chip')();
log.setFormat(function (message, prefix) {
log.setFormat(function (message, prefix, type) {
return prefix + message + '!';

@@ -53,4 +53,7 @@ });

#### log.setLevel
If you specify the optional `type` parameter, it will only change the formatter
for that type.
#### log.setLevel(string level)
Change the level of log that is shown (default: `log`).

@@ -63,6 +66,6 @@ ```javascript

Setting to a level from this list will enable logs of that level and all
of the levels after it: `trace`, `debug`, `log`, `info`, `warn`, `error`.
of the levels after it: `debug`, `trace`, `log`, `info`, `warn`, `error`.
Setting the level to `nothing` will stop all logs.
#### log.setPrefixes
#### log.setPrefixes(object prefixes)

@@ -75,4 +78,4 @@ Customize prefixes for the console log messages.

log.setPrefixes({
debug: 'DEBUG '.magenta,
trace: 'TRACE '.cyan,
debug: 'DEBUG '.magenta,
log: 'LOG '.grey,

@@ -88,3 +91,3 @@ info: 'INFO '.green,

#### log.setJsonSpace
#### log.setJsonSpace(string whitespace)

@@ -101,2 +104,2 @@ Customize the spacing that JSON.stringify uses.

Chip will soon support more transports than `stdout`. Hey, it's a start.
Chip will soon support more transports than `stdout`. Hey, it's a start.
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