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

staticseek-react

v0.1.1

Published

A React component for staticseek

Downloads

5

Readme

staticseek-react

A React component wrapper for staticseek, providing easy integration of full-text search capabilities into React applications.

Installation

npm install staticseek-react staticseek

Quick Start

import StaticSeek from 'staticseek-react';

function App() {
  return (
    <StaticSeek 
      query="search term" 
      indexUrl="/searchindex.json"
      suspense={<div>Loading...</div>}
    >
      {(results) => (
        <ul>
          {results.map(result => (
            <li key={result.id}>{result.key.title}</li>
          ))}
        </ul>
      )}
    </StaticSeek>
  );
}

Component API

Props

| Prop | Type | Required | Description | |------|------|----------|-------------| | query | string | Yes | The search query to execute | | indexUrl | string | Yes | URL to the pre-generated search index JSON file | | suspense | ReactNode | Yes | Component to show while loading the index | | children | (results: SearchResult[]) => ReactNode | Yes | Render function for search results |

Types

type SearchResult = {
    id: number;
    key: Record<string, unknown>;
    score: number;
    refs: Reference[];
};

type Reference = {
    token: string;
    path: string;
    pos?: number;
    wordaround?: string;
    distance: number;
};

Complete Example

Here's a complete example showing how to implement a search interface with staticseek-react:

import { type JSX, useState } from "react";
import type { SearchResult } from "staticseek";
import StaticSeek from "staticseek-react";

// Define the structure of your search result keys
type SearchKey = {
    slug: string;
    data: {
        title: string;
    };
};

// Component to render search results
function StaticSeekResult(result: SearchResult[]): JSX.Element {
    const lis = result.map((item) => {
        const key = item.key as SearchKey;
        return (
            <li key={key.slug}>
                <h3>{key.data.title}</h3>
                <p>{item.refs[0].wordaround}</p>
            </li>
        );
    });

    return (
        <>
            <h2>Results</h2>
            <ul>{result.length > 0 ? lis : <li>No results found.</li>}</ul>
        </>
    );
}

// Main application component
function App() {
    const [query, setQuery] = useState<string>("");
    const [trigger, setTrigger] = useState<boolean>(false);

    function onChangeInput(e: React.ChangeEvent<HTMLInputElement>) {
        setQuery(e.target.value);
        setTrigger(true);
    }

    return (
        <main>
            <div className="input-area">
                <div>Search</div>
                <input
                    type="text"
                    name="search"
                    id="search"
                    placeholder="Type your search query..."
                    onChange={onChangeInput}
                />
            </div>
            {trigger && (
                <StaticSeek 
                    query={query} 
                    indexUrl="searchindex.json" 
                    suspense={<div>Loading index...</div>}
                >
                    {StaticSeekResult}
                </StaticSeek>
            )}
        </main>
    );
}

Generating the Search Index

Before using staticseek-react, you need to generate a search index. Here's how to create one:

import { LinearIndex, createIndex, indexToObject } from 'staticseek';
import fs from 'fs';

// Your content array
const articles = [
    {
        slug: "getting-started",
        content: "Welcome to our documentation...",
        data: {
            title: "Getting Started Guide",
            description: "Learn how to get started..."
        }
    }
    // ... more articles
];

// Create the index
const index = createIndex(LinearIndex, articles, {
    key_fields: ['slug', 'data.title'],
    search_targets: ['content', 'data.title', 'data.description']
});

// Convert to serializable object and save
const indexObject = indexToObject(index);
fs.writeFileSync('public/searchindex.json', JSON.stringify(indexObject));

Advanced Features

Query Syntax

staticseek-react supports all the search features from staticseek:

  • Fuzzy Search: distance:2 searchterm
  • Exact Match: "exact phrase"
  • Boolean Operations:
    • AND: term1 term2
    • OR: term1 OR term2
    • NOT: -term1 term2
  • Field-Specific: from:title searchterm
  • Custom Weights: from:title weight:2.5 searchterm

Performance Optimization

For better performance with large datasets, consider:

  1. Using GPU-accelerated search:
import { GPULinearIndex } from 'staticseek';

const index = createIndex(GPULinearIndex, articles);
  1. Using optimized index for CJK languages:
import { HybridBigramInvertedIndex } from 'staticseek';

const index = createIndex(HybridBigramInvertedIndex, articles);

Browser Support

staticseek-react requires browsers that support:

  • ES6+ features
  • Intl.Segmenter for proper Unicode handling
  • WebGPU (optional, for GPU-accelerated search)

License

MIT