colorprint
Advanced tools
Comparing version 3.0.3 to 4.0.0
@@ -9,150 +9,150 @@ /** | ||
"use strict"; | ||
'use strict' | ||
const formatMsg = require('./msg/format_msg'), | ||
decorateMsg = require('./msg/decorate_msg'), | ||
indentMsg = require('./msg/indent_msg'); | ||
const formatMsg = require('./msg/format_msg') | ||
const decorateMsg = require('./msg/decorate_msg') | ||
const indentMsg = require('./msg/indent_msg') | ||
/** @lends module:colorprint/lib~Colorprint */ | ||
function Colorprint() { | ||
let s = this; | ||
s.init.apply(s, arguments); | ||
const s = this | ||
s.init.apply(s, arguments) | ||
} | ||
Colorprint.prototype = { | ||
disabled: false, | ||
prepareMsg: function () { | ||
let s = this; | ||
let msg = formatMsg.apply(formatMsg, arguments); | ||
return [s.PREFIX, indentMsg(msg, s.indent), s.SUFFIX].join(''); | ||
}, | ||
writeToStdout: function (msg, color) { | ||
let s = this; | ||
if(s.disabled) { | ||
return; | ||
} | ||
console.log(decorateMsg(msg, color)); | ||
}, | ||
writeToStderr: function (msg, color) { | ||
console.error(decorateMsg(msg, color)); | ||
}, | ||
/** Color for notice print. */ | ||
NOTICE_COLOR: 'magenta', | ||
/** Color for info print. */ | ||
INFO_COLOR: 'green', | ||
/** Color for debug print. */ | ||
DEBUG_COLOR: '', | ||
/** Color for trace print. */ | ||
TRACE_COLOR: 'white', | ||
/** Color for warn print. */ | ||
WARN_COLOR: 'yellow', | ||
/** Color for error print. */ | ||
ERROR_COLOR: 'red', | ||
/** Color for fatal print. */ | ||
FATAL_COLOR: 'bgRed', | ||
/** Alias for module:colorprint/lib~Colorprint#notice. */ | ||
NOTICE: function () { | ||
let s = this; | ||
s.notice.apply(s, arguments); | ||
}, | ||
/** Alias for module:colorprint/lib~Colorprint#info. */ | ||
INFO: function () { | ||
let s = this; | ||
s.info.apply(s, arguments); | ||
}, | ||
/** Alias for module:colorprint/lib~Colorprint#debug. */ | ||
DEBUG: function () { | ||
let s = this; | ||
s.debug.apply(s, arguments); | ||
}, | ||
/** Alias for module:colorprint/lib~Colorprint#trace. */ | ||
TRACE: function () { | ||
let s = this; | ||
s.trace.apply(s, arguments); | ||
}, | ||
/** Alias for module:colorprint/lib~Colorprint#warn. */ | ||
WARN: function () { | ||
let s = this; | ||
s.warn.apply(s, arguments); | ||
}, | ||
/** Alias for module:colorprint/lib~Colorprint#error. */ | ||
ERROR: function () { | ||
let s = this; | ||
s.error.apply(s, arguments); | ||
}, | ||
/** Alias for module:colorprint/lib~Colorprint#fatal. */ | ||
FATAL: function () { | ||
let s = this; | ||
s.fatal.apply(s, arguments); | ||
}, | ||
/** @constructs module:colorprint/lib~Colorprint */ | ||
init: function (config) { | ||
let s = this; | ||
Object.assign(s, config); | ||
}, | ||
/** Number of indent */ | ||
indent: 0, | ||
/** Message prefix */ | ||
PREFIX: '', | ||
/** Message suffix */ | ||
SUFFIX: '', | ||
/** | ||
* Print notice message. | ||
* @param {...string} msg - Message to print. | ||
*/ | ||
notice: function (msg) { | ||
let s = this; | ||
s.writeToStdout(s.prepareMsg.apply(s, arguments), s.NOTICE_COLOR); | ||
}, | ||
/** | ||
* Print info message. | ||
* @param {...string} msg - Message to print. | ||
*/ | ||
info: function (msg) { | ||
let s = this; | ||
s.writeToStdout(s.prepareMsg.apply(s, arguments), s.INFO_COLOR); | ||
}, | ||
/** | ||
* Print debug message. | ||
* @param {...string} msg - Message to print. | ||
*/ | ||
debug: function (msg) { | ||
let s = this; | ||
s.writeToStdout(s.prepareMsg.apply(s, arguments), s.DEBUG_COLOR); | ||
}, | ||
/** | ||
* Print trace message. | ||
* @param {...string} msg - Message to print. | ||
*/ | ||
trace: function (msg) { | ||
let s = this; | ||
s.writeToStdout(s.prepareMsg.apply(s, arguments), s.TRACE_COLOR); | ||
}, | ||
/** | ||
* Print warn message. | ||
* @param {...string} msg - Message to print. | ||
*/ | ||
warn: function (msg) { | ||
let s = this; | ||
s.writeToStdout(s.prepareMsg.apply(s, arguments), s.WARN_COLOR); | ||
}, | ||
/** | ||
* Print error message. | ||
* @param {...string} msg - Message to print. | ||
*/ | ||
error: function (msg) { | ||
let s = this; | ||
s.writeToStderr(s.prepareMsg.apply(s, arguments), s.ERROR_COLOR); | ||
}, | ||
/** | ||
* Print fatal message. | ||
* @param {...string} msg - Message to print. | ||
*/ | ||
fatal: function (msg) { | ||
let s = this; | ||
s.writeToStderr(s.prepareMsg.apply(s, arguments), s.FATAL_COLOR); | ||
disabled: false, | ||
prepareMsg () { | ||
const s = this | ||
let msg = formatMsg.apply(formatMsg, arguments) | ||
return [s.PREFIX, indentMsg(msg, s.indent), s.SUFFIX].join('') | ||
}, | ||
writeToStdout (msg, color) { | ||
const s = this | ||
if(s.disabled) { | ||
return; | ||
} | ||
console.log(decorateMsg(msg, color)) | ||
}, | ||
writeToStderr (msg, color) { | ||
console.error(decorateMsg(msg, color)) | ||
}, | ||
/** Color for notice print. */ | ||
NOTICE_COLOR: 'magenta', | ||
/** Color for info print. */ | ||
INFO_COLOR: 'green', | ||
/** Color for debug print. */ | ||
DEBUG_COLOR: '', | ||
/** Color for trace print. */ | ||
TRACE_COLOR: 'white', | ||
/** Color for warn print. */ | ||
WARN_COLOR: 'yellow', | ||
/** Color for error print. */ | ||
ERROR_COLOR: 'red', | ||
/** Color for fatal print. */ | ||
FATAL_COLOR: 'bgRed', | ||
/** Alias for module:colorprint/lib~Colorprint#notice. */ | ||
NOTICE () { | ||
const s = this | ||
s.notice.apply(s, arguments) | ||
}, | ||
/** Alias for module:colorprint/lib~Colorprint#info. */ | ||
INFO () { | ||
const s = this | ||
s.info.apply(s, arguments) | ||
}, | ||
/** Alias for module:colorprint/lib~Colorprint#debug. */ | ||
DEBUG () { | ||
const s = this | ||
s.debug.apply(s, arguments) | ||
}, | ||
/** Alias for module:colorprint/lib~Colorprint#trace. */ | ||
TRACE () { | ||
const s = this | ||
s.trace.apply(s, arguments) | ||
}, | ||
/** Alias for module:colorprint/lib~Colorprint#warn. */ | ||
WARN () { | ||
const s = this | ||
s.warn.apply(s, arguments) | ||
}, | ||
/** Alias for module:colorprint/lib~Colorprint#error. */ | ||
ERROR () { | ||
const s = this | ||
s.error.apply(s, arguments) | ||
}, | ||
/** Alias for module:colorprint/lib~Colorprint#fatal. */ | ||
FATAL () { | ||
const s = this | ||
s.fatal.apply(s, arguments) | ||
}, | ||
/** @constructs module:colorprint/lib~Colorprint */ | ||
init (config) { | ||
const s = this | ||
Object.assign(s, config) | ||
}, | ||
/** Number of indent */ | ||
indent: 0, | ||
/** Message prefix */ | ||
PREFIX: '', | ||
/** Message suffix */ | ||
SUFFIX: '', | ||
/** | ||
* Print notice message. | ||
* @param {...string} msg - Message to print. | ||
*/ | ||
notice (msg) { | ||
const s = this | ||
s.writeToStdout(s.prepareMsg.apply(s, arguments), s.NOTICE_COLOR) | ||
}, | ||
/** | ||
* Print info message. | ||
* @param {...string} msg - Message to print. | ||
*/ | ||
info (msg) { | ||
const s = this | ||
s.writeToStdout(s.prepareMsg.apply(s, arguments), s.INFO_COLOR) | ||
}, | ||
/** | ||
* Print debug message. | ||
* @param {...string} msg - Message to print. | ||
*/ | ||
debug (msg) { | ||
const s = this | ||
s.writeToStdout(s.prepareMsg.apply(s, arguments), s.DEBUG_COLOR) | ||
}, | ||
/** | ||
* Print trace message. | ||
* @param {...string} msg - Message to print. | ||
*/ | ||
trace (msg) { | ||
const s = this | ||
s.writeToStdout(s.prepareMsg.apply(s, arguments), s.TRACE_COLOR) | ||
}, | ||
/** | ||
* Print warn message. | ||
* @param {...string} msg - Message to print. | ||
*/ | ||
warn (msg) { | ||
const s = this | ||
s.writeToStdout(s.prepareMsg.apply(s, arguments), s.WARN_COLOR) | ||
}, | ||
/** | ||
* Print error message. | ||
* @param {...string} msg - Message to print. | ||
*/ | ||
error (msg) { | ||
const s = this | ||
s.writeToStderr(s.prepareMsg.apply(s, arguments), s.ERROR_COLOR) | ||
}, | ||
/** | ||
* Print fatal message. | ||
* @param {...string} msg - Message to print. | ||
*/ | ||
fatal (msg) { | ||
const s = this | ||
s.writeToStderr(s.prepareMsg.apply(s, arguments), s.FATAL_COLOR) | ||
} | ||
}; | ||
module.exports = Colorprint; | ||
module.exports = Colorprint |
@@ -9,3 +9,3 @@ /** | ||
"use strict"; | ||
'use strict' | ||
@@ -15,6 +15,6 @@ const Colorprint = require('./colorprint'); | ||
/** @lends create */ | ||
function create(config) { | ||
return new Colorprint(config); | ||
function create (config) { | ||
return new Colorprint(config); | ||
} | ||
module.exports = create; |
@@ -9,16 +9,17 @@ /** | ||
"use strict"; | ||
'use strict' | ||
const create = require('./create'); | ||
const create = require('./create') | ||
/** @lends define */ | ||
function define(properties){ | ||
function Logger(config){ | ||
let s = this; | ||
Object.assign(s, config); | ||
} | ||
Logger.prototype = create(properties); | ||
return Logger; | ||
function define (properties) { | ||
function Logger (config) { | ||
const s = this | ||
Object.assign(s, config) | ||
} | ||
Logger.prototype = create(properties) | ||
return Logger | ||
} | ||
module.exports = define; | ||
module.exports = define |
/** | ||
* Print ansi-colored message to stdout/stderr. | ||
* @version 3.0.3 | ||
* @version 4.0.0 | ||
* @module colorprint | ||
@@ -11,18 +11,19 @@ * @author {@link http://okunishitaka.com|Taka Okunishi | ||
"use strict"; | ||
'use strict' | ||
const Colorprint = require('./colorprint'), | ||
pkg = require('../package.json'), | ||
cliColor = require('cli-color'), | ||
define = require('./define'), | ||
create = require('./create'); | ||
const Colorprint = require('./colorprint') | ||
const pkg = require('../package.json') | ||
const cliColor = require('cli-color') | ||
const define = require('./define') | ||
const create = require('./create') | ||
let colorprint = create(); | ||
colorprint.create = create; | ||
colorprint.define = define; | ||
colorprint.colors = cliColor; | ||
colorprint.Colorprint = Colorprint; | ||
colorprint.version = pkg.version; | ||
let colorprint = create() | ||
Object.assign(colorprint, { | ||
create, | ||
define, | ||
Colorprint, | ||
colors: cliColor, | ||
version: pkg.version, | ||
}) | ||
module.exports = colorprint; | ||
module.exports = colorprint |
@@ -11,19 +11,19 @@ /** | ||
"use strict"; | ||
'use strict' | ||
const cliColor = require('cli-color'); | ||
const cliColor = require('cli-color') | ||
/** @lends decorateMsg */ | ||
function decorateMsg(msg, color) { | ||
if (!color) { | ||
return msg; | ||
} | ||
let decorator = color && cliColor[color]; | ||
if (!decorator) { | ||
throw new Error('Unknown color: ' + color); | ||
} | ||
return decorator(msg); | ||
function decorateMsg (msg, color) { | ||
if (!color) { | ||
return msg | ||
} | ||
let decorator = color && cliColor[ color ] | ||
if (!decorator) { | ||
throw new Error('Unknown color: ' + color) | ||
} | ||
return decorator(msg) | ||
} | ||
module.exports = decorateMsg; | ||
module.exports = decorateMsg | ||
@@ -9,38 +9,37 @@ /** | ||
"use strict"; | ||
"use strict" | ||
/** @lends formatMsg */ | ||
function formatMsg(msg) { | ||
let s = this; | ||
msg = Array.prototype.slice.call(arguments, 0).map(msg => { | ||
if (typeof(msg) === 'object') { | ||
try { | ||
return JSON.stringify(msg, null, 4); | ||
} catch (e) { | ||
// Do nothing. | ||
} | ||
} | ||
return msg; | ||
}) | ||
.filter(msg => !!msg) | ||
.map(msg => String(msg)); | ||
if (!msg.length) { | ||
return ''; | ||
function formatMsg (msg) { | ||
const s = this | ||
msg = Array.prototype.slice.call(arguments, 0).map(msg => { | ||
if (typeof(msg) === 'object') { | ||
try { | ||
return JSON.stringify(msg, null, 4) | ||
} catch (e) { | ||
// Do nothing. | ||
} | ||
} | ||
let formatted = msg.shift().replace(/%(.)/g, ($0, $1) => { | ||
switch ($1) { | ||
case 's': | ||
return String(msg.shift()); | ||
case 'd': | ||
return parseInt(msg.shift()); | ||
case 'f': | ||
return parseFloat(msg.shift()); | ||
default: | ||
return $0; | ||
} | ||
}); | ||
return [formatted].concat(msg).join(' '); | ||
return msg | ||
}) | ||
.filter(msg => !!msg) | ||
.map(msg => String(msg)) | ||
if (!msg.length) { | ||
return '' | ||
} | ||
let formatted = msg.shift().replace(/%(.)/g, ($0, $1) => { | ||
switch ($1) { | ||
case 's': | ||
return String(msg.shift()) | ||
case 'd': | ||
return parseInt(msg.shift()) | ||
case 'f': | ||
return parseFloat(msg.shift()) | ||
default: | ||
return $0 | ||
} | ||
}) | ||
return [ formatted ].concat(msg).join(' ') | ||
} | ||
module.exports = formatMsg; | ||
module.exports = formatMsg |
@@ -9,18 +9,18 @@ /** | ||
"use strict"; | ||
'use strict' | ||
const os = require('os'); | ||
const os = require('os') | ||
const EOL = os.EOL, | ||
TAB = ' '; | ||
const { EOL } = os | ||
const TAB = ' ' | ||
/** @lends indentMsg */ | ||
function indentMsg(msg, depth) { | ||
let indent = ''; | ||
for (let i = 0; i < depth; i++) { | ||
indent += TAB; | ||
} | ||
return indent + msg.replace(new RegExp(EOL, 'g'), EOL + indent); | ||
function indentMsg (msg, depth) { | ||
let indent = '' | ||
for (let i = 0; i < depth; i++) { | ||
indent += TAB | ||
} | ||
return indent + msg.replace(new RegExp(EOL, 'g'), EOL + indent) | ||
} | ||
module.exports = indentMsg; | ||
module.exports = indentMsg |
{ | ||
"name": "colorprint", | ||
"version": "3.0.3", | ||
"version": "4.0.0", | ||
"description": "Print ansi-colored message to stdout/stderr.", | ||
@@ -46,4 +46,5 @@ "main": "lib", | ||
"engines": { | ||
"node": ">=4.0.0" | ||
"node": ">=6", | ||
"npm": ">=3" | ||
} | ||
} |
@@ -5,24 +5,26 @@ /** | ||
*/ | ||
"use strict"; | ||
'use strict' | ||
const bin = require.resolve('../bin/colorprint'), | ||
assert = require('assert'), | ||
childProcess = require('child_process'); | ||
const bin = require.resolve('../bin/colorprint') | ||
const assert = require('assert') | ||
const childProcess = require('child_process') | ||
describe('bin', ()=> { | ||
function _spawn(command, args) { | ||
let spawned = childProcess.spawn(command, args); | ||
spawned.stdout.pipe(process.stdout); | ||
spawned.stderr.pipe(process.stderr); | ||
} | ||
function _spawn (command, args) { | ||
let spawned = childProcess.spawn(command, args) | ||
spawned.stdout.pipe(process.stdout) | ||
spawned.stderr.pipe(process.stderr) | ||
} | ||
it('Print.', (done) => { | ||
_spawn(bin, ['notice', 'This is notice', 'from cli.']); | ||
_spawn(bin, ['info', 'This is info', 'from cli.']); | ||
_spawn(bin, ['debug', 'This is debug', 'from cli.']); | ||
_spawn(bin, ['trace', 'This is trace', 'from cli.']); | ||
_spawn(bin, ['error', 'This is error', 'from cli.']); | ||
_spawn(bin, ['fatal', 'This is fatal', 'from cli.']); | ||
done(); | ||
}); | ||
}); | ||
it('Print.', (done) => { | ||
_spawn(bin, [ 'notice', 'This is notice', 'from cli.' ]) | ||
_spawn(bin, [ 'info', 'This is info', 'from cli.' ]) | ||
_spawn(bin, [ 'debug', 'This is debug', 'from cli.' ]) | ||
_spawn(bin, [ 'trace', 'This is trace', 'from cli.' ]) | ||
_spawn(bin, [ 'error', 'This is error', 'from cli.' ]) | ||
_spawn(bin, [ 'fatal', 'This is fatal', 'from cli.' ]) | ||
done() | ||
}) | ||
}) | ||
/* global describe, it */ |
@@ -5,59 +5,59 @@ /** | ||
*/ | ||
"use strict"; | ||
'use strict' | ||
const Colorprint = require('../lib/colorprint.js'), | ||
assert = require('assert'); | ||
const Colorprint = require('../lib/colorprint.js') | ||
const assert = require('assert') | ||
describe('colorpint', () => { | ||
it('Colorprint', (done) => { | ||
let colorprint = new Colorprint({}); | ||
colorprint.notice('This is notice'); | ||
colorprint.info('This is info'); | ||
colorprint.debug('This is debug'); | ||
colorprint.trace('This is trace'); | ||
colorprint.error('This is error'); | ||
colorprint.warn('This is warn'); | ||
colorprint.fatal('This is fatal'); | ||
it('Colorprint', (done) => { | ||
let colorprint = new Colorprint({}) | ||
colorprint.notice('This is notice') | ||
colorprint.info('This is info') | ||
colorprint.debug('This is debug') | ||
colorprint.trace('This is trace') | ||
colorprint.error('This is error') | ||
colorprint.warn('This is warn') | ||
colorprint.fatal('This is fatal') | ||
colorprint.INFO('This is INFO'); | ||
colorprint.DEBUG('This is DEBUG'); | ||
colorprint.TRACE('This is TRACE'); | ||
colorprint.ERROR('This is ERROR'); | ||
colorprint.WARN('This is WARN'); | ||
colorprint.FATAL('This is FATAL'); | ||
done(); | ||
}); | ||
colorprint.INFO('This is INFO') | ||
colorprint.DEBUG('This is DEBUG') | ||
colorprint.TRACE('This is TRACE') | ||
colorprint.ERROR('This is ERROR') | ||
colorprint.WARN('This is WARN') | ||
colorprint.FATAL('This is FATAL') | ||
done() | ||
}) | ||
it('Colorprint with indent', (done) => { | ||
let colorprint = new Colorprint({ | ||
indent: 2 | ||
}) | ||
colorprint.notice('This is indented notice') | ||
colorprint.info('This is indented info') | ||
colorprint.debug('This is indented debug') | ||
colorprint.trace('This is indented trace') | ||
colorprint.error('This is indented error') | ||
colorprint.warn('This is indented warn') | ||
colorprint.fatal('This is indented fatal') | ||
it('Colorprint with indent', (done) => { | ||
let colorprint = new Colorprint({ | ||
indent: 2 | ||
}); | ||
colorprint.notice('This is indented notice'); | ||
colorprint.info('This is indented info'); | ||
colorprint.debug('This is indented debug'); | ||
colorprint.trace('This is indented trace'); | ||
colorprint.error('This is indented error'); | ||
colorprint.warn('This is indented warn'); | ||
colorprint.fatal('This is indented fatal'); | ||
colorprint.INFO('This is indented INFO') | ||
colorprint.DEBUG('This is indented DEBUG') | ||
colorprint.TRACE('This is indented TRACE') | ||
colorprint.WARN('This is indented WARN') | ||
colorprint.ERROR('This is indented ERROR') | ||
colorprint.FATAL('This is indented FATAL') | ||
done() | ||
}) | ||
colorprint.INFO('This is indented INFO'); | ||
colorprint.DEBUG('This is indented DEBUG'); | ||
colorprint.TRACE('This is indented TRACE'); | ||
colorprint.WARN('This is indented WARN'); | ||
colorprint.ERROR('This is indented ERROR'); | ||
colorprint.FATAL('This is indented FATAL'); | ||
done(); | ||
}); | ||
it('Customize color print.', (done) => { | ||
let colorprint = new Colorprint({ | ||
PREFIX: 'Yeah!', | ||
SUFFIX: 'That\'s it!', | ||
INFO_COLOR: 'blue' | ||
}) | ||
colorprint.info('This will be blue with prefix.') | ||
done() | ||
}) | ||
}) | ||
it('Customize color print.', (done) => { | ||
let colorprint = new Colorprint({ | ||
PREFIX: 'Yeah!', | ||
SUFFIX: 'That\'s it!', | ||
INFO_COLOR: 'blue' | ||
}); | ||
colorprint.info('This will be blue with prefix.'); | ||
done(); | ||
}); | ||
}); | ||
/* global describe, it */ |
@@ -5,14 +5,14 @@ /** | ||
*/ | ||
"use strict"; | ||
'use strict' | ||
const create = require('../lib/create.js'), | ||
assert = require('assert'); | ||
const create = require('../lib/create.js') | ||
const assert = require('assert') | ||
describe('create', () => { | ||
it('Create', (done) => { | ||
assert.ok(create({})) | ||
done() | ||
}) | ||
}) | ||
it('Create', (done) => { | ||
assert.ok(create({})); | ||
done(); | ||
}); | ||
}); | ||
/* global describe, it */ |
@@ -5,22 +5,22 @@ /** | ||
*/ | ||
"use strict"; | ||
'use strict' | ||
const decorateMsg = require('../lib/msg/decorate_msg.js'), | ||
assert = require('assert'); | ||
const decorateMsg = require('../lib/msg/decorate_msg.js') | ||
const assert = require('assert') | ||
describe('decorate', ()=> { | ||
it('Decorate msg', (done) => { | ||
assert.ok(decorateMsg('foo', 'green')); | ||
assert.equal(decorateMsg(null), null); | ||
done(); | ||
}); | ||
it('Decorate msg', (done) => { | ||
assert.ok(decorateMsg('foo', 'green')) | ||
assert.equal(decorateMsg(null), null) | ||
done() | ||
}) | ||
it('Decorate msg with invalid color.', (done) => { | ||
assert.throws(function () { | ||
decorateMsg('foo', '__not_existing_color') | ||
}) | ||
done() | ||
}) | ||
}) | ||
it('Decorate msg with invalid color.', (done) => { | ||
assert.throws(function () { | ||
decorateMsg('foo', '__not_existing_color'); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
/* global describe, it */ |
@@ -5,23 +5,23 @@ /** | ||
*/ | ||
"use strict"; | ||
'use strict' | ||
const define = require('../lib/define.js'), | ||
assert = require('assert'); | ||
const define = require('../lib/define.js') | ||
const assert = require('assert') | ||
describe('define', ()=> { | ||
it('Define', (done) => { | ||
let Logger = define({ | ||
verbose: false | ||
}) | ||
let logger = new Logger({}) | ||
logger.INFO('This is custom INFO') | ||
logger.DEBUG('This is custom DEBUG') | ||
logger.TRACE('This is custom TRACE') | ||
logger.ERROR('This is custom ERROR') | ||
logger.WARN('This is custom WARN') | ||
logger.FATAL('This is custom FATAL') | ||
done() | ||
}) | ||
}) | ||
it('Define', (done) => { | ||
let Logger = define({ | ||
verbose: false | ||
}); | ||
let logger = new Logger({}); | ||
logger.INFO('This is custom INFO'); | ||
logger.DEBUG('This is custom DEBUG'); | ||
logger.TRACE('This is custom TRACE'); | ||
logger.ERROR('This is custom ERROR'); | ||
logger.WARN('This is custom WARN'); | ||
logger.FATAL('This is custom FATAL'); | ||
done(); | ||
}); | ||
}); | ||
/* global describe, it */ |
@@ -5,24 +5,25 @@ /** | ||
*/ | ||
"use strict"; | ||
'use strict' | ||
const formatMsg = require('../lib/msg/format_msg.js'), | ||
assert = require('assert'); | ||
const formatMsg = require('../lib/msg/format_msg.js') | ||
const assert = require('assert') | ||
describe('format', () => { | ||
it('Format msg', (done) => { | ||
assert.equal(formatMsg('Hey, my name is %s, I am %d years old.', 'John', 34, 'Hoo!'), "Hey, my name is John, I am 34 years old. Hoo!"); | ||
assert.equal(formatMsg(''), ''); | ||
assert.equal(formatMsg(), ''); | ||
assert.equal(formatMsg('foo%f', 0.4), 'foo0.4'); | ||
assert.equal(formatMsg('foo%j', 0.4), 'foo%j 0.4'); | ||
done(); | ||
}); | ||
it('Format msg', (done) => { | ||
assert.equal(formatMsg('Hey, my name is %s, I am %d years old.', 'John', 34, 'Hoo!'), "Hey, my name is John, I am 34 years old. Hoo!") | ||
assert.equal(formatMsg(''), '') | ||
assert.equal(formatMsg(), '') | ||
assert.equal(formatMsg('foo%f', 0.4), 'foo0.4') | ||
assert.equal(formatMsg('foo%j', 0.4), 'foo%j 0.4') | ||
done() | ||
}) | ||
it('Format msg with object', (done) => { | ||
let msg = formatMsg({foo: 'bar'}, null); | ||
assert.ok(msg); | ||
it('Format msg with object', (done) => { | ||
let msg = formatMsg({ foo: 'bar' }, null) | ||
assert.ok(msg) | ||
done(); | ||
}); | ||
}); | ||
done() | ||
}) | ||
}) | ||
/* global describe, it */ |
@@ -5,14 +5,14 @@ /** | ||
*/ | ||
"use strict"; | ||
'use strict' | ||
const indentMsg = require('../lib/msg/indent_msg.js'), | ||
assert = require('assert'); | ||
const indentMsg = require('../lib/msg/indent_msg.js') | ||
const assert = require('assert') | ||
describe('indent', () => { | ||
it('Indent msg', (done) => { | ||
assert.equal(indentMsg('foo', 2).trim(), 'foo') | ||
done() | ||
}) | ||
}) | ||
it('Indent msg', (done) => { | ||
assert.equal(indentMsg('foo', 2).trim(), 'foo'); | ||
done(); | ||
}); | ||
}); | ||
/* global describe, it */ |
@@ -5,31 +5,32 @@ /** | ||
*/ | ||
"use strict"; | ||
'use strict' | ||
const lib = require('../lib'), | ||
assert = require('assert'); | ||
const lib = require('../lib') | ||
const assert = require('assert') | ||
describe('lib', () => { | ||
it('Lib', (done) => { | ||
assert.ok(lib.create({})); | ||
assert.ok(new lib.Colorprint({})); | ||
lib.colors.red('foo'); | ||
lib.notice('This is notice'); | ||
lib.info('This is info'); | ||
lib.debug('This is debug'); | ||
lib.trace('This is trace'); | ||
lib.error('This is error'); | ||
lib.warn('This is warn'); | ||
lib.fatal('This is fatal'); | ||
it('Lib', (done) => { | ||
assert.ok(lib.create({})) | ||
assert.ok(new lib.Colorprint({})) | ||
lib.colors.red('foo') | ||
lib.notice('This is notice') | ||
lib.info('This is info') | ||
lib.debug('This is debug') | ||
lib.trace('This is trace') | ||
lib.error('This is error') | ||
lib.warn('This is warn') | ||
lib.fatal('This is fatal') | ||
lib.INFO('This is INFO'); | ||
lib.DEBUG('This is DEBUG'); | ||
lib.TRACE('This is TRACE'); | ||
lib.WARN('This is WARN'); | ||
lib.ERROR('This is ERROR'); | ||
lib.FATAL('This is FATAL'); | ||
process.nextTick(()=> { | ||
done(); | ||
}); | ||
}); | ||
}); | ||
lib.INFO('This is INFO') | ||
lib.DEBUG('This is DEBUG') | ||
lib.TRACE('This is TRACE') | ||
lib.WARN('This is WARN') | ||
lib.ERROR('This is ERROR') | ||
lib.FATAL('This is FATAL') | ||
process.nextTick(()=> { | ||
done() | ||
}) | ||
}) | ||
}) | ||
/* global describe */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
623
134843