npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

v_core_timers

v0.1.4

Published

Simple to use Timers with Events for node and web.

Downloads

12

Readme

v_core_timers

Simple to use Timers with Events for node and web.

📑 How to use

const { V_Watch } = require('v_core_timers');

Create a new timers controller

const v_watch = new V_Watch();

Add a new timer

Create a task/timer by giving it name, interval and a callback function.

// Simple Task
v_watch.new('my_timer', 1000, () => console.log('timer is running'));

// or
v_watch.create('my_timer', 1000, () => console.log('timer is running'));

Create a disabled/inactive tasks (default is active/enabled)

v_watch.create('my_timer', 1000, () => console.log('timer is running'), false);

🔻 This only adds the timer to the list of timers, it does not start it.

Start a timer

v_watch.start('my_timer');

Has a timer

Check if the timer exists.

v_watch.has('my_timer');

🔻 This will return true even if the timer is not running.

Is Active Check

Just a passthrough to get the status of it from the timer object.

v_watch.isActive('my_timer');

Stop a timer

Stop a task/timer by name. This will not remove it from tasks list.

v_watch.stop('my_timer');

Delete a timer

Delete a timer. Stops it if it is running.

v_watch.delete('my_timer');

End all timers

This will stop all tasks[timers] and clear the task list.

v_watch.end();

Stats

Get some useful information about the timers.

v_watch.stats();

EXAMPLE OUTPUT

{
  disabledTasksCount: 1,
  activeTasksCount: 1,
  totalTasksCount: 2,
  tasks: [
    { name: 'TestTask', active: false, interval: 1 },
    { name: 'SecondaryTask', active: true, interval: 10 }
  ]
}

🎪 Events

New / Created a timer

v_watch.on('new', async (key) => console.log('New timer: '+ key));

Delete / Removed a timer

v_watch.on('delete', async (key) => console.log('deleted timer: '+ key));

End / Stopped all timers

v_watch.on('end', async () => console.log('Ended All Timers'));

Timer Started

v_watch.on('start', async (key) => console.log('Started Timer: '+ key));

Timer Stopped

v_watch.on('stop', async (key) => console.log('Ended Timer: '+ key));

Run / Executed

v_watch.on('run', async (key) => console.log('Run Timer: ' + key));

Interval Change

v_watch.on('intervalChange', async (data) => console.log(data.key + ' interval changed to ' + data.interval));

🥒 Inner Timer Object Manual Usage

Get it

const { V_Core_Timer } = require('v_core_timers');

Create a new basic interval timer object

const v_timer = new V_Core_Timer({ cb: () => console.log('timer is running'), interval: 1000, autoStart: true });

Begin if not active

v_timer.begin();

Alias: .start()

End if active

v_timer.end();

Alias: .stop()

Set different Interval for a timer

v_timer.setInterval(2000);

Alias: .changeInterval()

Get Status of a timer

v_timer.status();

Alias: .isActive()

Run a callback manually

v_timer.run();

Alias: .execute()

🎪 Events

Begin / Start

v_timer.on('begin', async () => console.log('started'));

End / Stop

v_timer.on('end', async () => console.log('started'));

Run / Executed

v_timer.on('run', async () => console.log('started'));

📏 Helper vTime

Get milliseconds from...

const { vTime } = require('v_core_timers');

Seconds

vTime.seconds(value); //> (value * 1000);

Minutes

vTime.minutes(value); //> vTime.seconds(value * 60);

Hours

vTime.hours(value); //> vTime.minutes(value * 60);

Days

vTime.days(value); //> vTime.hours(value * 24);

Weeks

vTime.weeks(value); //> vTime.days(value * 7); 

Months

vTime.months(value); //> vTime.days(value * 30); 

Years

vTime.years(value); //> vTime.days(value * 365); 

NOTE: value is 1 by default.

SAMPLE vTime Usage

Just a basic logging to console.

const { vTime } = require('v_core_timers');
(async () => {
  console.log(await vTime.seconds(2)); //> 2000
  console.log(await vTime.minutes(2)); //> 12000
  console.log(await vTime.hours(2)); //> 7200000
  console.log(await vTime.days(2)); //> 172800000 
  console.log(await vTime.weeks(2)); //> 1209600000
  console.log(await vTime.months(2)); //> 2592000000
  console.log(await vTime.years(2)); //> 63072000000
})();