{"id":27294017,"url":"https://github.com/oscarpalmer/timer","last_synced_at":"2025-07-09T19:33:41.277Z","repository":{"id":57700236,"uuid":"508774883","full_name":"oscarpalmer/timer","owner":"oscarpalmer","description":"A better timer?","archived":false,"fork":false,"pushed_at":"2025-06-10T12:43:06.000Z","size":697,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-10T12:50:39.915Z","etag":null,"topics":["requestanimationframe","setinterval","settimeout","timer"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oscarpalmer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-06-29T16:51:54.000Z","updated_at":"2025-06-10T12:43:10.000Z","dependencies_parsed_at":"2025-04-11T22:45:44.570Z","dependency_job_id":"5a2b573f-5f04-4dcf-898d-6c688ce1dcf1","html_url":"https://github.com/oscarpalmer/timer","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"6fd0372ff38811d5dffeb5dbd2da0d0903b622ce"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/oscarpalmer/timer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oscarpalmer%2Ftimer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oscarpalmer%2Ftimer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oscarpalmer%2Ftimer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oscarpalmer%2Ftimer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oscarpalmer","download_url":"https://codeload.github.com/oscarpalmer/timer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oscarpalmer%2Ftimer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264502483,"owners_count":23618614,"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":["requestanimationframe","setinterval","settimeout","timer"],"created_at":"2025-04-11T22:45:37.866Z","updated_at":"2025-07-09T19:33:41.237Z","avatar_url":"https://github.com/oscarpalmer.png","language":"TypeScript","readme":"# Timer\n\n[![npm](https://badge.fury.io/js/@oscarpalmer%2Ftimer.svg)](https://www.npmjs.com/package/@oscarpalmer/timer) [![Tests](https://github.com/oscarpalmer/timer/actions/workflows/test.yml/badge.svg)](https://github.com/oscarpalmer/timer/actions/workflows/test.yml)\n\nA better solution for timeout- and interval-based timers.\n\n## Installation\n\nTimer is available on _npm_ as [`@oscarpalmer/timer`](https://www.npmjs.com/package/@oscarpalmer/timer) to be bundled with your awesome projects.\n\n## Getting started\n\nThis is fairly lightweight package, so hopefully you'll be up and running in seconds :blush:\n\n### Examples\n\nThe timers can be called with nice helper methods, which also auto-starts the timers:\n\n```typescript\nimport {repeat, wait} from '@oscarpalmer/timer';\n\nconst waited = wait(waitedCallback);\nconst repeated = repeat(repeatedCallback, 10);\n```\n\nOr they can be created using the `new`-keyword, but without being auto-started:\n\n```typescript\nimport {Timer} from '@oscarpalmer/timer';\n\nconst waited = new Timer(waitedCallback);\nconst repeated = new Timer(repeatedCallback, 10);\n```\n\n## Parameters\n\nWhen creating a _Timer_, either with the new `new`-keyword or using the functions, you can configure the timer with a few parameters:\n\n|Parameter|Description|\n|--------:|:----------|\n|`callback`|Callback function to be invoked for each run that are __required__ for all timers.\u003cbr\u003eFor more information on callbacks, please read [the callbacks section](#callbacks).|\n|`count`|How many times the timer should run.\u003cbr\u003eIf no value is provided, it will default to `1` when using the `new`-keyword and the `wait`-method, but throws an error for the `repeat`-method.|\n|`time`|How many milliseconds between each invokations of the provided callback.\u003cbr\u003eDefaults to `0`, which is not really _0_ milliseconds, but close enough :wink:|\n|`after`|A callback to run after the timer finishes, both when cancelled and completed.\u003cbr\u003eIf _count_ is greater than `1` and _after_ __is not__ `undefined`, a function is expected.|\n\n## Methods and properties\n\nAn instance of _Timer_ also has a few helpful methods and properties:\n\n|Name|Type|Description|\n|---:|----|:----------|\n|`active`|_Property_|A `boolean` value to check if the timer is running|\n|`finished`|_Property_|A `boolean` value to check if the timer was able to finish|\n|`start()`|_Method_|Starts the timer.\u003cbr\u003eNecessary when creating a timer using the class syntax _(e.g. `new Waited...`)_, but helpful when the timer needs to be started at other times, as well.|\n|`stop()`|_Method_|Stops the timer|\n|`restart()`|_Method_|Restarts the timer|\n\n## Callbacks\n\nCallbacks for both waited and repeated timers receive one parameter:\n\n```typescript\nfunction callback(index) {\n\t// 'index' is the current step\n\t// starts at 0, goes up to a maximum of count - 1\n\t// for this example: 0 → 9\n};\n```\n\nWhen you create a repeated timer, you can also provide a callback to run when the timer stops, as below:\n\n```typescript\nfunction after(finished: boolean) {\n\t// Let's do something fun!\n}\n\nrepeat(() =\u003e {}, 10, after);\n```\n\nThe `finished`-parameter for the `after`-function can be used to determine if the timer was stopped manually, or if it was able to finish its work.\n\n## License\n\n[MIT licensed](LICENSE), natch :wink:\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foscarpalmer%2Ftimer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foscarpalmer%2Ftimer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foscarpalmer%2Ftimer/lists"}