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

key-interval

v0.5.1

Published

You can set or clear time interval with key. It's like setInterval and clearInterval. You must use a keyword 'new' because it is class object.

Downloads

10

Readme

key-interval

Hello! This is a module for setInterval as class! Enjoy it!

Install

npm i key-interval

Usage

The package exports the KeyIntervalclass as default export.

const KeyInterval = require('key-interval');

There are functions to help you.

KeyInterval.setTimeInterval(callback, values, key[, time])

All of parameters are required except time (default is 1000 msec).

Params:

  • callback(required): callback function.
  • values(required): An array which has params for callback.
  • key(required): The key for managing each interval instances.
  • time(optional): The time to set interval. (default 1000 msec)

KeyInterval.setEndTime(key[, time])

The key is required and time is optional (default is 1000 msec).

Params:

  • key(required): The key for stopping an running interval of instance.
  • time(optional): The time to set interval. (default 1000 msec)

KeyInterval.pauseTimeInterval(key)

Params:

  • key(required): The key to pause an running interval.

KeyInterval.restartTimeInterval(key[, time[, callback[, values]]])

All of parameters are optional except key. Especially, default of time is 1000 msec.

Params:

  • key(required): The key to restart interval of instance.
  • time(optional): The time to set interval. (default 1000 msec)
  • callback(optional): new callback function to set at exist key of puased interval.
  • values(optional): An new array which has params for callback.

* If you want to change callback or parameters for callback, you can set callback or values using this method.

KeyInterval.clearTimeInterval(key)

Clear interval using key in instance. All data will be deleted.

Params:

  • key(required): The key to clear an running interval.

KeyInterval.clearAllInterval()

Clear all interval of instance.

Params: no exist

Example

const KeyInterval = require('key-interval');

const runTest = () => {
	const SETTIME = 1000;
	const ENDTIME = 3500;
	const TEST_A = 'testA';
	const TEST_B = 'testB';

	const testA = new KeyInterval();
	const testB = new KeyInterval();
	const cb = (str) => console.log(str);

	testA.setTimeInterval(cb, [TEST_A], TEST_A, SETTIME);
	testB.setTimeInterval(cb, [TEST_B], TEST_B, SETTIME);

	testA.setEndTime(TEST_A, ENDTIME);
	testB.setEndTime(TEST_B, ENDTIME);
};

runTest();

RUN TEST

You can test this module with script npm test or npm run test.

node node_modules/key-interval/test.js