- Remove deprecated getChangeScoreForString() and getClosestMatchForString() methods
- Improve type safety with correct return types (string | null)
- Add comprehensive documentation with performance guide, error handling, and real-world examples
- Include browser compatibility info, troubleshooting, and API reference sections
- Modernize developer experience with current best practices
fuzzy match strings against word dictionaries/arrays
> **Smart fuzzy matching for the modern developer** - Effortlessly match strings, sort objects, and search content with intelligent algorithms
## Install
A powerful TypeScript library that brings intelligent fuzzy matching to your applications. Whether you're building search features, autocomplete functionality, or data filtering systems, SmartFuzzy delivers the precision and flexibility you need.
To install `@push.rocks/smartfuzzy`, use the following npm command. It's recommended to do this in a project where TypeScript is already configured:
## 🚀 Features
- **🎯 Precise String Matching** - Find closest matches in dictionaries with confidence scores
- **📊 Smart Object Sorting** - Sort objects by property similarity with customizable criteria
- **⚡ Lightning Fast** - Built on proven algorithms (Levenshtein distance + Fuse.js)
- **🔧 TypeScript Native** - Full type safety and IntelliSense support
- **📱 Universal** - Works in Node.js and modern browsers
## 📦 Installation
Install using pnpm (recommended):
```bash
npm install @push.rocks/smartfuzzy --save
pnpm install @push.rocks/smartfuzzy
```
## Usage
Or with your preferred package manager:
```bash
npm install @push.rocks/smartfuzzy
# or
yarn add @push.rocks/smartfuzzy
```
`@push.rocks/smartfuzzy` is a versatile library designed to help you perform fuzzy searches and sorts on arrays of strings and objects. Whether you're building a search feature, organizing data, or implementing autocomplete functionality, `@push.rocks/smartfuzzy` offers you the tools needed to achieve efficient and intuitive search results. Below are various scenarios to cover a broad set of features of the module, ensuring you can integrate it effectively into your TypeScript projects.
## 🌐 Browser Compatibility
### Setting Up
SmartFuzzy works in all modern environments:
First, ensure you import the necessary components:
### Node.js
- **Node.js 16+** (ES2022 support required)
- Full TypeScript support with type definitions included
### Browsers
- **Modern browsers** supporting ES2022 features
- Chrome 94+, Firefox 93+, Safari 15+, Edge 94+
- **No additional build setup required** - works with standard bundlers
### TypeScript Setup
Ensure your `tsconfig.json` includes:
```json
{
"compilerOptions":{
"target":"ES2022",
"module":"NodeNext",
"moduleResolution":"NodeNext",
"esModuleInterop":true
}
}
```
### Bundle Size
- **Core library**: ~15KB minified + gzipped
- **Dependencies**: Fuse.js (~12KB), Leven (~2KB)
- **Total footprint**: ~29KB minified + gzipped
## 🚀 Quick Start (30 seconds)
Get up and running with SmartFuzzy in under a minute:
This example demonstrates how to instantiate the `Smartfuzzy` class with a list of strings (dictionary) and add more entries to it. You can then use it to get the closest match for a given search string.
This example demonstrates how to instantiate the `Smartfuzzy` class with a list of strings (dictionary) and add more entries to it. You can then use it to find the closest match or calculate similarity scores for a given search string.
### Advanced Object Sorting
Imagine you are managing a list of objects, and you wish to sort them based on the resemblance of one or more of their properties to a search term:
### 📊 Intelligent Object Sorting
Transform any object array into a smart, searchable dataset:
```typescript
interfaceICar{
@@ -66,9 +146,9 @@ console.log(searchResults); // Results will be sorted by relevance to 'Benz'
This scenario shows how to use `ObjectSorter` for sorting an array of objects based on how closely one of their string properties matches a search term. This is particularly useful for filtering or autocomplete features where relevance is key.
### Searching Within Articles
### 📄 Powerful Content Search
If your application involves searching through articles or similar textual content, `ArticleSearch` allows for a weighted search across multiple fields:
Build sophisticated search experiences for articles, blog posts, or any content with multiple fields:
```typescript
import{IArticle}from'@tsclass/tsclass/content';
@@ -101,11 +181,455 @@ console.log(searchResult); // Array of matches with relevance to 'rich history'
The `ArticleSearch` class showcases how to implement a search feature across a collection of articles with prioritization across different fields (e.g., title, content, tags). This ensures more relevant search results and creates a better experience for users navigating through large datasets or content libraries.
### Conclusion
## 🔥 Real-World Use Cases
`@push.rocks/smartfuzzy` offers a robust set of functionalities for integrating fuzzy searching and sorting capabilities into your TypeScript applications. By following the examples demonstrated, you can effectively utilize the module to enhance user experience where text search is a critical component of the application.
### Search-as-You-Type
Build responsive search experiences:
Remember to always consider the specific requirements of your project when implementing these features, as adjustments to configurations such as threshold levels and keys to search on can significantly impact the effectiveness of your search functionality.
**Q: What's the difference between `findClosestMatch` and `calculateScores`?**
A: `findClosestMatch` returns only the best match, while `calculateScores` returns scores for all dictionary entries, letting you implement custom ranking logic.
**Q: How do I handle empty results?**
A: Always check for null/empty returns:
```typescript
constmatch=fuzzy.findClosestMatch('query');
if(match===null){
console.log('No suitable match found');
}
```
## 🚀 Get Started Today
Ready to add intelligent search to your application? SmartFuzzy makes it easy:
1. Install the package
2. Import the classes you need
3. Start matching, sorting, and searching!
Perfect for building search bars, recommendation systems, data filters, and more.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.