ksdc
Version:
Measure how similar two strings are using the Sørensen–Dice Coefficient
98 lines (63 loc) • 2.48 kB
Markdown
> Measure how similar two strings are using the [Sørensen–Dice Coefficient](https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient)
[](https://github.com/macarie/ksdc/actions?query=workflow%3Atest) [](https://codecov.io/gh/macarie/ksdc) [](https://github.com/macarie/ksdc/blob/master/license)
```console
$ npm install ksdc
```
Or if you prefer using Yarn:
```console
$ yarn add ksdc
```
```javascript
import { compareStrings, findMatch } from "ksdc"
compareStrings("night", "nacht")
// => 0.25
const compareNightWith = compareStrings("night")
compareNightWith("nacht")
compareNightWith("night")
findMatch(["heal", "thing"], "ideal")
// => {
// => bestMatch: { score: 0.5714285714285714, index: 0, reference: 'heal' },
// => matches: [
// => { score: 0.5714285714285714, reference: 'heal' },
// => { score: 0, reference: 'thing' }
// => ]
// => }
const findMatchFromList = findMatch(["heal", "thing"])
findMatchFromList("ideal")
findMatchFromList("zeal")
```
Compare `input` with `reference`, returns the Sørensen–Dice coefficient between the two strings.
This is a [curried](https://en.wikipedia.org/wiki/Currying) function. If `input` is not provided a function that accepts `input` as an argument is returned.
Type: `string`
Type: `string`
Compare `input` with a list of strings, `references`, and finds the best match for it, returns an object that has the following properties:
```typescript
interface match {
bestMatch: {
score: number
index: number
reference: string
}
matches: Array<{
score: number
reference: string
}>
}
```
This is a [curried](https://en.wikipedia.org/wiki/Currying) function. If `input` is not provided a function that accepts `input` as an argument is returned.
Type: `string[]`
Type: `string`
The latest version of Chrome, Firefox, Safari, and Edge.
Node.js 12 or later.