Spotr Spotr

A powerful fuzzy search library for client-side collections in TypeScript

  • Zero Dependencies - Custom Levenshtein implementation, no external deps
  • Fuzzy Matching - Configurable threshold (0-1) for fuzzy string matching
  • Nested Field Support - Dot notation for deeply nested object properties
  • Keywords - Add custom filtering logic for exact keyword matches
  • Framework Integrations - React, Vue, Svelte, Solid, and Preact support
  • TypeScript - Full type definitions included
npm install spotr

ESM + CJS, tree-shakeable v1.0.0-alpha.3 3.4 kB gzipped

import { useState } from 'react'; import { useSpotr } from 'spotr/react'; function SearchComponent() { const [query, setQuery] = useState(''); const spotr = useSpotr({ collection: items, fields: [ { name: 'title', weight: 1 }, { name: 'description', weight: 0.7 }, ], }); const result = spotr.query(query); return ( <> <input value={query} onChange={(e) => setQuery(e.target.value)} /> <ul> {result.results.map((r) => ( <li key={r.item.title}>{r.item.title}</li> ))} </ul> </> ); }

Give it a shot!

This example demonstrates a few different configuration options used, with fields setup for fuzzy matching, keywords for exact subsets, and combining keywords with fuzzy search terms. Notice the results are scored based on the fuzzy field matches.

Try:
Keywords:
Combined:
ScoreFirst NameLast NameEmailCityCompanySubscribed
-AliceJohnsonalice.johnson@acme.comSan FranciscoAcme Corp
-AliceChenalice.chen@acme.comSan FranciscoAcme Corp
-BobSmithbob@acme.comSan FranciscoAcme Corp
-BruceWaynebruce@wayneenterprises.comGothamWayne Enterprises
-CarolDaviscarol@globex.comNew YorkGlobex Inc
-CharlieBrowncharlie@initech.comLondonInitech
-DianaPrincediana@themyscira.orgParisThemyscira Foundation
-EdwardNortoned@starkindustries.comLos AngelesStark Industries
-FionaGreenfiona@umbrella.comTokyoUmbrella Corp
-GeorgeWilsongeorge@wayneenterprises.comGothamWayne Enterprises
-HannahMontanahannah@disney.comOrlandoDisney
-IvanPetrovivan@sovkhoz.ruMoscowSovkhoz Industries
-JuliaRobertsjulia.roberts@hollywood.comLos AngelesHollywood Studios
-JuliaMartinezjulia.martinez@hollywood.comLos AngelesHollywood Studios
-KevinHartkevin@comedy.comPhiladelphiaComedy Central
-LauraCroftlaura@archaeology.orgLondonCroft Manor
-MichaelScottmichael.scott@dundermifflin.comScrantonDunder Mifflin
-MichaelBoltonmichael.bolton@dundermifflin.comScrantonDunder Mifflin
-NancyDrewnancy@detective.comRiver HeightsDrew Detective Agency
-OscarWildeoscar@literature.ieDublinLiterary Society