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 🙏

© 2025 – Pkg Stats / Ryan Hefner

libsql-ratelimiter

v0.0.2

Published

A simple rate limiter using libsql | turso

Readme

libsql-ratelimiter

A flexible rate-limiting library built on top of libSQL, providing multiple algorithms (fixed window, sliding window, and token bucket) to control how frequently actions can be performed.

Installation

npm install libsql-ratelimiter

Configuration

Environment variables can be used to set the configuration:

LIBSQL_URL=
LIBSQL_AUTH_TOKEN=

Basic Usage

import { createRateLimiter } from 'libsql-ratelimiter';

async function example() {
  const rateLimiter = await createRateLimiter({
    url: 'file:./path/to/rate-limit.db', // process.env.LIBSQL_URL
    // ...other config like authToken LIBSQL_AUTH_TOKEN can be used
  });

  // Check if it's initialized
  console.log('Is initialized?', rateLimiter.isInitialized());

  // Limit requests using the fixed window algorithm
  const result = await rateLimiter.limit({
    key: 'someUser',
    limit: 5, // requests
    window: 60, // seconds
    algorithm: 'fixed', // 'fixed', 'sliding', or 'token'
  });
  console.log('Fixed window result:', result);

  // Close the client when done
  rateLimiter.close();
}

API

createRateLimiter(config?)

Creates and returns a new RateLimiter instance.

limit(options)

Checks if a given request identified by options.key should be allowed under the specified algorithm. Returns a RateLimitResult object containing:

  • success: whether the request is allowed
  • limit: max capacity
  • remaining: remaining limit
  • reset: milliseconds until limit resets

isInitialized()

Returns a boolean indicating if the underlying table is set up.

close()

Closes the underlying client connection.