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 🙏

© 2024 – Pkg Stats / Ryan Hefner

search-utils

v1.0.4

Published

The Search Utils Library is a lightweight, modular JavaScript component library designed to enhance the performance and usability of search functionality in web applications. This library provides a suite of utility functions to streamline and optimize re

Downloads

4

Readme

SearchUtils

SearchUtils is a lightweight JavaScript utility library for implementing efficient and responsive search functionalities. It provides features like indexing, caching, filtering, and debouncing to enhance the performance and user experience of search bars or sidebars.

Features

  • Indexing: Efficiently index large datasets for quick search operations.
  • Caching: Cache search results to minimize redundant computations.
  • Filtering: Real-time search filtering to narrow down results based on user input.
  • Debouncing: Prevent excessive function calls by delaying the execution of the search operation.

Installation

You can install SearchUtils via npm:

npm install search-utils

Usage

Here’s how you can use SearchUtils in your project:

Basic Example

import { createIndex, cacheResults, filterResults, debounceSearch } from 'search-utils';

// Sample dataset
const data = [
  { id: 1, name: 'Apple' },
  { id: 2, name: 'Banana' },
  { id: 3, name: 'Cherry' },
];

// Create an index
const index = createIndex(data, 'name');

// Cache the results
const cachedSearch = cacheResults((query) => filterResults(index, query));

// Debounce the search function
const debouncedSearch = debounceSearch(cachedSearch, 300);

// Example usage in a search bar event handler
searchInput.addEventListener('input', (event) => {
  const query = event.target.value;
  const results = debouncedSearch(query);
  console.log(results);
});

API Reference

createIndex(data: Array, key: String)

Creates an index from the provided dataset.

  • Parameters:

    • data: The array of objects to index.
    • key: The key to index by (e.g., name).
  • Returns: An indexed object for quick search operations.

cacheResults(searchFunction: Function)

Caches the results of a search function to avoid redundant computations.

  • Parameters:

    • searchFunction: The search function whose results should be cached.
  • Returns: A function that performs cached searches.

filterResults(index: Object, query: String)

Filters the indexed data based on the search query.

  • Parameters:

    • index: The indexed data to search through.
    • query: The search query.
  • Returns: An array of objects that match the query.

debounceSearch(searchFunction: Function, delay: Number)

Debounces a search function to delay its execution.

  • Parameters:

    • searchFunction: The function to debounce.
    • delay: The delay in milliseconds.
  • Returns: A debounced function that executes after the specified delay.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request with your changes. Make sure to write tests and update the documentation where necessary.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Acknowledgements

Thanks to everyone who contributed to this project by reporting bugs, suggesting features, or submitting pull requests.