{"id":24564705,"url":"https://github.com/tdecker91/srtimer","last_synced_at":"2025-04-19T20:37:30.149Z","repository":{"id":34003160,"uuid":"37758277","full_name":"tdecker91/srTimer","owner":"tdecker91","description":"Configurable javascript timer application.","archived":false,"fork":false,"pushed_at":"2023-01-24T17:14:25.000Z","size":80,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T23:52:45.931Z","etag":null,"topics":["javascript","javascript-timer-application","rubiks-cube-timer","timer","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tdecker91.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-20T04:57:40.000Z","updated_at":"2023-03-13T16:48:24.000Z","dependencies_parsed_at":"2023-02-13T23:40:24.016Z","dependency_job_id":null,"html_url":"https://github.com/tdecker91/srTimer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdecker91%2FsrTimer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdecker91%2FsrTimer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdecker91%2FsrTimer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdecker91%2FsrTimer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tdecker91","download_url":"https://codeload.github.com/tdecker91/srTimer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249795195,"owners_count":21326776,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","javascript-timer-application","rubiks-cube-timer","timer","typescript"],"created_at":"2025-01-23T11:20:18.472Z","updated_at":"2025-04-19T20:37:30.119Z","avatar_url":"https://github.com/tdecker91.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# srTimer\nSimple javascript timer application. Originally made to run my cube timer app at http://www.solvingrubik.com/\nCan easily be included and configured to work on any webpage.\n\n## Instalation\nDownload the timer.js file and put it in your web directory.\n\nOR\n\nInstall the package using npm\n```bash\nnpm install --save sr-timer\n```\n\n## Usage\nImport the library\n\n```javascript\nimport SRTimer from 'sr-timer'\n```\n\nCreate a new instance of the timer. The timer will automatically bind to window key events to listen for the spacebar to start / stop the timer.\n\n```javascript\nlet timer = new SRTimer()\n```\n\nOptionally an alternate keycode can be passed in to the constructor customize what key is listens for.\n\n```javascript\nlet timer = new SRTimer(65) // use 'A' key\n```\n\nIf you don't want the timer to bind to window events you can pass in null as the timer key.\n\n```javascript\nlet timer = new SRTimer(null) // start / stop timer manually\ntimer.start()\n...\ntimer.stop()\nconst elapsed = timer.getElapsedTime()\n```\n\nWhen you no longer need the timer make sure to call `unbind` to stop listening for keyevents\n```javascript\ntimer.unbind();\ndelete timer;\n```\n\n## Registering Listeners\nListeners can be registered to receive events when the timer starts, stops, ticks, or resets. This allows the timer to call your custom code to fit any of your application's needs. \n```javascript\ntimer.addStartListener(() =\u003e {\n  console.log('timer started')\n})\n\ntimer.addStopListener(stopEvent =\u003e {\n  console.log(`elapsed time ${stopEvent.time}`)\n})\n```\n\n## API\n  | Method | Description | Example |\n  |---|---|---|\n  | `start()` | starts the timer | `timer.start()` |\n  | `stop()` | stops the timer and sets the elapsed time. | `timer.stop()` |\n  | `reset()` | resets the timer and sets elapsed time back to 0 | `timer.reset()` |\n  | `isRunning()` | returns true if the timer is currently started | `timer.isRunning()` |\n  | `getElapsedTime()` | Gives the current elapsed time as a formatted string | `let elapsed = timer.getElapsedTime()` |\n  | `addStartListener(listener: () =\u003e void)` | register listener for when the timer starts | `timer.addStartListener(() =\u003e { console.log('started') })` |\n  | `addStopListener(listener: (event: TimerEvent) =\u003e void)` | register listener for when the timer stops | `timer.addStopListener(event =\u003e { console.log('stopped', event) })` |\n  | `addResetListener(listener: () =\u003e void)` | register listener for when the timer resets | `timer.addResetListener(() =\u003e { console.log('reset') })` |\n  | `addTickListener(listener: (event: TimerEvent) =\u003e void)` | register listener for when the timer ticks | `timer.addTickListener(event =\u003e { console.log('tick', event) })` |\n\n## Development\n\n### Build the dist\n```bash\nnpm run build\n```\n\nPublish to registry\n\n1. update version in `package.json`\n1. build bundle `npm run build` and build library `tsc`\n1. run `npm publish`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftdecker91%2Fsrtimer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftdecker91%2Fsrtimer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftdecker91%2Fsrtimer/lists"}