@tomaszatoo/ngx-timer
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

⏱️ ngx-timer

Reactive, high-precision, animation-frame-based timers for Angular.
Easily count up or down with support for pause/resume, custom speeds, and completion handling.


📦 Installation

npm install @tomaszatoo/ngx-timer

🔗 Source

🚀 Features

  • 🎯 Count up or down
  • ⏸️ pause() / ▶️ resume() support
  • 🚀 Custom speed (e.g. 0.5 = slow-mo, 2 = fast-forward)
  • 📏 Optional maxValue (for CountUp) or duration (for CountDown)
  • 🧠 Smart emissions (no redundant updates)
  • 🧮 Emits both human-readable string and raw milliseconds
  • 🧼 Lightweight and zero-dependency

🧠 Interface

export interface TimerData {
  valueString: string;  // Formatted string like "00:42.381"
  valueNumber: number;  // Raw milliseconds
}

⬇️ CountDownTimerService

Usage

constructor(private countDown: CountDownTimerService) {}

ngOnInit() {
  const duration = 10_000; // 10 seconds

  this.countDown.start(duration, 's', 1); // (duration, resolution?, speed?)

  this.countDown.getObservable().subscribe({
    next: (data) => console.log('Countdown:', data.valueString),
    complete: () => console.log('Countdown complete!'),
  });
}

⬆️ CountUpTimerService

Usage

constructor(private countUp: CountUpTimerService) {}

ngOnInit() {
  const max = 60_000; // 1 minute

  this.countUp = new CountUpTimerService(max); // maxValue passed to constructor
  this.countUp.start(0, 's', 1); // (startFrom?, resolution?, speed?)

  this.countUp.getObservable().subscribe({
    next: (data) => console.log('CountUp:', data.valueString),
    complete: () => console.log('CountUp complete!'),
  });
}

⏯️ Pause / Resume / Speed Control

this.countUp.pause();
this.countUp.resume();
this.countUp.setSpeed(0.5); // Half speed

🔚 Stop & Restart

this.countDown.stop();
this.countDown.start(30_000); // Restart from 30 sec

🧪 Resolutions

Key Format Example
s 42.381
m 00:42.381
h 00:00:42.381
d 0d 00:00:42.381

Readme

Keywords

none

Package Sidebar

Install

npm i @tomaszatoo/ngx-timer

Weekly Downloads

0

Version

1.1.1

License

none

Unpacked Size

61.7 kB

Total Files

17

Last publish

Collaborators

  • tomas-zatoo