console-hue
Advanced tools
Comparing version 1.0.0 to 1.0.1
const shouldStringify = ['Object', 'Array'] | ||
const msgTypes = require('./msgTypes')() | ||
function getStr (msg) { | ||
return shouldStringify.includes(msg.constructor.name) | ||
? JSON.stringify(msg) | ||
: msg | ||
function getStr (msg, original = false) { | ||
if (!msg || original) { | ||
return msg | ||
} else if (shouldStringify.includes(msg.constructor.name)) { | ||
return JSON.stringify(msg) | ||
} | ||
return msg | ||
} | ||
module.exports = function (type, msg) { | ||
return `${msgTypes[type]}${getStr(msg)}${msgTypes['log']}` | ||
module.exports = function (type, msg, original) { | ||
return `${msgTypes[type]}${getStr(msg, original)}${msgTypes['log']}` | ||
} |
@@ -27,1 +27,6 @@ const getColorMsg = require('./colormsg.js') | ||
}) | ||
test('Testing undefined message', () => { | ||
const res = getColorMsg('log') | ||
expect(res.constructor.name).toBe('String') | ||
}) |
@@ -7,4 +7,4 @@ const {log} = require('console') | ||
function logMsg (type) { | ||
return function (msg) { | ||
log(getColorMsg(type, msg)) | ||
return function (msg, original) { | ||
log(getColorMsg(type, msg, original)) | ||
} | ||
@@ -11,0 +11,0 @@ } |
{ | ||
"name": "console-hue", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Description ", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# console-hue | ||
This tiny module is basically an improved version of the native `console.log`, adding color support for different type of messages and a "Stringify" functionality by default for `Objects` and `Arrays`. | ||
This tiny module is basically an improved version of the native `console.log`, adding colour support for different type of messages and a "Stringify" functionality by default for `Objects` and `Arrays`. | ||
@@ -32,3 +32,3 @@ ## Install | ||
And then you can use `consoleh` with any of the previous methods to get a colorful reply in the console: | ||
And then you can use `consoleh` with any of the previous methods to get a colourful reply in the console: | ||
@@ -40,3 +40,5 @@ ```js | ||
consoleh.success('This message should be green') | ||
// Red output | ||
consoleh.error('This message should be red') | ||
// Yellow output | ||
consoleh.warning('This message should be yellow') | ||
@@ -46,8 +48,20 @@ | ||
As described before the module will attempt to "Stringify" the Arrays and Objects passed in the message sent to the module. | ||
As described before the module will attempt to "Stringify" the Arrays and Objects passed in the message sent to the module. You can override this behaviour by passing `true` as the second parameter: | ||
```js | ||
### License | ||
> const consoleh = require('console-hue') | ||
// With default Stringigy behaviour | ||
consoleh.log({fn: function(msg) {console.log(msg)}}) | ||
{} | ||
// Getting the original msg without Stringigy | ||
consoleh.log({fn: function(msg) {console.log(msg)}}, true) | ||
[object Object] | ||
``` | ||
### License | ||
Copyright © 2019, [Juan Convers](https://juanconvers.com). | ||
Released under the [MIT License](LICENSE). |
65
65
5211
7