
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
ng2-simple-timer
Advanced tools
A simple timer service for Angular, base on RxJS.
Name/ID(string) base API. RxJS object not exposed.
ng2-simple-timer uses to Angular CLI starting 8.2.0. New repository github.com/J-Siu/ng2-simple-timer-lib contains both library and example.
Version < 8.2.0 are in old repository github.com/J-Siu/ng2-simple-timer
npm install ng2-simple-timer
ng2-simple-timer is implemented as Angular injectable service name SimpleTimer.
Add SimpleTimer into module providers (eg. app.module.ts.
import { SimpleTimer } from 'ng2-simple-timer';
@NgModule({
providers: [SimpleTimer]
})
import {SimpleTimer} from 'ng2-simple-timer';
export class ChildComponent {
constructor(private st: SimpleTimer) { }
}
Create timer with optional delay start. Unit in second.
newTimer(name: string, sec: number, delay: boolan = false): boolean
newTimer will create timer name and tick every 'number' of seconds. Creating timer with the same name multiple times has no side effect.
delay: If set to true will delay the 1st tick till the end of the first interval.
Return false if timer name exist.
this.st.newTimer('5sec', 5);
this.st.newTimer('5sec', 5, true);
Create timer with optional customer delay. Unit in second.
newTimerCD(name: string, sec: number, delay: number = 0): boolean
newTimerCD will create timer name and tick every 'number' of seconds. Creating timer with the same name multiple times has no side effect.
delay: If set to X, will delay the 1st tick for X seconds.
Return false if timer name exist.
this.st.newTimerCD('5sec', 5);
this.st.newTimerCD('5sec', 5, 10);
Create High Resolution timer with optional customer delay. Unit in millisecond.
newTimerHR(name: string, msec: number, delay: number = 0): boolean
newTimerHR will create timer name and tick every 'number' of milliseconds. Creating timer with the same name multiple times has no side effect.
delay: If set to X, will delay the 1st tick for X milliseconds.
Return false if timer name exist.
this.st.newTimerHR('5ms', 5);
this.st.newTimerHR('5ms', 5, 10);
delTimer(name: string): boolean
delTimer will delete timer name
Return false if timer name does not exist.
this.st.delTimer('5sec');
getTimer(): string[]
getTimer will return all timer name in string array.
let t: string[] = this.st.getTimer();
getSubscription(): string[]
getSubscription will return all subscription id in string array.
let ids: string[] = this.st.getSubscription();
subscribe(name: string, callback: () => void): string
subscribe will link callback function to timer name. Whenever timer name tick, callback will be invoked.
Return subscription id(string).
Return empty string if timer name does not exist.
Either use Lambda(fat arrow) in typescript to pass in callback or bind this to another variable in javascript, else this scope will be lost.
Lambda(fat arrow)
counter: number = 0;
timerId: string;
ngOnInit() {
// lazy mode
this.timerId = this.st.subscribe('5sec', () => this.callback());
}
callback() {
this.counter++;
}
unsubscribe(id: string): boolean
unsubscribe will cancel subscription using id.
unsubscribe will return false if id is undefined or id is not found in subscription list.
timerId: string;
this.st.unsubscribe(this.timerId);
You will need Angular CLI to build the library and run the example.
git clone https://github.com/J-Siu/ng2-simple-timer-lib.git
cd ng2-simple-timer-lib
npm i
ng build ng2-simple-timer
ng serve --open
SimpleTimer only"noImplicitAny": falsepeerDependencies, it is modified as follow:
"peerDependencies": { "@angular/core": ">=2.4.0" }subscribe(name: string, callback: (any) => void): string change to subscribe(name: string, callback: () => void): stringsubscribedelay option for newTimernewTimernewTimerCD Create timer with optional custom delay start. Unit in second.newTimerHR Create timer with optional custom delay start. Unit in millisecond.The MIT License
Copyright (c) 2021
Permission 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:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE 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.
FAQs
Angular simple timer service
We found that ng2-simple-timer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.