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

@sthirajs/chunked

v2.0.0

Published

Size-aware virtual store chunking for Sthira

Readme

@sthirajs/chunked

Size-aware virtual store with LRU caching for large datasets.

Installation

pnpm add @sthirajs/chunked

Quick Start

import { createChunkedStore } from '@sthirajs/chunked';

const store = createChunkedStore({
  name: 'large-dataset',
  chunkSize: 1000, // Items per chunk
  maxChunks: 10, // Max chunks in memory
});

// Load data
await store.setChunk('page-1', largeArray.slice(0, 1000));
await store.setChunk('page-2', largeArray.slice(1000, 2000));

// Get data (auto-loads from cache or storage)
const chunk = await store.getChunk('page-1');

API Reference

createChunkedStore(config)

interface ChunkedStoreConfig<T> {
  name: string; // Store identifier
  chunkSize: number; // Items per chunk
  maxChunks?: number; // Max chunks in memory (LRU eviction)
  tiers?: TierConfig[]; // Memory tier configuration
  onEvict?: (key: string, chunk: T[]) => void;
}

const store = createChunkedStore<User>({
  name: 'users',
  chunkSize: 500,
  maxChunks: 20,
});

// API
await store.setChunk(key, data); // Set chunk
await store.getChunk(key); // Get chunk (loads if evicted)
store.hasChunk(key); // Check if in memory
store.deleteChunk(key); // Remove chunk
store.clear(); // Clear all chunks
store.getKeys(); // Get all chunk keys
store.getStats(); // { totalChunks, memoryUsage, ... }

LRUCache

Standalone LRU cache:

import { LRUCache } from '@sthirajs/chunked';

const cache = new LRUCache<string, User[]>({
  maxSize: 10,
  onEvict: (key, value) => {
    console.log(`Evicted: ${key}`);
  },
});

cache.set('users-1', users);
cache.get('users-1'); // Moves to front (most recently used)
cache.has('users-1');
cache.delete('users-1');
cache.clear();

Memory Tiers

Configure different storage tiers based on access patterns:

const store = createChunkedStore({
  name: 'products',
  chunkSize: 100,
  tiers: [
    { name: 'hot', maxSize: 5 }, // Frequently accessed
    { name: 'warm', maxSize: 10 }, // Occasionally accessed
    { name: 'cold', maxSize: 50 }, // Rarely accessed
  ],
});

// Chunks automatically move between tiers based on access

Use Cases

Large Tables

// Virtual scrolling with chunked data
const tableStore = createChunkedStore<Row>({
  name: 'table-data',
  chunkSize: 50, // 50 rows per chunk
  maxChunks: 10, // 500 rows in memory max
});

// Load visible chunks
async function loadVisibleRows(startRow: number, endRow: number) {
  const startChunk = Math.floor(startRow / 50);
  const endChunk = Math.floor(endRow / 50);

  for (let i = startChunk; i <= endChunk; i++) {
    if (!tableStore.hasChunk(`chunk-${i}`)) {
      const data = await fetchRows(i * 50, 50);
      await tableStore.setChunk(`chunk-${i}`, data);
    }
  }
}

Paginated Data

const paginatedStore = createChunkedStore({
  name: 'search-results',
  chunkSize: 20, // 20 items per page
  maxChunks: 5, // Keep 5 pages in memory
});

async function loadPage(page: number) {
  const key = `page-${page}`;
  if (!paginatedStore.hasChunk(key)) {
    const data = await api.search({ page, limit: 20 });
    await paginatedStore.setChunk(key, data);
  }
  return paginatedStore.getChunk(key);
}

Time-Series Data

const timeSeriesStore = createChunkedStore({
  name: 'metrics',
  chunkSize: 1000, // 1000 data points per chunk
  maxChunks: 24, // 24 hours in memory
  onEvict: (key, data) => {
    // Persist to IndexedDB on eviction
    persistToStorage(key, data);
  },
});

Exports

// Store
export { createChunkedStore }

// LRU Cache
export { LRUCache }

// Types
export type { ChunkedStoreConfig, Chunk, ChunkMeta, TierConfig, ... }

License

MIT