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

prefetch-ai

v0.1.1

Published

Predictive prefetching for React using mouse kinematics and Markov chains

Readme

PrefetchAI

npm version License: MIT

Zero-latency React applications through physical and behavioral intelligence.

PrefetchAI is a lightweight, dependency-free library that predicts user click intent in real-time. By combining mouse kinematics (physical intent) with Markov chains (behavioral patterns), it triggers background data fetches before a user even clicks, significantly reducing perceived latency.

NPM Package | GitHub Repository

Key Features

  • Kinematic Prediction: High-fidelity mouse tracking (velocity, acceleration, alignment) using requestAnimationFrame.
  • Markov Chain Intelligence: Learns user navigation paths to prefetch data based on historical behavioral patterns.
  • Dynamic Thresholding: Automatically adjusts prediction confidence based on real-time network latency.
  • Multi-Point Alignment: High-precision targeting by checking element corners and centers.
  • Safe & Efficient: Automatic deduplication, 5-second TTL cache, and GET-only prefetching.
  • Visual Debugger: Integrated diagnostic overlay to inspect prediction scores and vectors in development.

Installation

npm install prefetch-ai

Quick Start

1. Basic Hook Usage

Use the usePredictiveFetch hook on any interactive element. Data starts loading when the user's mouse points toward the target with high velocity and alignment.

import { useRef } from 'react';
import { usePredictiveFetch } from 'prefetch-ai';

function ProductLink({ id }) {
  const linkRef = useRef(null);
  
  // Data starts loading when the user's mouse points toward this button
  const { data, loading, error } = usePredictiveFetch(linkRef, `https://api.example.com/products/${id}`);

  return (
    <button ref={linkRef} onClick={() => console.log('Data:', data)}>
      {loading ? 'Preparing...' : 'View Product'}
    </button>
  );
}

2. Behavioral Intelligence (Markov)

To enable behavioral prediction, record transitions to help the engine learn navigation patterns.

import { MarkovTracker } from 'prefetch-ai';

// In your navigation handler
const onNavigate = (to) => {
  MarkovTracker.recordTransition(window.location.pathname, to);
};

// The hook will now prefetch if this route is statistically likely
const data = usePredictiveFetch(ref, url, { 
  routeKey: '/dashboard' 
});

3. Visual Debugger (Development)

Visualize the underlying predictive engine's calculations.

import { DebugProvider, PredictiveDebugger } from 'prefetch-ai';

function App() {
  return (
    <DebugProvider>
      <PredictiveDebugger />
      <YourApp />
    </DebugProvider>
  );
}

API Reference

usePredictiveFetch(ref, url, options)

| Option | Type | Default | Description | | :--- | :--- | :--- | :--- | | ttl | number | 5000 | Cache time-to-live in milliseconds. | | threshold | number | 0.85 | Confidence threshold for kinematic trigger (0.0 to 1.0). | | routeKey | string | null | The route to match for Markov behavioral prediction. |

MarkovTracker

  • recordTransition(from, to): Updates the transition matrix with a new navigation event.
  • predictNext(currentRoute): Returns the most likely next route and its probability.
  • windowSize: Limits the memory of the tracker to the last $N$ transitions (default: 50).

License

MIT © Jishnu