timer-logs
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -21,4 +21,4 @@ declare type Config = { | ||
private readonly startTime; | ||
private finishTime; | ||
private mostRecentlyStartedLabel; | ||
private finishTime?; | ||
private mostRecentlyStartedLabel?; | ||
private config; | ||
@@ -38,3 +38,3 @@ private readonly savedTimes; | ||
start(label: string): { | ||
stop: () => number; | ||
stop: () => number | undefined; | ||
}; | ||
@@ -45,3 +45,3 @@ /** | ||
*/ | ||
stop(label: string): number; | ||
stop(label: string): number | undefined; | ||
/** | ||
@@ -63,3 +63,3 @@ * Stops the most recently started timer, and starts a new one | ||
*/ | ||
end(): number; | ||
end(): number | undefined; | ||
/** | ||
@@ -66,0 +66,0 @@ * prints times to the console in JSON format for Google Cloud Logging. |
15
index.js
@@ -29,7 +29,12 @@ "use strict"; | ||
console.assert(this.savedTimes[label].finishTime === undefined, 'Stop called more than once for same label'); | ||
this.savedTimes[label].finishTime = Date.now(); | ||
this.savedTimes[label].time = this.savedTimes[label].finishTime - this.savedTimes[label].startTime; | ||
const finishTime = Date.now(); | ||
this.savedTimes[label].finishTime = finishTime; | ||
this.savedTimes[label].time = finishTime - this.savedTimes[label].startTime; | ||
return this.savedTimes[label].time; | ||
} | ||
next(label) { | ||
if (!this.mostRecentlyStartedLabel) { | ||
console.error('Next called before a timer was started'); | ||
return; | ||
} | ||
this.stop(this.mostRecentlyStartedLabel); | ||
@@ -52,4 +57,6 @@ this.start(label); | ||
}; | ||
Object.entries(this.savedTimes).forEach(([label, times]) => { | ||
printObject[label] = times.time; | ||
Object.entries(this.savedTimes) | ||
.forEach(([label, times]) => { | ||
if (typeof times.time === 'number') | ||
printObject[label] = times.time; | ||
}); | ||
@@ -56,0 +63,0 @@ if ((_f = this === null || this === void 0 ? void 0 : this.config) === null || _f === void 0 ? void 0 : _f.details) |
14
index.ts
@@ -65,4 +65,5 @@ type Config = { | ||
console.assert(this.savedTimes[label].finishTime === undefined, 'Stop called more than once for same label') | ||
this.savedTimes[label].finishTime = Date.now() | ||
this.savedTimes[label].time = this.savedTimes[label].finishTime - this.savedTimes[label].startTime | ||
const finishTime = Date.now() | ||
this.savedTimes[label].finishTime = finishTime | ||
this.savedTimes[label].time = finishTime - this.savedTimes[label].startTime | ||
return this.savedTimes[label].time | ||
@@ -84,2 +85,6 @@ } | ||
public next(label: string) { | ||
if(!this.mostRecentlyStartedLabel){ | ||
console.error('Next called before a timer was started') | ||
return | ||
} | ||
this.stop(this.mostRecentlyStartedLabel) | ||
@@ -108,4 +113,5 @@ this.start(label) | ||
} | ||
Object.entries(this.savedTimes).forEach(([label, times]) => { | ||
printObject[label] = times.time | ||
Object.entries(this.savedTimes) | ||
.forEach(([label, times]) => { | ||
if(typeof times.time === 'number') printObject[label] = times.time | ||
}) | ||
@@ -112,0 +118,0 @@ if (this?.config?.details) |
{ | ||
"name": "timer-logs", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"devDependencies": { | ||
@@ -5,0 +5,0 @@ "@types/node": "^15.00.0" |
@@ -5,3 +5,4 @@ { | ||
"target": "ES2019", | ||
"sourceMap": false | ||
"sourceMap": false, | ||
"strict": true | ||
}, | ||
@@ -8,0 +9,0 @@ "exclude": [ |
Sorry, the diff of this file is not supported yet
29768
494