Effortless and fast string similarity comparison using multiple algorithms, including bigrams, Levenshtein, Jaro-Winkler, and Ratcliff/Obershelp. Perfect for fuzzy search, NLP, and intelligent text matching.
npm install stringwise



stringwise is a fast and lightweight TypeScript library for comparing string similarity using multiple algorithms like bigrams, Levenshtein, Jaro-Winkler, and Ratcliff/Obershelp. Itβs ideal for fuzzy searching, intelligent suggestions, and natural language processing tasks where accuracy and performance matter.
- β‘οΈ Efficient and Lightweight: Built for real-time performance in search and suggestion engines.
- π§ Multiple Algorithms: Choose from default, levenshtein, jaro-winkler, or ratcliff-obershelp.
- π― Precise Similarity Control: Use round option to control rating precision.
- π Fuzzy Matching Made Easy: Quickly identify the best match among multiple strings.
- π Fully Typed: Built with TypeScript for a safer developer experience.
- π¦ Modular Structure: Ready to scale with your application needs.
Install via npm or yarn:
``bash`
npm install stringwise
or
`bash`
yarn add stringwise
`ts`
import { compareTwoStrings, findBestMatch, getSimilarityFn } from "stringwise";
`ts`
compareTwoStrings("hello", "h3llo"); // e.g. 0.5
`ts
const result = findBestMatch("hello", ["halo", "hell", "hello", "world"]);
console.log(result.bestMatch);
// { target: 'hello', rating: 1 }
console.log(result.ratings);
/*
[
{ target: 'halo', rating: 0.2857142857142857 },
{ target: 'hell', rating: 0.8571428571428571 },
{ target: 'hello', rating: 1 },
{ target: 'world', rating: 0 }
]
*/
`
`ts`
const result = findBestMatch("kitten", ["sitting"], {
algorithm: "levenshtein",
round: 3,
});
`ts`
const sim = getSimilarityFn("jaro-winkler");
console.log(sim("MARTHA", "MARHTA")); // ~0.9611
Returns a similarity score between 0 and 1 using bigram overlap.
---
Returns an object containing:
- bestMatch: The string with the highest similaritybestMatchIndex
- : Index in the original listratings
- : All similarity scores
Options:
`ts`
type FindBestMatchOptions = {
round?: number; // Decimal places
algorithm?: "default" | "levenshtein" | "jaro-winkler" | "ratcliff-obershelp";
};
---
Returns the similarity function for a given algorithm name.
---
`ts
type MatchRating = {
target: string;
rating: number;
};
type FindBestMatchResult = {
bestMatch: MatchRating;
bestMatchIndex: number;
ratings: MatchRating[];
};
`
- Node.js v14.0.0 or newer
- TypeScript (recommended)
Licensed under the MIT License. See the LICENSE file for more details.
Contributions are welcome! Whether it's a bug fix, feature, or idea β feel free to open a pull request.
1. Fork the repo
2. Create your branch: git checkout -b my-featuregit commit -m 'feat: awesome feature'`
3. Commit your changes:
4. Push and open a PR on GitHub
Created by Kledenai
π« me@kledenai.com
π github.com/kledenai