diff --git a/index.js b/index.js index f01ad03..059514c 100644 --- a/index.js +++ b/index.js @@ -8,9 +8,11 @@ bl = {}; */ var localBl; localBl = {}; -localBl.normalPrefix = ' Log: '.bgCyan.white.bold + ' '; localBl.errorPrefix = ' Error: '.bgRed.white.bold + ' '; +localBl.normalPrefix = ' Log: '.bgCyan.white.bold + ' '; +localBl.okPrefix = ' '.bgGreen + ' OK! '.bgBlack.green.bold + ' '; localBl.successPrefix = ' Success: '.bgGreen.white.bold + ' '; +localBl.warnPrefix = ' '.bgYellow + ' Warn: '.bgBlack.yellow.bold + ' '; /** * * @param logText @@ -22,15 +24,21 @@ bl.log = function (logText, logType) { if (logType === void 0) { logType = 'normal'; } try { switch (logType) { - case 'normal': - logText = localBl.normalPrefix + logText.cyan.bold; - break; case 'error': logText = localBl.errorPrefix + logText.red.bold; break; + case 'normal': + logText = localBl.normalPrefix + logText.cyan.bold; + break; + case 'ok': + logText = localBl.okPrefix + logText.italic; + break; case 'success': logText = localBl.successPrefix + logText.green.bold; break; + case 'warn': + logText = localBl.warnPrefix + logText.italic; + break; default: logText.blue.bold; console.log(('unknown logType for "' + logText + '"').red.bold); @@ -51,6 +59,14 @@ bl.log = function (logText, logType) { bl.error = function (logText) { return bl.log(logText, 'error'); }; +/** + * logs an 'OK!' message to console + * @param logText + * @returns {boolean} + */ +bl.ok = function (logText) { + return bl.log(logText, 'ok'); +}; /** * logs a success to console * @param logText string to log as error @@ -59,4 +75,12 @@ bl.error = function (logText) { bl.success = function (logText) { return bl.log(logText, 'success'); }; +/** + * logs a 'warn:' message to console + * @param logText string to log as error + * @returns {boolean} + */ +bl.warn = function (logText) { + return bl.log(logText, 'warn'); +}; module.exports = bl; diff --git a/package.json b/package.json index 35e781a..802c665 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "beautiful logging", "main": "index.js", "scripts": { - "test": "cd ts/compile && gulp", + "test": "(cd ts/compile && gulp) && (node test.js)", "release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)" }, "repository": { diff --git a/test.js b/test.js index 9cb12ff..79a491c 100644 --- a/test.js +++ b/test.js @@ -5,11 +5,15 @@ console.log(''); console.log('declarative function calls:'); beautyLog.log('beautylog.log(), with normal logText, without logType'); beautyLog.error('beautylog.error(), with normal logText, without logType'); +beautyLog.ok('beautylog.ok(), with normal logText, without logType'); beautyLog.success('beautylog.success(), with normal logText, without logType'); +beautyLog.warn('beautylog.warn(), with normal logText, without logType'); console.log(''); console.log('logType String:'); beautyLog.log('beautylog.log(), with normal logText, without logType'); beautyLog.log('beautylog.log(), with normal logText, with logType "error"', 'error'); +beautyLog.log('beautylog.log(), with normal logText, with logType "ok"', 'ok'); beautyLog.log('beautylog.log(), with normal logText, with logType "success"', 'success'); +beautyLog.log('beautylog.log(), with normal logText, with logType "warn"', 'warn'); console.log(''); console.log('*** end test ***'); diff --git a/ts/index.js b/ts/index.js new file mode 100644 index 0000000..3db6b54 --- /dev/null +++ b/ts/index.js @@ -0,0 +1,87 @@ +/// +var colors = require("colors"); +var bl; +bl = {}; +/** + * object to append to all locally used params + * @type {{}} + */ +var localBl; +localBl = {}; +localBl.errorPrefix = ' Error: '.bgRed.white.bold + ' '; +localBl.normalPrefix = ' Log: '.bgCyan.white.bold + ' '; +localBl.okPrefix = ' '.bgGreen + ' OK! '.bgBlack.green.bold + ' '; +localBl.successPrefix = ' Success: '.bgGreen.white.bold + ' '; +localBl.warnPrefix = ' '.bgYellow + ' Warn: '.bgBlack.yellow.bold + ' '; +/** + * + * @param logText + * @param logType + * @returns {boolean} + */ +bl.log = function (logText, logType) { + if (logText === void 0) { logText = 'empty log'; } + if (logType === void 0) { logType = 'normal'; } + try { + switch (logType) { + case 'error': + logText = localBl.errorPrefix + logText.red.bold; + break; + case 'normal': + logText = localBl.normalPrefix + logText.cyan.bold; + break; + case 'ok': + logText = localBl.okPrefix + logText.italic; + break; + case 'success': + logText = localBl.successPrefix + logText.green.bold; + break; + case 'warn': + logText = localBl.warnPrefix + logText.italic; + break; + default: + logText.blue.bold; + console.log(('unknown logType for "' + logText + '"').red.bold); + } + console.log(logText); + return true; + } + catch (error) { + console.log(localBl.errorPrefix + 'You seem to have tried logging something strange'.red.bold + error); + return false; + } +}; +/** + * logs an error to console + * @param logText + * @returns {boolean} + */ +bl.error = function (logText) { + return bl.log(logText, 'error'); +}; +/** + * logs an 'OK!' message to console + * @param logText + * @returns {boolean} + */ +bl.ok = function (logText) { + return bl.log(logText, 'ok'); +}; +/** + * logs a success to console + * @param logText string to log as error + * @returns {boolean} + */ +bl.success = function (logText) { + return bl.log(logText, 'success'); +}; +/** + * logs a 'warn:' message to console + * @param logText string to log as error + * @returns {boolean} + */ +bl.warn = function (logText) { + return bl.log(logText, 'warn'); +}; +module.exports = bl; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/ts/index.js.map b/ts/index.js.map new file mode 100644 index 0000000..41618c3 --- /dev/null +++ b/ts/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,IAAI,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAG/B,IAAI,EAAM,CAAC;AACX,EAAE,GAAG,EAAE,CAAA;AAEP;;;GAGG;AACH,IAAI,OAAW,CAAC;AAChB,OAAO,GAAG,EAAE,CAAC;AACb,OAAO,CAAC,WAAW,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,GAAI,GAAG,CAAC;AACzD,OAAO,CAAC,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAI,GAAG,CAAC;AACzD,OAAO,CAAC,QAAQ,GAAG,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,GAAI,GAAG,CAAC;AACnE,OAAO,CAAC,aAAa,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,GAAI,GAA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GAAG,kDAAkD,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;QACvG,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;AACL,CAAC,CAAC;AAGF;;;;GAIG;AACH,EAAE,CAAC,KAAK,GAAG,UAAS,OAAO;IACvB,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AACpC,CAAC,CAAC;AAEF;;;;GAIG;AACH,EAAE,CAAC,EAAE,GAAG,UAAS,OAAO;IACpB,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC,CAAC;AAEF;;;;GAIG;AACH,EAAE,CAAC,OAAO,GAAG,UAAS,OAAO;IACzB,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACtC,CAAC,CAAA;AAED;;;;GAIG;AACH,EAAE,CAAC,IAAI,GAAG,UAAS,OAAO;IACtB,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACnC,CAAC,CAAA;AAED,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC"} \ No newline at end of file diff --git a/ts/index.ts b/ts/index.ts index a3b3ea6..c1ee832 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -11,9 +11,11 @@ bl = {} */ var localBl:any; localBl = {}; -localBl.normalPrefix = ' Log: '.bgCyan.white.bold + ' '; localBl.errorPrefix = ' Error: '.bgRed.white.bold + ' '; +localBl.normalPrefix = ' Log: '.bgCyan.white.bold + ' '; +localBl.okPrefix = ' '.bgGreen + ' OK! '.bgBlack.green.bold + ' '; localBl.successPrefix = ' Success: '.bgGreen.white.bold + ' '; +localBl.warnPrefix = ' '.bgYellow + ' Warn: '.bgBlack.yellow.bold + ' '; /** * @@ -24,15 +26,21 @@ localBl.successPrefix = ' Success: '.bgGreen.white.bold + ' '; bl.log = (logText:string = 'empty log',logType:string = 'normal') => { try { switch (logType) { - case 'normal': - logText = localBl.normalPrefix + logText.cyan.bold; - break; case 'error': logText = localBl.errorPrefix + logText.red.bold; break; + case 'normal': + logText = localBl.normalPrefix + logText.cyan.bold; + break; + case 'ok': + logText = localBl.okPrefix + logText.italic; + break; case 'success': logText = localBl.successPrefix + logText.green.bold; break; + case 'warn': + logText = localBl.warnPrefix + logText.italic; + break; default: logText.blue.bold; console.log(('unknown logType for "' + logText + '"').red.bold); @@ -56,6 +64,15 @@ bl.error = function(logText) { return bl.log(logText, 'error'); }; +/** + * logs an 'OK!' message to console + * @param logText + * @returns {boolean} + */ +bl.ok = function(logText) { + return bl.log(logText, 'ok'); +}; + /** * logs a success to console * @param logText string to log as error @@ -65,4 +82,13 @@ bl.success = function(logText) { return bl.log(logText, 'success'); } +/** + * logs a 'warn:' message to console + * @param logText string to log as error + * @returns {boolean} + */ +bl.warn = function(logText) { + return bl.log(logText, 'warn'); +} + module.exports = bl; diff --git a/ts/test.js b/ts/test.js new file mode 100644 index 0000000..6888ead --- /dev/null +++ b/ts/test.js @@ -0,0 +1,20 @@ +/// +var beautyLog = require('./index.js'); +console.log('*** start test ***'); +console.log(''); +console.log('declarative function calls:'); +beautyLog.log('beautylog.log(), with normal logText, without logType'); +beautyLog.error('beautylog.error(), with normal logText, without logType'); +beautyLog.ok('beautylog.ok(), with normal logText, without logType'); +beautyLog.success('beautylog.success(), with normal logText, without logType'); +beautyLog.warn('beautylog.warn(), with normal logText, without logType'); +console.log(''); +console.log('logType String:'); +beautyLog.log('beautylog.log(), with normal logText, without logType'); +beautyLog.log('beautylog.log(), with normal logText, with logType "error"', 'error'); +beautyLog.log('beautylog.log(), with normal logText, with logType "ok"', 'ok'); +beautyLog.log('beautylog.log(), with normal logText, with logType "success"', 'success'); +beautyLog.log('beautylog.log(), with normal logText, with logType "warn"', 'warn'); +console.log(''); +console.log('*** end test ***'); +//# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/ts/test.js.map b/ts/test.js.map new file mode 100644 index 0000000..31db29e --- /dev/null +++ b/ts/test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,IAAI,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAEtC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAClC,OAAO,CAAC,GAAG,CAAE,EAAE,CAAC,CAAC;AAEjB,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAC3C,SAAS,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;AACvE,SAAS,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;AAC3E,SAAS,CAAC,EAAE,CAAC,sDAAsD,CAAC,CAAC;AACrE,SAAS,CAAC,OAAO,CAAC,2DAA2D,CAAC,CAAC;AAC/E,SAAS,CAAC,IAAI,CAAC,wDAAwD,CAAC,CAAC;AAEzE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAEhB,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAC/B,SAAS,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;AACvE,SAAS,CAAC,GAAG,CAAC,4DAA4D,EAAC,OAAO,CAAC,CAAC;AACpF,SAAS,CAAC,GAAG,CAAC,yDAAyD,EAAC,IAAI,CAAC,CAAC;AAC9E,SAAS,CAAC,GAAG,CAAC,8DAA8D,EAAC,SAAS,CAAC,CAAC;AACxF,SAAS,CAAC,GAAG,CAAC,2DAA2D,EAAC,MAAM,CAAC,CAAC;AAElF,OAAO,CAAC,GAAG,CAAE,EAAE,CAAC,CAAC;AACjB,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC"} \ No newline at end of file diff --git a/ts/test.ts b/ts/test.ts index b49197a..f7a0dd1 100644 --- a/ts/test.ts +++ b/ts/test.ts @@ -7,14 +7,18 @@ console.log (''); console.log('declarative function calls:'); beautyLog.log('beautylog.log(), with normal logText, without logType'); beautyLog.error('beautylog.error(), with normal logText, without logType'); +beautyLog.ok('beautylog.ok(), with normal logText, without logType'); beautyLog.success('beautylog.success(), with normal logText, without logType'); +beautyLog.warn('beautylog.warn(), with normal logText, without logType'); console.log(''); console.log('logType String:'); beautyLog.log('beautylog.log(), with normal logText, without logType'); beautyLog.log('beautylog.log(), with normal logText, with logType "error"','error'); +beautyLog.log('beautylog.log(), with normal logText, with logType "ok"','ok'); beautyLog.log('beautylog.log(), with normal logText, with logType "success"','success'); +beautyLog.log('beautylog.log(), with normal logText, with logType "warn"','warn'); console.log (''); console.log('*** end test ***'); \ No newline at end of file