finds similar
words/abbreviationsin the abbreviations-in-code project lists.meant to avoid duplicate or near-duplicate entries.
Uses the Damerau-Levenshtein distance to calculate
similarities between entries of the machine-readable JSON abbreviations.
- words with
score < 3are included in the results. - a
score: 0means it's an exact duplicate. - results are sorted by lowest score, ascending.
The lower the
score, the more similar the words are.The score is the number of additions/deletions/edits required to change a word into another.
e.g: "cat" and "car" distance is
1.
npm i https://github.com/nicholaswmin/similar.gittheres no deps, neither
prodnordev/test.
Example usage:
import { compare } from '@nicholaswmin/similar'
const json = await fetch('https://raw.githubusercontent.com/abbrcode/abbreviations-in-code/refs/heads/main/data/abbrs/.json')
.then(res => res.json())
const similarWords = compare.words(json, { cutoff: 3 })
const similarAbbrs = compare.abbrs(json, { cutoff: 3 })
console.dir(similarWords, { depth: 3 })
// console.dir(similarAbbrs, { depth: 3 })returns:
{
name: 'predication',
i: 202,
matches: [
{ name: 'prediction', i: 203, matches: [], score: 1 },
{ name: 'production', i: 208, matches: [], score: 3 }
]
},
{
name: 'time',
i: 260,
matches: [
{ name: 'timer', i: 261, matches: [], score: 1 },
{ name: 'sine', i: 239, matches: [], score: 2 },
{ name: 'type', i: 266, matches: [], score: 2 },
{ name: 'active', i: 4, matches: [], score: 3 },
{ name: 'image', i: 131, matches: [], score: 3 },
{ name: 'link', i: 156, matches: [], score: 3 },
{ name: 'node', i: 177, matches: [], score: 3 },
{ name: 'pixel', i: 197, matches: [], score: 3 },
{ name: 'text', i: 259, matches: [], score: 3 },
{ name: 'to', i: 263, matches: [], score: 3 }
]
},
}
// and so on...The above example can be run via node example.js
no need for
npm i, its a native test runner
node --run testNik. Kyriakides, @nicholaswmin