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

simple-and-advanced-search

v0.2.0

Published

Perform simple and advanced search in JS arrays

Readme

SIMPLE AND ADVANCED SEARCH

Filter arrays of strings by matching a query string on the client. Useful for combobox widgets and similar.

Dependencies

No dependencies

SIMPLE SEARCH

Simple search searches an array of strings using javaScript search() function and regular expressions (case-insensitive).

  • < 300 bytes minified
  • UMD support

Arguments:

  • stringsCollection (type: array): the set of strings to search for a match.
  • queryString (type: string): the query string.

Output:

The function returns an array with the indexes of the matched strings (position of the item in the stringsCollection array).

Usage example:


var stringsCollection = ['string1', 'string2', 'string3'], //the set of string to search for a match
  queryString = 'string2'; //the query string

var searchResult = simpleSearch(stringsCollection, queryString); //search ...

console.log(searchResult); // output: [1]

ADVANCED SEARCH

Advanced search searches an array of strings for a match by calculating the Levenshtein distance for each pair of query string word and word of the strings to search (case-insensitive). Supports mispelled words.

  • < 900 bytes minified
  • UMD support

Arguments:

  • stringsCollection (type: array): the set of strings to search for a match.
  • queryString (type: string): the query string.
  • minDistance (type: float > 0 and < 1): the minimum Levenshtein distance for a word pair to be considered as a match.
  • minAverageDistance (type: float > 0 and < 1): the minimum average Levenshtein distance of the matched words for the string to be considered as a match.

Output

The function returns an array of objects containing the indexes of the matched strings and other useful informations about the match.

  • index: the index of the matched string (position of the item in the stringsCollection array).
  • wordMatchesCount: the number of matched words.
  • averageDistance: the sum of the matched word's distances divided by the number of matched words.
  • wordMatchesPercentage: the number of matched words divided by the number of words of the query string.
  • matchedWords: an array containing the matched words.

Usage example:


var stringsCollection = ['string1', 'string2', 'string3'], //the set of string to search for a match
  queryString = 'sring2'; //the query string

var searchResult = AdvancedSearch(stringsCollection, queryString, 0.7, 0.7); //search ...

console.log(searchResult); //output: {index: 2, wordMatchesCount: 1, averageDistance: 0.XXX, wordMatchesPercentage: 0.XXX, matchedWords: ['string2']}

DEMOS

Open the simple-search/demo.html and advanced-search/demo.html files in the browser and check the console for a real-world demo.

EXECUTION TIME

  • MacBook Pro 15" 2016, 2.5 GHz Intel Core i7, 16GB 1600 MHz DDR3.
  • Chrome version 60.0.3112.113 (Official Build) (64-bit)
  • Items in array: 65592 (names of cities).
  • Query string: 'bolzano'.

CUP Throttling | Simple search execution time | Advanced search execution time ---------------|------------------------------|--------------------------------- No throttling | > 10 ms | > 140 ms 5x slowdown | > 50 ms | > 820 ms 20x slowdown | > 190 ms | > 3200 ms

LICENSE

Simple and Advanced search is licensed under the terms of the MIT license.

See LICENSE.md for detailed informations.