Skip to content

Commit

Permalink
refactor;bump
Browse files Browse the repository at this point in the history
  • Loading branch information
117 committed Sep 25, 2024
1 parent 65ab3f2 commit 1c74a7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@117/stopwatch",
"description": "An easy-to-use stopwatch for Deno.",
"version": "1.0.1",
"version": "1.0.2",
"exports": "./mod.ts",
"imports": {
"@/": "./",
Expand Down
14 changes: 11 additions & 3 deletions src/createStopwatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* @property {function(): number} getElapsedTime - Returns the elapsed time in milliseconds.
*/
export type Stopwatch = {
start: () => void;
stop: () => void;
reset: () => void;
start: () => Stopwatch;
stop: () => Stopwatch;
reset: () => Stopwatch;
getElapsedTime: () => number;
};

Expand All @@ -27,23 +27,31 @@ export const createStopwatch = (): Stopwatch => {
startTime = Date.now() - elapsedTime;
running = true;
}

return this;
},
stop() {
if (running) {
elapsedTime = Date.now() - startTime!;
running = false;
}

return this;
},
reset() {
elapsedTime = 0;

if (running) {
startTime = Date.now();
}

return this;
},
getElapsedTime() {
if (running) {
return Date.now() - startTime!;
}

return elapsedTime;
},
};
Expand Down

0 comments on commit 1c74a7d

Please sign in to comment.