UNPKG

surrogate

Version:

Object method hooks made easy

48 lines 1.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Trackable = void 0; class Trackable { constructor() { this.hookTimes = []; this.nanosecondsInMilliseconds = 1000000; this.nanosecondsInSeconds = 1000000000; } getStartTime() { return Date.now() - this.getTotalDuration(); } getHookStartTime() { return this.getStartTime() + (this.hookStartTime - this.startTime); } getLastRunDuration() { const [hookStart, hookEnd] = this.lastRun; return hookEnd - hookStart; } getTotalDuration() { return this.getNow() - this.startTime; } getDurationSinceLastRun() { const lastRun = this.lastRunEnd; return this.getNow() - lastRun; } setHookStart() { this.hookStartTime = this.getNow(); } setHookEnd() { this.hookTimes.push([this.hookStartTime, this.getNow()]); } get lastRun() { var _a; const [hookStart, hookEnd] = (_a = this.hookTimes[this.hookTimes.length - 1]) !== null && _a !== void 0 ? _a : []; return [hookStart !== null && hookStart !== void 0 ? hookStart : this.startTime, hookEnd !== null && hookEnd !== void 0 ? hookEnd : this.getNow()]; } get lastRunStart() { const [hookStart] = this.lastRun; return hookStart; } get lastRunEnd() { const [, hookEnd] = this.lastRun; return hookEnd; } } exports.Trackable = Trackable; //# sourceMappingURL=index.js.map