Coder Social home page Coder Social logo

key-interval's Introduction

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

key-interval's People

Contributors

vcz-gray avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.