Giter Site home page Giter Site logo

ftonato / set-interval-manager Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 171 KB

A simple utility for managing intervals without having to manually track interval IDs. Easily start and stop intervals using a unique identifier.

Home Page: https://www.npmjs.com/package/set-interval-manager

License: MIT License

TypeScript 97.57% JavaScript 2.43%
clearinterval interval setinterval timer interval-manager

set-interval-manager's Introduction

set-interval-manager

npm version GitHub license

A utility class for managing intervals created by setInterval.

Installation

You can install the package using npm:

npm install set-interval-manager

Examples

// ES6 import
import SetInterval from 'set-interval-manager';

// (or) CommonJS require
const SetInterval = require('set-interval-manager');


const mockFn = () => 'set-interval-manager';

// --- (start + clear) ---

SetInterval.start(mockFn, 1000, 'basic-example');

SetInterval.clear('basic-example');

// --- (start + clearAll) ---

SetInterval.start(mockFn, 1000, 'interval-one');
SetInterval.start(mockFn, 1500, 'interval-two');
SetInterval.start(mockFn, 2000, 'interval-three');

SetInterval.clearAll();

// --- (start + listAll) ---

SetInterval.start(mockFn, 1000, 'interval-one');
SetInterval.start(mockFn, 1500, 'interval-two');

SetInterval.listAll(); // => ['interval-one', 'interval-two']

SetInterval.clear('interval-one');

SetInterval.listAll(); // => ['interval-two']

API

SetInterval

The main class exported by the package.

start(fn: IntervalFn, interval: number, key: string): void

Starts a new interval that calls the specified function at the specified interval.

  • fn (required): The function to call.
  • interval (required): The interval (in milliseconds) at which to call the function.
  • key (required): A unique string identifier for the interval.

clear(key: string): void

Stops the interval with the specified key.

  • key (required): The string identifier for the interval to stop.

clearAll(): void

Stops all intervals managed by this utility.

listAll(): string[]

Gets an array of all keys currently being used to manage intervals.


License

This package is released under the MIT License.

set-interval-manager's People

Contributors

ftonato avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.