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

afo-ratelimit

v0.1.1

Published

Function Rate Limiter

Downloads

9

Readme

RateLimit

Queue up a bunch of functions, and let them execute based on invocations per millisecond rules.

var RateLimit = require('../index.js');

var rl = new RateLimit({
	checkInterval: 500,
	rates: [
		{limit: 1, per: 1000}, // 1 per second
		{limit: 5, per: 1000*30}, // 5 per 30-seconds
		{limit: 9, per: 1000*60}, // 9 per minute
		{limit: 200, per: 1000*60*60}, // 200 per hour
		{limit: 1000, per: 1000*60*60*24} // 1000 per day
	]
});

function logTime() {
	var hrtime = process.hrtime();
	console.log('example: timestamp %s, hrtime %dns',new Date().toISOString(),hrtime[0]*1e9+hrtime[1]);
}

for ( var i = 0; i < 20; i++ ) {
	rl.addToQueue('unique queue ID',logTime);
}

/*
example: timestamp 2015-10-06T12:49:38.833Z, hrtime 1162041936436785ns
example: timestamp 2015-10-06T12:49:40.790Z, hrtime 1162043933269469ns
example: timestamp 2015-10-06T12:49:41.791Z, hrtime 1162044934806502ns
example: timestamp 2015-10-06T12:49:42.792Z, hrtime 1162045935057011ns
example: timestamp 2015-10-06T12:49:43.793Z, hrtime 1162046935985948ns
example: timestamp 2015-10-06T12:50:08.806Z, hrtime 1162071949138051ns
example: timestamp 2015-10-06T12:50:09.806Z, hrtime 1162072949668703ns
example: timestamp 2015-10-06T12:50:10.806Z, hrtime 1162073949912099ns
example: timestamp 2015-10-06T12:50:11.807Z, hrtime 1162074950196589ns
example: timestamp 2015-10-06T12:50:38.822Z, hrtime 1162101964641538ns
example: timestamp 2015-10-06T12:50:39.823Z, hrtime 1162102965398596ns
example: timestamp 2015-10-06T12:50:40.823Z, hrtime 1162103965747886ns
example: timestamp 2015-10-06T12:50:41.823Z, hrtime 1162104965813871ns
example: timestamp 2015-10-06T12:50:42.824Z, hrtime 1162105966210181ns
example: timestamp 2015-10-06T12:51:08.838Z, hrtime 1162131980659081ns
example: timestamp 2015-10-06T12:51:09.839Z, hrtime 1162132981490818ns
example: timestamp 2015-10-06T12:51:10.839Z, hrtime 1162133981739746ns
example: timestamp 2015-10-06T12:51:11.840Z, hrtime 1162134982114324ns
*/