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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@limity/core

v0.1.3

Published

Framework-agnostic rate limiting core

Readme

@limity/core

Framework-agnostic rate limiting core. Use this directly if you need rate limiting in any JavaScript/TypeScript application.

Installation

npm install @limity/core
# or
pnpm add @limity/core
# or
yarn add @limity/core

Quick Start

import { rateLimit } from '@limity/core';

const result = await rateLimit({
  key: 'user:123',
  limit: 100,
  window: 60,
});

if (!result.allowed) {
  throw new Error('Too many requests');
}

console.log(`Requests remaining: ${result.remaining}`);
console.log(`Resets at: ${new Date(result.reset * 1000)}`);

How It Works

Memory Mode (Default)

Stores rate limit counters in memory. Perfect for:

  • Single-server applications
  • Development and testing
  • Low-traffic applications
const result = await rateLimit({
  key: 'user:123',
  limit: 100,
  window: 60,
});

Hosted Mode (With API Key)

Uses a remote hosted service. Perfect for:

  • Multi-server deployments
  • Serverless/edge functions
  • High-traffic applications
  • Shared rate limiting across services
export LIMITY_API_KEY=your_api_key

Then use the same code - it automatically switches to hosted mode:

const result = await rateLimit({
  key: 'user:123',
  limit: 100,
  window: 60,
});
// Uses hosted API, falls back to memory on failure

API Reference

rateLimit(options)

Checks if a request should be allowed based on rate limits.

Parameters:

interface RateLimitOptions {
  key: string;       // Unique identifier (user ID, IP, etc.)
  limit?: number;    // Max requests per window (default: 100)
  window?: number;   // Window size in seconds (default: 60)
}

Returns:

interface RateLimitResult {
  allowed: boolean;  // True if request is allowed
  remaining: number; // Requests remaining in window
  reset: number;     // Unix timestamp when window resets
}

Examples

Rate Limit by User ID

const userId = 'user:456';
const result = await rateLimit({
  key: userId,
  limit: 50,
  window: 60,
});

if (!result.allowed) {
  console.log(`Try again in ${result.reset - Math.floor(Date.now() / 1000)}s`);
}

Rate Limit by IP Address

const ipAddress = '192.168.1.1';
const result = await rateLimit({
  key: `ip:${ipAddress}`,
  limit: 100,
  window: 60,
});

Different Limits for Different Endpoints

// Strict limit for login attempts
const loginResult = await rateLimit({
  key: `login:${email}`,
  limit: 5,
  window: 300, // 5 per 5 minutes
});

// Relaxed limit for API calls
const apiResult = await rateLimit({
  key: `api:${userId}`,
  limit: 1000,
  window: 60,
});

Configuration

Environment Variables

  • LIMITY_API_KEY (optional) - API key for hosted mode. If not set, uses memory mode.
export LIMITY_API_KEY=your_api_key

Default Values

  • Limit: 100 requests
  • Window: 60 seconds
  • Mode: Memory (no API key needed)

When to Use

✅ Use @limity/core when:

  • You need simple rate limiting logic
  • You're building a Node.js library or SDK
  • You want full control over rate limiting
  • You're building for a single environment

🔗 Use @limity/node instead if:

  • You're building an Express.js application
  • You want automatic IP-based rate limiting

🌐 Use @limity/edge instead if:

  • You're deploying to edge functions (Vercel, Cloudflare, etc.)
  • You need rate limiting in serverless environments

Performance

  • Memory mode: ~0.1ms per check (in-process)
  • Hosted mode: ~50-200ms per check (network + API)