diff --git a/package.json b/package.json index 3d1d136..6831311 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "test": "mocha", "build": "esbuild src/browser.ts --bundle --minify --sourcemap --target=firefox120 --outfile=public/bundle.js", + "watch": "npm run build -- --watch", "prepare": "npm run build", "clean-coverage": "rm -rf coverage .nyc_output .xunit", "coverage": "npm run clean-coverage && nyc mocha", diff --git a/src/index.ts b/src/index.ts index 978ae1d..d49b709 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,9 +35,15 @@ function parseTimestamp(s: string): number { function toTimestamp(n: number): string { n = Math.floor(n); - return `${Math.floor(n / 60) - .toString() - .padStart(2, "0")}:${(n % 60).toString().padStart(2, "0")}`; + let result: number[] = []; + while (n / 60 > 0) { + result.push(n % 60); + n = Math.floor(n / 60); + } + return result + .map((n, i) => (i >= 2 ? n.toString() : n.toString().padStart(2, "0"))) + .reverse() + .join(":"); } export function parse_youtube(content: string): Timestamp[] {