Sørensen–Dice coefficient
npm install dice-coefficient[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[Sørensen–Dice coefficient][wiki].
* What is this?
* When should I use this?
* Install
* Use
* API
* diceCoefficient(value, other)
* CLI
* Types
* Compatibility
* Related
* Contribute
* Security
* License
This package exposes a string similarity algorithm.
That means it gets two strings (typically words), and turns it into a number
between 0 (completely different) and 1 (exactly the same).
You’re probably dealing with natural language, and know you need this, if
you’re here!
This package is [ESM only][esm].
In Node.js (version 14.14+, 16.0+), install with [npm][]:
``sh`
npm install dice-coefficient
In Deno with [esm.sh][esmsh]:
`js`
import {diceCoefficient} from 'https://esm.sh/dice-coefficient@2'
In browsers with [esm.sh][esmsh]:
`html`
`js
import {diceCoefficient} from 'dice-coefficient'
diceCoefficient('abc', 'abc') // => 1
diceCoefficient('abc', 'xyz') // => 0
diceCoefficient('night', 'nacht') // => 0.25
diceCoefficient('night', 'nacht') === dice('NiGhT', 'NACHT') // => true
`
This package exports the identifier diceCoefficient.
There is no default export.
Get the difference according to Sørensen–Dice.
> 👉 Note: you can pass bigrams (from [n-gram][n-gram]) too, which will
> improve performance when you are comparing the same values multiple times.
###### value
Primary value (string, Array, required).
###### other
Other value (string, Array, required).
##### Returns
Difference (number).
The result is normalized to a number between 0 (completely different)1
and (exactly the same).
`txt
Usage: dice-coefficient [options]
Sørensen–Dice coefficient
Options:
-h, --help output usage information
-v, --version output version number
Usage:
Types
This package is fully typed with [TypeScript][].
It exports no additional types.
Compatibility
This package is at least compatible with all maintained versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
It also works in Deno and modern browsers.
Related
levenshtein-edit-distance
— levenshtein edit distance
* lancaster-stemmer
— lancaster stemming algorithm
* double-metaphone
— double metaphone algorithm
* soundex-code
— soundex algorithm
* syllable`Yes please!
See [How to Contribute to Open Source][contribute].
This package is safe.
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/words/dice-coefficient/workflows/main/badge.svg
[build]: https://github.com/words/dice-coefficient/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/words/dice-coefficient.svg
[coverage]: https://codecov.io/github/words/dice-coefficient
[downloads-badge]: https://img.shields.io/npm/dm/dice-coefficient.svg
[downloads]: https://www.npmjs.com/package/dice-coefficient
[size-badge]: https://img.shields.io/bundlephobia/minzip/dice-coefficient.svg
[size]: https://bundlephobia.com/result?p=dice-coefficient
[npm]: https://docs.npmjs.com/cli/install
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[typescript]: https://www.typescriptlang.org
[contribute]: https://opensource.guide/how-to-contribute/
[license]: license
[author]: https://wooorm.com
[wiki]: https://en.wikipedia.org/wiki/Sørensen–Dice_coefficient
[n-gram]: https://github.com/words/n-gram