Comparing version 0.2.4 to 0.2.5
import { Config } from "./interfaces/config.interface"; | ||
import { Part } from "./interfaces/part.interface"; | ||
/** | ||
* Main Achorn class hosting Achorn core functionality | ||
*/ | ||
export default class Achorn { | ||
/** | ||
* Global Achorn config | ||
*/ | ||
globalConfig: Config; | ||
/** | ||
* Getter returning the length of the longest prefix | ||
*/ | ||
private get longestPrefixLength(); | ||
constructor(config?: Config); | ||
/** | ||
* Set global Achorn config | ||
* @param config Config object to set | ||
*/ | ||
config(config: Config): void; | ||
/** | ||
* Joins Array of paths to loggable message | ||
* @param parts Array of Parts to log | ||
*/ | ||
joinParts(parts: Part[], whitespace?: number): string[]; | ||
/** | ||
* Helper method to calculate additional whitespace after given parts | ||
* @param parts Array of Parts to determine whitespace after | ||
*/ | ||
calcAdditionalWhitespace(parts: Part[]): number; | ||
/** | ||
* Log given input with given prefix | ||
* @param prefixName Name/key of the prefix which will be used to log message | ||
* @param input Array of parts to log after prefix, can literally be anything | ||
*/ | ||
private consoleLog; | ||
/** | ||
* Creates and returns a new Timer | ||
* @param key Timer key, optional | ||
*/ | ||
timer(key?: string): Timer; | ||
} | ||
/** | ||
* Achorn Timer class handling everything Timer related | ||
*/ | ||
declare class Timer { | ||
/** | ||
* Achorn instance to compose console output | ||
*/ | ||
achorn: Achorn; | ||
/** | ||
* Start time unix timestamp | ||
*/ | ||
startTime: number; | ||
/** | ||
* End time unix timestamp | ||
*/ | ||
endTime: number; | ||
/** | ||
* Timer duration in milliseconds | ||
*/ | ||
duration: number; | ||
/** | ||
* Timer key to be displayed in console output | ||
*/ | ||
key: string; | ||
constructor(key?: string); | ||
/** | ||
* Start Timer | ||
*/ | ||
start(): void; | ||
/** | ||
* End Timer | ||
*/ | ||
end(): void; | ||
/** | ||
* End Timer with success message | ||
*/ | ||
success(...input: any[]): void; | ||
/** | ||
* End Timer with error message | ||
*/ | ||
error(...input: any[]): void; | ||
/** | ||
* End Timer with abort message | ||
*/ | ||
abort(...input: any[]): void; | ||
} | ||
export {}; |
@@ -1,1 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.achorn=e():t.achorn=e()}(window,(function(){return function(t){var e={};function o(r){if(e[r])return e[r].exports;var s=e[r]={i:r,l:!1,exports:{}};return t[r].call(s.exports,s,s.exports,o),s.l=!0,s.exports}return o.m=t,o.c=e,o.d=function(t,e,r){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)o.d(r,s,function(e){return t[e]}.bind(null,s));return r},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=0)}([function(t,e,o){const r=o(1).Achorn;t.exports=r},function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const r=o(2);class s{constructor(t){this.globalConfig={},this.config(t||{});r.prefixes.concat(t&&t.prefixes||[]).map(t=>{t.keys.map(t=>{this[t]=(...e)=>{this.consoleLog(t,e)}})})}get longestPrefixLength(){return r.prefixes.map(t=>t.parts[1].string).reduce((t,e)=>t.length>e.length?t:e).length}config(t){this.globalConfig=t}joinParts(t,e){let o=""+" ".repeat(e||0),r=[];return t.map(t=>{o+="%c"+t.string,r.push(t.style)}),[o].concat(r)}calcAdditionalWhitespace(t){const e=t[1].string.length;return this.longestPrefixLength-e+1}consoleLog(t,e){const o=r.prefixes.find(e=>e.keys.includes(t))||r.prefixes.find(t=>t.keys.includes("info"));let s=[].concat(o.parts);switch(s.push({string:" ".repeat(this.calcAdditionalWhitespace(s)),style:"color: unset;"}),this.globalConfig.showTimestamp&&s.unshift({string:`[${(new Date).getHours()}:${(new Date).getMinutes()}:${(new Date).getSeconds()}] `,style:"color: unset;"}),this.globalConfig.globalPrefix&&(s=this.globalConfig.globalPrefix.concat(s)),o.logType){case"warn":return void console.warn(...this.joinParts(s,1),...e.length>0?e:[e[0]]);case"error":return void console.error(...this.joinParts(s,1),...e.length>0?e:[e[0]]);default:console.log(...this.joinParts(s,2),...e.length>0?e:[e[0]])}}timer(t){return new n(t)}}e.default=s;class n{constructor(t){this.achorn=new s,this.key=t,this.start()}start(){this.startTime=+new Date;const t=[{string:"‣ ",style:"color: #2EB6CB;"},{string:this.key?this.key:"timer",style:"color: #2EB6CB; font-weight: bold;"}];t.push({string:" ".repeat(this.achorn.calcAdditionalWhitespace(t)),style:"color: unset;"}),console.log(...this.achorn.joinParts(t,2),"Timer started")}end(){this.endTime=+new Date,this.duration=this.endTime-this.startTime;const t=[{string:"‣ ",style:"color: #2EB6CB;"},{string:this.key?this.key:"timer",style:"color: #2EB6CB; font-weight: bold;"}];t.push({string:" ".repeat(this.achorn.calcAdditionalWhitespace(t)),style:"color: unset;"}),console.log(...this.achorn.joinParts(t,2),`Timer ended after ${this.duration}ms`)}success(...t){this.endTime=+new Date,this.duration=this.endTime-this.startTime;const e=[{string:"✔️ ",style:"color: #7EB507;"},{string:this.key?this.key:"success",style:"color: #7EB507; font-weight: bold;"}];e.push({string:" ".repeat(this.achorn.calcAdditionalWhitespace(e)),style:"color: unset;"}),console.log(...this.achorn.joinParts(e,2),...t&&t.length>0?t:[`Timer succeeded after ${this.duration}ms`])}error(...t){this.endTime=+new Date,this.duration=this.endTime-this.startTime;const e=[{string:"× ",style:"color: #FF312D;"},{string:this.key?this.key:"aborted",style:"color: #FF312D; font-weight: bold;"}];e.push({string:" ".repeat(this.achorn.calcAdditionalWhitespace(e)),style:"color: unset;"}),console.error(...this.achorn.joinParts(e,1),...t&&t.length>0?t:[`Timer errored after ${this.duration}ms`])}abort(...t){this.endTime=+new Date,this.duration=this.endTime-this.startTime;const e=[{string:"⚠️ ",style:"color: #DBA02A;"},{string:this.key?this.key:"error",style:"color: #DBA02A; font-weight: bold;"}];e.push({string:" ".repeat(this.achorn.calcAdditionalWhitespace(e)),style:"color: unset;"}),console.warn(...this.achorn.joinParts(e,1),...t&&t.length>0?t:[`Timer aborted after ${this.duration}ms`])}}},function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.prefixes=void 0,e.prefixes=[{keys:["success"],parts:[{string:"✔️ ",style:"color: #7EB507;"},{string:"success",style:"color: #7EB507; font-weight: bold;"}]},{keys:["error"],logType:"error",parts:[{string:"× ",style:"color: #FF312D;"},{string:"error",style:"color: #FF312D; font-weight: bold;"}]},{keys:["warn","warning"],logType:"warn",parts:[{string:"⚠️ ",style:"color: #DBA02A;"},{string:"warning",style:"color: #DBA02A; font-weight: bold;"}]},{keys:["await","awaiting"],parts:[{string:"… ",style:"color: #2EB6CB;"},{string:"awaiting",style:"color: #2EB6CB; font-weight: bold;"}]},{keys:["start"],parts:[{string:"► ",style:"color: #7EB507;"},{string:"start",style:"color: #7EB507; font-weight: bold;"}]},{keys:["pause"],parts:[{string:"‖ ",style:"color: #DBA02A;"},{string:"pause",style:"color: #DBA02A; font-weight: bold;"}]},{keys:["debug"],parts:[{string:"● ",style:"color: #2EB6CB;"},{string:"debug",style:"color: #2EB6CB; font-weight: bold;"}]},{keys:["info"],parts:[{string:"i ",style:"color: #2EB6CB;"},{string:"info",style:"color: #2EB6CB; font-weight: bold;"}]},{keys:["fatal"],logType:"error",parts:[{string:"◆ ",style:"color: #FF312D;"},{string:"fatal",style:"color: #FF312D; font-weight: bold;"}]},{keys:["timerStart"],parts:[{string:"‣ ",style:"color: #2EB6CB;"},{string:"timer",style:"color: #2EB6CB; font-weight: bold;"}]}]}])})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("Achorn",[],e):"object"==typeof exports?exports.Achorn=e():t.Achorn=e()}(window,(function(){return function(t){var e={};function o(r){if(e[r])return e[r].exports;var n=e[r]={i:r,l:!1,exports:{}};return t[r].call(n.exports,n,n.exports,o),n.l=!0,n.exports}return o.m=t,o.c=e,o.d=function(t,e,r){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)o.d(r,n,function(e){return t[e]}.bind(null,n));return r},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=0)}([function(t,e,o){"use strict";var r=this&&this.__spreadArrays||function(){for(var t=0,e=0,o=arguments.length;e<o;e++)t+=arguments[e].length;var r=Array(t),n=0;for(e=0;e<o;e++)for(var s=arguments[e],i=0,l=s.length;i<l;i++,n++)r[n]=s[i];return r};Object.defineProperty(e,"__esModule",{value:!0});var n=o(1),s=function(){function t(t){var e=this;this.globalConfig={},this.config(t||{}),n.prefixes.concat(t&&t.prefixes||[]).map((function(t){t.keys.map((function(t){e[t]=function(){for(var o=[],r=0;r<arguments.length;r++)o[r]=arguments[r];e.consoleLog(t,o)}}))}))}return Object.defineProperty(t.prototype,"longestPrefixLength",{get:function(){return n.prefixes.map((function(t){return t.parts[1].string})).reduce((function(t,e){return t.length>e.length?t:e})).length},enumerable:!1,configurable:!0}),t.prototype.config=function(t){this.globalConfig=t},t.prototype.joinParts=function(t,e){var o=""+" ".repeat(e||0),r=[];return t.map((function(t){o+="%c"+t.string,r.push(t.style)})),[o].concat(r)},t.prototype.calcAdditionalWhitespace=function(t){var e=t[1].string.length;return this.longestPrefixLength-e+1},t.prototype.consoleLog=function(t,e){var o=n.prefixes.find((function(e){return e.keys.includes(t)}))||n.prefixes.find((function(t){return t.keys.includes("info")})),s=[].concat(o.parts);switch(s.push({string:" ".repeat(this.calcAdditionalWhitespace(s)),style:"color: unset;"}),this.globalConfig.showTimestamp&&s.unshift({string:"["+(new Date).getHours()+":"+(new Date).getMinutes()+":"+(new Date).getSeconds()+"] ",style:"color: unset;"}),this.globalConfig.globalPrefix&&(s=this.globalConfig.globalPrefix.concat(s)),o.logType){case"warn":return void console.warn.apply(console,r(this.joinParts(s,1),e.length>0?e:[e[0]]));case"error":return void console.error.apply(console,r(this.joinParts(s,1),e.length>0?e:[e[0]]));default:console.log.apply(console,r(this.joinParts(s,2),e.length>0?e:[e[0]]))}},t.prototype.timer=function(t){return new i(t)},t}();e.default=s;var i=function(){function t(t){this.achorn=new s,this.key=t,this.start()}return t.prototype.start=function(){this.startTime=+new Date;var t=[{string:"‣ ",style:"color: #2EB6CB;"},{string:this.key?this.key:"timer",style:"color: #2EB6CB; font-weight: bold;"}];t.push({string:" ".repeat(this.achorn.calcAdditionalWhitespace(t)),style:"color: unset;"}),console.log.apply(console,r(this.achorn.joinParts(t,2),["Timer started"]))},t.prototype.end=function(){this.endTime=+new Date,this.duration=this.endTime-this.startTime;var t=[{string:"‣ ",style:"color: #2EB6CB;"},{string:this.key?this.key:"timer",style:"color: #2EB6CB; font-weight: bold;"}];t.push({string:" ".repeat(this.achorn.calcAdditionalWhitespace(t)),style:"color: unset;"}),console.log.apply(console,r(this.achorn.joinParts(t,2),["Timer ended after "+this.duration+"ms"]))},t.prototype.success=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.endTime=+new Date,this.duration=this.endTime-this.startTime;var o=[{string:"✔️ ",style:"color: #7EB507;"},{string:this.key?this.key:"success",style:"color: #7EB507; font-weight: bold;"}];o.push({string:" ".repeat(this.achorn.calcAdditionalWhitespace(o)),style:"color: unset;"}),console.log.apply(console,r(this.achorn.joinParts(o,2),t&&t.length>0?t:["Timer succeeded after "+this.duration+"ms"]))},t.prototype.error=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.endTime=+new Date,this.duration=this.endTime-this.startTime;var o=[{string:"× ",style:"color: #FF312D;"},{string:this.key?this.key:"aborted",style:"color: #FF312D; font-weight: bold;"}];o.push({string:" ".repeat(this.achorn.calcAdditionalWhitespace(o)),style:"color: unset;"}),console.error.apply(console,r(this.achorn.joinParts(o,1),t&&t.length>0?t:["Timer errored after "+this.duration+"ms"]))},t.prototype.abort=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.endTime=+new Date,this.duration=this.endTime-this.startTime;var o=[{string:"⚠️ ",style:"color: #DBA02A;"},{string:this.key?this.key:"error",style:"color: #DBA02A; font-weight: bold;"}];o.push({string:" ".repeat(this.achorn.calcAdditionalWhitespace(o)),style:"color: unset;"}),console.warn.apply(console,r(this.achorn.joinParts(o,1),t&&t.length>0?t:["Timer aborted after "+this.duration+"ms"]))},t}()},function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.prefixes=void 0,e.prefixes=[{keys:["success"],parts:[{string:"✔️ ",style:"color: #7EB507;"},{string:"success",style:"color: #7EB507; font-weight: bold;"}]},{keys:["error"],logType:"error",parts:[{string:"× ",style:"color: #FF312D;"},{string:"error",style:"color: #FF312D; font-weight: bold;"}]},{keys:["warn","warning"],logType:"warn",parts:[{string:"⚠️ ",style:"color: #DBA02A;"},{string:"warning",style:"color: #DBA02A; font-weight: bold;"}]},{keys:["await","awaiting"],parts:[{string:"… ",style:"color: #2EB6CB;"},{string:"awaiting",style:"color: #2EB6CB; font-weight: bold;"}]},{keys:["start"],parts:[{string:"► ",style:"color: #7EB507;"},{string:"start",style:"color: #7EB507; font-weight: bold;"}]},{keys:["pause"],parts:[{string:"‖ ",style:"color: #DBA02A;"},{string:"pause",style:"color: #DBA02A; font-weight: bold;"}]},{keys:["debug"],parts:[{string:"● ",style:"color: #2EB6CB;"},{string:"debug",style:"color: #2EB6CB; font-weight: bold;"}]},{keys:["info"],parts:[{string:"i ",style:"color: #2EB6CB;"},{string:"info",style:"color: #2EB6CB; font-weight: bold;"}]},{keys:["fatal"],logType:"error",parts:[{string:"◆ ",style:"color: #FF312D;"},{string:"fatal",style:"color: #FF312D; font-weight: bold;"}]},{keys:["timerStart"],parts:[{string:"‣ ",style:"color: #2EB6CB;"},{string:"timer",style:"color: #2EB6CB; font-weight: bold;"}]}]}])})); | ||
//# sourceMappingURL=achorn.js.map |
import { Part } from "./part.interface"; | ||
import { Prefix } from "./prefix.interface"; | ||
export interface Config { | ||
/** | ||
* Boolean if a timestamp shall be displayed before every message | ||
*/ | ||
showTimestamp?: boolean; | ||
/** | ||
* Array of Preifx Parts of global prefix displayed before every message | ||
*/ | ||
globalPrefix?: Part[]; | ||
/** | ||
* Array of custom prefixes added to default ones | ||
*/ | ||
prefixes?: Prefix[]; | ||
} |
{ | ||
"name": "achorn", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "🌰 A colourful, good looking, fully customisable logger for the browser", | ||
@@ -10,3 +10,5 @@ "publishConfig": { | ||
"build": "webpack", | ||
"watch": "webpack --watch" | ||
"watch": "webpack --watch", | ||
"lint": "tslint -p tsconfig.json", | ||
"prettier": "prettier --write src/**/*.ts" | ||
}, | ||
@@ -18,2 +20,3 @@ "author": "Juri Adams <juri@adams.sh>", | ||
"ts-loader": "^7.0.5", | ||
"tslint": "^6.1.2", | ||
"typescript": "^3.9.5", | ||
@@ -24,5 +27,8 @@ "webpack": "^4.43.0", | ||
"files": [ | ||
"lib/**/*" | ||
"lib/**/*", | ||
"README.md", | ||
"tsconfig.json", | ||
"index.js" | ||
], | ||
"main": "lib/achorn.js" | ||
} |
38706
11
159
6