ksdc

1.0.4 • Public • Published

ksdc Release Version

Measure how similar two strings are using the Sørensen–Dice Coefficient

Test Results Coverage Status GitHub

Install

$ npm install ksdc

Or if you prefer using Yarn:

$ yarn add ksdc

Usage

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")

API

compareStrings(reference, input)

Compare input with reference, returns the Sørensen–Dice coefficient between the two strings.

This is a curried function. If input is not provided a function that accepts input as an argument is returned.

reference

Type: string

input

Type: string

findMatch(references, input)

Compare input with a list of strings, references, and finds the best match for it, returns an object that has the following properties:

interface match {
  bestMatch: {
    score: number
    index: number
    reference: string
  }
  matches: Array<{
    score: number
    reference: string
  }>
}

This is a curried function. If input is not provided a function that accepts input as an argument is returned.

references

Type: string[]

input

Type: string

Browser support

The latest version of Chrome, Firefox, Safari, and Edge.

Node.js support

Node.js 12 or later.

Package Sidebar

Install

npm i ksdc

Weekly Downloads

11

Version

1.0.4

License

MIT

Unpacked Size

14.2 kB

Total Files

6

Last publish

Collaborators

  • macarie