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

react-highlight-search

v1.2.1

Published

Text highlight with deep search through DOM elements.

Readme

React-Highlight-Search

React Highlight Search is an out-of-the-box solution for deep text search through the DOM tree. It provides a lightweight and fast ReactJS component (19.9 kB, reduced to 7.0 kB gzip), built with Vanilla JS and featuring zero dependencies.

Installation

The easiest way to install react-highlight-search is by using either npm or yarn commands:

npm install react-highlight-search

or

yarn add react-highlight-search

Basic Usage in React App

Live Demo

Implementing deep search through a nested DOM is incredibly simple with the react-highlight-search package.

import React, { useState, useCallback } from "react";
import { HighlightSearchWrapper } from "react-highlight-search";

const ExampleWithSearch = () => {
  const [searchString, setSearchString] = useState(""); // State variable to hold the search string
  const [matchData, setMatchData] = useState({
    wrapperIndex: 0,
    matchesFound: 0,
    matchParentElement: null,
  }); // Search data returned by the component

  const handleInputChange = useCallback((e) => {
    setSearchString(e.target.value);
  }, []);

  return (
    <>
      <input onInput={handleInputChange} />
      <HighlightSearchWrapper
        searchString={searchString} // Pass the search string
        onMatchData={setMatchData} // Pass the function to update search data on a successful search
      >
        <div className={"example-of-nesting-1"}>
            Hello World!
            <div className={"example-of-nesting-2}>
                Other text example
                <div className={"example-of-nesting-3}>
                    Search Me!
                    <ul>
                        <li>Search Me..</li>
                        <li>
                            Search Me Again!
                            <span>Search Me!</span>
                        </li>
                        <li>Hello World!</li>
                        <li>
                            <div>
                                <h4>Other text example</h4>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
      </HighlightSearchWrapper>

      // Block shows example of the search result data
      <div style={{ width: "350px" }}>
        <div>Wrapper Index: {matchData.wrapperIndex}</div>
        <div>Matches Found: {matchData.matchesFound}</div>
        <div>
          Match Parent Element:
          {matchData.matchParentElement
            ? matchData.matchParentElement.toString()
            : ""}
        </div>
      </div>
    </>
  );
};

export default ExampleWithSearch;

Props

| Name | Required | Type | Default | Description | | ------------- | ------------- | ------------- | ------------- | ------------- | | searchString | Yes | string | undefined | The text to search for. | setTriggerSearch | No | Function | undefined | The function to trigger search manually. | ignoreCase | No | boolean | true | Ignore case sensitive of the search string. | searchMinLength | No | number | 1 | The minimum length of text required to start the search. | onMatchData | No | Function | undefined | Callback function triggered on a successful search. | spanClassName | No | string | "hlsearch-span-el" | Class name applied to the elements added to the DOM for highlighting text. | index | No | number | 0 | Index value returned in the onMatchData callback. Useful for managing multiple components. // TODO: issues with dots

License

MIT Licensed. Copyright (c) Vladyslav Dotsenko 2025.