-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from JustinPinner/1.0.3
1.0.3
- Loading branch information
Showing
10 changed files
with
425 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Formatting helper functions | ||
|
||
const leftPad = function(unpadded, char, maxLen) { | ||
// don't rely on implicit conversion | ||
const str = !isNaN(unpadded) ? unpadded.toString() : unpadded; | ||
// protect against negative padding length | ||
const padLen = ((maxLen || str.length) - str.length < 0) ? 0 : (maxLen || str.length) - str.length; | ||
const padChars = char.repeat(padLen); | ||
return `${padChars}${str}`; | ||
}; | ||
|
||
const time = function(dateVal, includeMillis) { | ||
const when = dateVal || new Date(); | ||
const hh = leftPad(when.getHours(), '0', 2); | ||
const mm = leftPad(when.getMinutes(), '0', 2); | ||
const ss = leftPad(when.getSeconds(), '0', 2); | ||
const mi = leftPad(when.getMilliseconds(), '0', 3); | ||
return `${hh}:${mm}:${ss}${includeMillis ? `.${mi}` : ''}`; | ||
}; | ||
|
||
const date = function(dateVal) { | ||
const when = dateVal || new Date(); | ||
const yyyy = when.getFullYear(); | ||
const mm = leftPad(when.getMonth(), '0', 2); | ||
const dd = leftPad(when.getDate(), '0', 2); | ||
return `${yyyy}-${mm}-${dd}`; | ||
} | ||
|
||
const dateTime = function(dateVal, includeMillis) { | ||
return `${date(dateVal)} ${time(dateVal, includeMillis)}`; | ||
}; | ||
|
||
class Formatter { | ||
constructor() { | ||
this.leftPad = leftPad; | ||
this.formatTime = time; | ||
this.formatDate = date; | ||
this.formatDateTime = dateTime; | ||
} | ||
}; | ||
|
||
export { | ||
Formatter | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// A _really_ basic logger class for debugging ops | ||
// Figured it'd be easier to use other logging targets/libraries via a single provider class | ||
|
||
import { Formatter } from '../lib/format'; | ||
|
||
class Logger { | ||
constructor(parent) { | ||
this._parent = parent; | ||
this.formatter = new Formatter(); | ||
} | ||
} | ||
|
||
Logger.prototype.logAction = function(logMessage) { | ||
const now = new Date(); | ||
const withMillis = true; | ||
console.log(`${this.formatter.formatTime(now, withMillis)} > ${this._parent}: ${logMessage}`); | ||
} | ||
|
||
export { | ||
Logger | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters