Scripts2026年7月4日·1 分钟阅读

Fuse.js — Lightweight Fuzzy-Search Library for JavaScript

A powerful, lightweight fuzzy-search library for JavaScript and TypeScript with zero dependencies, supporting weighted search, extended patterns, and flexible scoring.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Fuse.js Overview
直接安装命令
npx -y tokrepo@latest install b5621511-77c5-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

Fuse.js is a lightweight fuzzy-search library for JavaScript that works in both the browser and Node.js. It requires zero dependencies and enables approximate string matching so users can find results even with typos or partial queries.

What Fuse.js Does

  • Performs fuzzy (approximate) string matching on arrays of objects or strings
  • Supports weighted search across multiple keys with configurable thresholds
  • Provides extended search operators for exact match, prefix, suffix, and inverse queries
  • Works entirely client-side with no external services or network calls required
  • Returns scored and sorted results with optional match highlighting metadata

Architecture Overview

Fuse.js implements a modified Bitap algorithm for approximate string matching. When initialized, it builds an internal index of the provided data set keyed by the configured search fields. Each search query is scored against every indexed entry using configurable distance and threshold parameters, and results are ranked by relevance score.

Self-Hosting & Configuration

  • Install via npm, yarn, or pnpm; also available as a CDN script for browsers
  • Create a Fuse instance with your data array and an options object specifying keys and weights
  • Adjust the threshold option (0.0 to 1.0) to control match strictness
  • Set distance to define how far a match can be from the expected location
  • Enable includeScore and includeMatches for detailed result metadata

Key Features

  • Zero dependencies and under 15 KB minified and gzipped
  • Works identically in Node.js, browsers, and Deno
  • Extended search syntax for combining fuzzy, exact, prefix, and inverse patterns
  • Weighted multi-key search for prioritizing certain fields over others
  • Configurable scoring with threshold, distance, and location parameters

Comparison with Similar Tools

  • Lunr.js — full-text search with stemming and field boosting; heavier and requires building an index upfront
  • FlexSearch — faster for large datasets with memory-mapped indexes; more complex API surface
  • MiniSearch — similar lightweight approach with auto-suggest and prefix search built in
  • Algolia/Typesense — server-side search engines with dashboards; overkill for client-side use cases

FAQ

Q: Does Fuse.js support TypeScript? A: Yes, Fuse.js ships with built-in TypeScript type definitions.

Q: Can Fuse.js handle large datasets? A: It works well for datasets up to tens of thousands of items. For millions of records, consider a server-side search engine.

Q: Does it support async or streaming search? A: No, Fuse.js performs synchronous in-memory search. For very large lists, you can batch or paginate your data.

Q: Can I search nested objects? A: Yes, use dot notation in the keys config, such as author.name, to search nested properties.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产