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

intervals-composite

v1.0.0

Published

simplifies working with individual and composite intervals in an application.

Downloads

4

Readme

intervals-composite

build:? npm npm npm

Encapsulate javascript .setInterval & .clearInterval into an Interval class. It also adds an IntervalComposite that simplifies working with multiple intervals in an application.

Table of Contents

install

npm install --save intervals-composite

API

require

const { Interval, IntervalComposite } = require('intervals-composite');

import

import { Interval, IntervalComposite } from 'intervals-composite';

Interval

Example
const interval = new Interval({
  cb: () => console.log('test'),
  ms: 3000,
  label: 'test-interval'
});

// OR, if you have the callback in another object 

const handler = {
  someFunction: () => console.log('test')
};

const interval = new Interval({
  cb: handler.someFunction,
  ms: 3000,
  label: 'test-interval'
});

gets the interval label.

Example
console.log(interval.getLabel()); // 'test-interval'

.getMs()

gets the interval ms.

Example
console.log(interval.getMs()); // 3000

.getCb()

gets the interval callback.

Example
console.log(interval.getCb()); // [Function: someFunction]

starts the interval.

Example
interval.start();

checks if the interval is running.

Example
console.log(interval.isRunning()); // true

/*
test
test
test
.
.
.
*/

clears the interval

Example
interval.clear();

console.log(interval.isRunning()); // false

IntervalComposite

Example

const dataLoaders = new IntervalComposite('data-loaders');

.add(interval)

adds an interval.

Example

dataLoaders.add(new Interval({
  cb: () => console.log('users'),
  ms: 7000,
  label: 'users' 
}));

dataLoaders.add(new Interval({
  cb: () => console.log('products'),
  ms: 3000,
  label: 'products' 
}));

dataLoaders.add(new Interval({
  cb: () => console.log('orders'),
  ms: 1000,
  label: 'orders' 
}));

.has(label)

checks if a label exists.

Example

console.log(dataLoaders.has('orders')); // true

gets an interval by its label.

Example
const ordersInterval = dataLoaders.get('orders');

console.log(ordersInterval.getLabel()); // orders
console.log(ordersInterval.isRunning()); // false

gets the composite label.

Example
console.log(dataLoaders.getLabel()); // data-loaders

.forEach(cb)

traverses the intervals.

Example
dataLoaders.forEach((interval) => {
  console.log(interval.getLabel());
});

/*
users
products
orders
*/

.filter(cb, label)

filters the intervals using a callback. It also accept an optional label to name the filtered composite.

Example
const slowLoaders = dataLoaders.filter((i) => i.getMs() > 1000, 'slow-intervals');

console.log(slowLoaders.getLabel()); // slow-intervals

slowLoaders.forEach((interval) => console.log(interval.getLabel()));
/*
users
products
*/

.toArray()

converts the composite into an array of intervals.

Example
console.log(dataLoaders.toArray().map(i => i.getLabel()));

/*
[ 'users', 'products', 'orders' ]
*/

.count()

gets the count of intervals.

Example
console.log(dataLoaders.count()); // 3

starts the intervals

Example
dataLoaders.start();

/*
orders
orders
products
orders
orders
orders
products
orders
users
orders
orders
*/

checks if the intervals are started.

Example
console.log(dataLoaders.isRunning()); // true

clears the intervals.

Example
dataLoaders.clear();
console.log(dataLoaders.isRunning()); // false

Build

grunt build

License

The MIT License. Full License is here