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

@mistakster/text-search

v2.0.1

Published

A library to filter an array of objects by text content

Downloads

9

Readme

text-search

Overview

This code contains a simple search library that allows you to create a search function to find items in a list based on specific fields and perform a ranked search based on a query string.

Prepare your data as a list of objects, where each object represents an item you want to search through. Each object should have properties corresponding to the fields you want to use for search.

The search function will return a list of items that match the query, sorted by relevance. The relevance is determined based on the position of the query tokens in the items' fields.

The display field is used to determine the order of items with equal relevance scores. It ensures that the search results are consistently ordered, and if no display field is provided, the first field specified in the field parameter will be used instead. The display field can be handy when you want to give priority to certain fields for sorting purposes in cases where multiple items have the same relevance to the query.

Example

import { createSearch } from '@mistakster/text-search';

const indexer = createSearch('title'); // ['title', 'description']

const search = indexer([
  {
    title: 'Star Wars: Episode IV - A New Hope',
    description: `Luke Skywalker joins forces with a Jedi Knight,
      a cocky pilot, a Wookiee and two droids to save the galaxy from
      the Empire's world-destroying battle station, while also attempting
      to rescue Princess Leia from the mysterious Darth Vader.`
  },
  {
    title: 'Star Wars: Episode V - The Empire Strikes Back',
    description: `After the Rebels are brutally overpowered by
      the Empire on the ice planet Hoth, Luke Skywalker begins Jedi
      training with Yoda, while his friends are pursued by Darth Vader
      and a bounty hunter named Boba Fett all over the galaxy.`
  },
  {
    title: 'Star Wars: Episode VI - Return of the Jedi',
    description: `After a daring mission to rescue Han Solo from Jabba the Hutt,
      the Rebels dispatch to Endor to destroy the second Death Star. Meanwhile,
      Luke struggles to help Darth Vader back from the dark side without falling
      into the Emperor's trap.`
  }
]);

const results = search('Jedi');