{"id":15184668,"url":"https://github.com/j-siu/ng2-simple-timer","last_synced_at":"2025-10-01T23:30:50.193Z","repository":{"id":132734762,"uuid":"65207146","full_name":"J-Siu/ng2-simple-timer","owner":"J-Siu","description":"A simple timer service for Angular 2, base on RxJS.","archived":true,"fork":false,"pushed_at":"2022-05-16T16:58:18.000Z","size":37,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-09-28T17:21:36.948Z","etag":null,"topics":["angular","angular-2","angular2","angular2-service","ng2","simpletimer","timer","timer-service"],"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/J-Siu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","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}},"created_at":"2016-08-08T13:39:22.000Z","updated_at":"2023-01-28T00:45:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"52d28b22-8a28-4593-b48d-ba0e7939ceed","html_url":"https://github.com/J-Siu/ng2-simple-timer","commit_stats":{"total_commits":45,"total_committers":3,"mean_commits":15.0,"dds":"0.19999999999999996","last_synced_commit":"98a07f73e15bc23ce8c235a884cbd55abe60e084"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J-Siu%2Fng2-simple-timer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J-Siu%2Fng2-simple-timer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J-Siu%2Fng2-simple-timer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J-Siu%2Fng2-simple-timer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/J-Siu","download_url":"https://codeload.github.com/J-Siu/ng2-simple-timer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234909086,"owners_count":18905504,"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":["angular","angular-2","angular2","angular2-service","ng2","simpletimer","timer","timer-service"],"created_at":"2024-09-27T17:21:38.810Z","updated_at":"2025-10-01T23:30:44.945Z","avatar_url":"https://github.com/J-Siu.png","language":"TypeScript","readme":"# Angular Simple Timer [![Paypal donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/donate/?business=HZF49NM9D35SJ\u0026no_recurring=0\u0026currency_code=CAD)\n\nA simple timer service for Angular, base on RxJS.\n\nName/ID(string) base API. RxJS object not exposed.\n\n\u003e To enable faster update, ng2-simple-timer switched to Angular CLI starting 8.2.0 and use new repository https://github.com/J-Siu/ng2-simple-timer-lib/\n\u003e\n\u003e Project contains both library and example.\n\u003e\n\u003e All version \u003c 8.2.0 are in old repository https://github.com/J-Siu/ng2-simple-timer/\n\n### Table Of Content\n\u003c!-- TOC --\u003e\n\n- [Version](#version)\n- [Install](#install)\n- [Usage](#usage)\n  - [\"noImplicitAny\": false](#noimplicitany-false)\n  - [Import into Angular2 RC5+ application typescript](#import-into-angular2-rc5-application-typescript)\n  - [API](#api)\n      - [newTimer](#newtimer)\n      - [delTimer](#deltimer)\n      - [getTimer](#gettimer)\n      - [getSubscription](#getsubscription)\n      - [subscribe](#subscribe)\n      - [unsubscribe](#unsubscribe)\n- [Example](#example)\n- [Contributors](#contributors)\n- [Changelog](#changelog)\n- [License](#license)\n\n\u003c!-- /TOC --\u003e\n\n### Version\n\n- For Angular 2.x.x, please use 1.3.1.\n- For Angular 4.x.x, please use 1.3.5.\n- For Angular 6.x.x, please use 6.0.0.\n\n### Install\n\n```\nnpm install ng2-simple-timer\n```\n\n### Usage\n\n#### \"noImplicitAny\": false\n\nMust set `\"noImplicitAny\": false` in application __tsconfig.json__. Else following error may occur at build time:\n\n    error TS7006: Parameter 'any' implicitly has an 'any' type\n\n#### Import into Angular2 RC5+ application (typescript)\n\n`ng2-simple-timer` is implemented as Angular injectable service name __SimpleTimer__.\n\n__For module using SimpleTimer__\n\nAdd `SimpleTimer` into module providers (eg. [app.module.ts](https://github.com/J-Siu/ng2-simple-timer-example/blob/master/app/app.module.ts)).\n\n```javascript\nimport { SimpleTimer } from 'ng2-simple-timer';\n\n@NgModule({\n\tproviders: [SimpleTimer]\n})\n```\n\n__For each child component using SimpleTimer__\n\n```javascript\nimport {SimpleTimer} from 'ng2-simple-timer';\n\nexport class ChildComponent {\n\n\tconstructor(private st: SimpleTimer) { }\n\n}\n```\n\n#### API\n\n###### newTimer\n\n`newTimer(name: string, sec: number, delay: boolean = false): boolean`\n\n`newTimer` will create timer `name` and tick every 'number' of seconds. Creating timer with the same name multiple times has no side effect.\n\n`delay`: If set to true will delay the 1st tick till the end of the first interval.\n\nReturn `false` if timer `name` exist.\n\n```javascript\nthis.st.newTimer('5sec', 5);\nthis.st.newTimer('5sec', 5, true);\n```\n\n###### delTimer\n\n`delTimer(name: string): boolean`\n\n`delTimer` will delete timer `name`\n\nReturn `false` if timer `name` does not exist.\n\n```javascript\nthis.st.delTimer('5sec');\n```\n\n###### getTimer\n\n`getTimer(): string[]`\n\n`getTimer` will return all timer name in string array.\n```javascript\nlet t: string[] = this.st.getTimer();\n```\n\n###### getSubscription\n\n`getSubscription(): string[]`\n\n`getSubscription` will return all subscription id in string array.\n```javascript\nlet ids: string[] = this.st.getSubscription();\n```\n\n###### subscribe\n\n`subscribe(name: string, callback: () =\u003e void): string`\n\n`subscribe` will link `callback` function to timer `name`. Whenever timer `name` tick, `callback` will be invoked.\n\nReturn subscription id(string).\n\nReturn empty string if timer `name` does not exist.\n\nEither use Lambda(fat arrow) in typescript to pass in callback or bind `this` to another variable in javascript, else `this` scope will be lost.\n\n__Lambda(fat arrow)__\n```javascript\ncounter: number = 0;\ntimerId: string;\n\nngOnInit() {\n\t// lazy mode\n\tthis.timerId = this.st.subscribe('5sec', () =\u003e this.callback());\n}\n\ncallback() {\n\tthis.counter++;\n}\n```\n\n###### unsubscribe\n\n`unsubscribe(id: string): boolean`\n\n`unsubscribe` will cancel subscription using `id`.\n\n`unsubscribe` will return false if `id` is undefined or `id` is not found in subscription list.\n\n```javascript\ntimerId: string;\n\nthis.st.unsubscribe(this.timerId);\n```\n\n### Example\n\nGitHub: [ng2-simple-timer-example](https://github.com/J-Siu/ng2-simple-timer-example)\nPlunker: [Angular2 Simple Timer Example](http://embed.plnkr.co/HaTd8q/)\n\n### Contributors\n\n* [John Sing Dao Siu](https://github.com/J-Siu)\n\n\n### Changelog\n\n* 0.2.0\n\t- Angular 2 RC4\n* 0.2.2\n\t- API change\n\t\t- newTimer() return boolean\n\t\t- subscribe() - lazy mode removed\n\t- API new\n\t\t- delTimer()\n* 0.2.3\n\t- Support Angular 2 RC5\n* 0.2.4\n\t- Remove module, export `SimpleTimer` only\n* 1.2.4\n\t- Support Angular 2.0.0\n\t- Clean up package\n* 1.2.5\n\t- Add Plunker example\n* 1.2.7\n\t- Support Angular 2.4.*\n\t- Replace node-uuid with uuid\n* 1.2.8\n\t- Change uuid as dependency\n* 1.2.9\n\t- Replace uuid with angular2-uuid\n* 1.3.0\n\t- Add instruction for `\"noImplicitAny\": false`\n\t- Clean up package\n* 1.3.1\n\t- Due to the rapid release cycle of Angular, to minimize update purely due to `peerDependencies`, it is modified as follow:\n\t\t-\t`\"peerDependencies\": { \"@angular/core\": \"\u003e=2.4.0\" }`\n* 1.3.2\n\t- Update package.json for Angular 4.3.1. For Angular 2.x.x, please use 1.3.1 or earlier.\n\t- Fix readme example code syntax error.\n\t- API change:\n\t\t- `subscribe(name: string, callback: (any) =\u003e void): string` change to `subscribe(name: string, callback: () =\u003e void): string`\n* 1.3.3\n\t- Fix readme example code for `subscribe`\n* 1.3.4\n\t- Add `delay` option for `newTimer`\n* 1.3.5\n\t- Bugfix for `newTimer`\n* 6.0.0\n\t- Update for Angular 6.x, which include moving from RxJS 5.1 to 6.0\n\t- Update version to match major version of Angular\n\n### License\n\nThe MIT License\n\nCopyright (c) 2018\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":["https://www.paypal.com/donate/?business=HZF49NM9D35SJ\u0026no_recurring=0\u0026currency_code=CAD"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj-siu%2Fng2-simple-timer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fj-siu%2Fng2-simple-timer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj-siu%2Fng2-simple-timer/lists"}