Package Exports
- mismo-strings
- mismo-strings/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mismo-strings) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
mismo
A lightweight utility that finds the degree of similarity between two strings using Dice’s Coefficient. This algorithm is often more intuitive than Levenshtein distance for natural-language comparison.
Note:
mismo-stringsis a maintained fork of the originalstring-similaritylibrary by Ace Aakash. Code is licensed under MIT, with attribution retained as required.
Table of Contents
Usage
For Node.js
Install:
npm install mismo --saveUse in your code:
const stringCompare = require("mismo-strings");
const similarity = stringCompare.compareTwoStrings("healed", "sealed");
// similarity → 0.8
const matches = stringCompare.findBestMatch("healed", [
"edward",
"sealed",
"theatre",
]);
// matches → { ratings: [...], bestMatch: {...}, bestMatchIndex: ... }For browser apps
Use the UMD build:
<script src="//unpkg.com/mismo/umd/mismo.min.js"></script>
<script>
stringCompare.compareTwoStrings("what!", "who?");
</script>This exposes a global variable stringCompare.
Tip: For case-insensitive comparison, you can convert strings to lowercase before comparing:
stringCompare.compareTwoStrings(str1.toLowerCase(), str2.toLowerCase());
API
compareTwoStrings(string1, string2)
Returns a number between 0 and 1 representing similarity (0 = completely different, 1 = identical). Comparison is case-sensitive by default.
Arguments
string1(string)string2(string)
Order does not matter.
Returns
number – similarity score between 0 and 1.
Examples
stringCompare.compareTwoStrings("healed", "sealed");
// → 0.8
stringCompare.compareTwoStrings(
"Olive-green table for sale, in extremely good condition.",
"For sale: table in very good condition, olive green in colour."
);
// → 0.6060606060606061findBestMatch(mainString, targetStrings)
Compares mainString against each string in targetStrings.
Arguments
mainString(string)targetStrings(Array)
Returns
An object:
{
ratings: [
{ target: "abc", rating: 0.5 },
{ target: "def", rating: 0.2 },
...
],
bestMatch: { target: "abc", rating: 0.5 },
bestMatchIndex: 0
}Example
stringCompare.findBestMatch(
"Olive-green table for sale, in extremely good condition.",
[
"For sale: green Subaru Impreza, 210,000 miles",
"For sale: table in very good condition, olive green in colour.",
"Wanted: mountain bike with at least 21 gears."
]
);Release Notes
1.0.0 — Initial mismo release
- Forked from original
string-similarity - Renamed and repackaged under
mismo - Updated documentation and cleaned API references
- Preserved MIT license and attribution
License
MIT — includes original copyright notice from aceakash/string-similarity.