Skip to content

Commit

Permalink
adds doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank M. Taylor committed Oct 11, 2023
1 parent d4ca39b commit 0c2a6fe
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export default class Log {
return this;
}

/**
* @description logs text to a file
* @param {string} info - the text to log
* @returns {this}
*/
async infoToFileAsync(info) {
const rawMessage = info || this.rawMessage;

Expand All @@ -47,6 +52,11 @@ export default class Log {
return this;
}

/**
* @description outputs a message using internal "styles"
* @param {string} info - the info to style
* @param {boolean} showTimestamp=false - whether to show a timestamp
*/
static styleInfo(info, showTimestamp = false) {
return `
==============${showTimestamp ? new Date() : ''}===============
Expand All @@ -55,6 +65,12 @@ ${info}
`;
}

/**
* @description adds a colorful padded box around a message
* @param {string} info - the info to style
* @param {boolean} showTimestamp=false - whether to show a timestamp
* @return {boxen} a styled message
*/
static boxInfo(info, showTimestamp = false) {
const options = { padding: 1 };
if (showTimestamp) {
Expand All @@ -64,6 +80,12 @@ ${info}
return boxen(info, options);
}

/**
* @description logs a message to the console that is styled
* @param {string} info - the info to style
* @param {boolean} isImportant - whether to give the message a background
* @returns {this}
*/
toConsole(info, isImportant) {
const rawMessage = info || this.rawMessage;
const infoMessage = Log.boxInfo(rawMessage);
Expand All @@ -78,6 +100,9 @@ ${info}
return this;
}

/**
* @description starts a timer on the log object (you only get one)
*/
startTimer() {
this.timerStart = Date.now();
if (this.timerEnd) {
Expand All @@ -86,12 +111,19 @@ ${info}
return this;
}

/**
* @description ends a timer on the log object
*/
endTimer() {
this.timerEnd = Date.now();

return this;
}

/**
* @description gets the elapsed time
* @returns {number} the elapsed time in seconds
*/
get elapsedTime() {
let elapsedTime = null;

Expand Down

0 comments on commit 0c2a6fe

Please sign in to comment.