1.0.2 • Published 4 years ago

basic_timers v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Basic timers

basic_timers provides timers that run like a stopwatch. Can be used in any JavaScript project where timers are needed.

Installation

To install the most recent stable version:

Using NPM:
npm i basic_timers

Types of Timers

Runs indefinitely until end() method is executed.

Parameters:
Property Nametypedescriptiondefault
on_startFunctionFunction to be ran when timer startsnull
on_endFunctionFunction to be ran when timer endsnull
on_updateFunctionFunction to be ran every time timer updatesnull
on_pauseFunctionFunction to be ran every time timer is pausednull
on_resumeFunctionFunction to be ran every time timer is resumednull
update_interval_rateintMilliseconds between checking for update10
const on_start = () => console.log("start");
const on_end = () => console.log("end");
const timer = new Timer({
  on_start,
  on_end,
  update_interval_rate: 100,
});
Method / Attributedescription
timer.start()Starts timer
timer.pause()Pauses timer
timer.resume()Resumes a paused timer
timer.end()Ends timer
timer.get_time()Get total time elapsed
is_runningChecks if timer is running and returns boolean
is_pausedCheck if timer is paused and returns boolean

Runs for a fixed duration or until end() method is called.

Parameters: Extends Timer Class
Property Nametypedescriptiondefault
on_startFunctionFunction to be ran when timer startsnull
on_endFunctionFunction to be ran when timer endsnull
on_updateFunctionFunction to be ran every time timer updatesnull
on_pauseFunctionFunction to be ran every time timer is pausednull
on_resumeFunctionFunction to be ran every time timer is resumednull
update_interval_rateintMilliseconds between checking for update10
durationintMilliseconds timer will run until timer.end() is called automaticallyrequired
const on_start = () => console.log("start");
const on_end = () => console.log("end");
const timer = new FixedTimer({
  on_start,
  on_end,
  duration: 1000 * 20,
  update_interval_rate: 100,
});
// timer will run for 20 seconds
Method / Attributedescription
timer.start()Starts timer
timer.pause()Pauses timer
timer.resume()Resumes a paused timer
timer.end()Ends timer
timer.get_time()Get total time elapsed
is_runningChecks if timer is running and returns boolean
is_pausedCheck if timer is paused and returns boolean

Runs indefinitely and times intervals.

Parameters: Extends Timer Class
Property Nametypedescriptiondefault
on_startFunctionFunction to be ran when timer startsnull
on_endFunctionFunction to be ran when timer endsnull
on_updateFunctionFunction to be ran every time timer updatesnull
on_pauseFunctionFunction to be ran every time timer is pausednull
on_resumeFunctionFunction to be ran every time timer is resumednull
update_interval_rateintMilliseconds between checking for update10
on_complete_intervalFunctionFunction to be run when an interval is completednull
const on_start = () => console.log("start");
const on_end = () => console.log("end");
const on_complete_interval = () => console.log("interval completed");
const timer = new IntervalTimer({
  on_start,
  on_end,
  on_complete_interval,
  duration: 1000 * 20,
  update_interval_rate: 100,
});
for (let i = 1; i < 4; i++) {
  setTimeout(() => timer.complete_interval(), i * 2000);
}
console.log(timer.get_all_completed_intervals());
Methoddescription
timer.start()Starts timer
timer.pause()Pauses timer
timer.resume()Resumes a paused timer
timer.end()Ends timer
timer.get_time()Get total time elapsed
is_runningChecks if timer is running and returns boolean
is_pausedCheck if timer is paused and returns boolean
timer.complete_interval()Adds total time for interval to list of completed intervals
timer.get_all_completed_intervals()Gets list of all completed intervals

Examples

Here's very basic example in action. You can see the code here. If you would like to add a project too this section feel free to make a PR or contact us.

Contributing

First of all, thank you! We appreciate the contribution!

When contributing to this repository, please first discuss the change you wish to make via issue, email, slack or any other method with the owners of this repository before making a change.

Please create an issue if you would like to request a feature or report a bug.

License

MIT

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.3.0

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago