New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

timerpro

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timerpro

Manage intervals and timeouts like a pro

latest
npmnpm
Version
1.0.4
Version published
Maintainers
0
Created
Source

timerPro

A lightweight JavaScript module for managing setTimeout and setInterval timers. This module works in both Node.js and the browser, providing an easy-to-use API for creating, clearing, and managing timers.

Installation

You can install timerpro via npm:

npm install timerpro

Or simply include it in your project by adding the JavaScript file.

Usage

The timerpro module allows you to set and manage named setTimeout and setInterval timers. You can also clear, reset, and clear all timers using the provided methods.

Importing the Module

Node.js

const timerPro = require('timerpro');

Browser

Include the script in your HTML file:

<script src="https://cdn.jsdelivr.net/npm/timerpro/dist/timerpro.min.js"></script>

Then, access it via timerPro:

timerPro.setTimeout("example", () => console.log("Hello!"), 1000);

API Methods

timerPro.setTimeout(name, func, delay, args = [])

Creates a new setTimeout timer.

  • Parameters:

    • name (string): The timer name.
    • func (function): The function to execute after the delay.
    • delay (number): Time in milliseconds before the function is executed.
    • args (array): Optional arguments to pass to the function.
  • Returns: The ID of the created setTimeout.

timerPro.setInterval(name, func, delay, args = [])

Creates a new setInterval timer.

  • Parameters:

    • name (string): The timer name.
    • func (function): The function to execute repeatedly.
    • delay (number): Time in milliseconds between function executions.
    • args (array): Optional arguments to pass to the function.
  • Returns: The ID of the created setInterval.

timerPro.clearTimeout(name)

Clears a setTimeout timer by name. If name is not provided, all setTimeout timers will be cleared.

  • Parameters:
    • name (string, optional): The timer name.

timerPro.clearInterval(name)

Clears a setInterval timer by name. If name is not provided, all setInterval timers will be cleared.

  • Parameters:
    • name (string, optional): The timer name.

timerPro.clearAll()

Clears all setTimeout and setInterval timers.

Example

Here's an example demonstrating how to use timerpro:

const timerPro = require('timerpro');

// Set a timeout
timerPro.setTimeout("MyTimeout", (i, msg) => {
    console.log(`${i} - ${msg}`);
}, 5000, [1, "Hello World!"]);

// Set an interval
timerPro.setInterval("MyInterval", (i, msg) => {
    console.log(`${i} - ${msg}`);
}, 2000, [1, "Repeating Message"]);

// Clear the timeout
timerPro.clearTimeout("MyTimeout");

// Clear the interval
timerPro.clearInterval("MyInterval");

// Clear all timers
timerPro.clearAll();

Keywords

setTimeout

FAQs

Package last updated on 15 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts