Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dice-coefficient

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dice-coefficient

Sørensen–Dice coefficient

  • 2.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.1K
increased by6.13%
Maintainers
2
Weekly downloads
 
Created
Source

dice-coefficient

Build Coverage Downloads Size

Sørensen–Dice coefficient.

Contents

What is this?

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

When should I use this?

You’re probably dealing with natural language, and know you need this, if you’re here!

Install

This package is ESM only. In Node.js (version 14.14+, 16.0+), install with npm:

npm install dice-coefficient

In Deno with esm.sh:

import {diceCoefficient} from 'https://esm.sh/dice-coefficient@2'

In browsers with esm.sh:

<script type="module">
  import {diceCoefficient} from 'https://esm.sh/dice-coefficient@2?bundle'
</script>

Use

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

API

This package exports the identifier diceCoefficient. There is no default export.

diceCoefficient(value, other)

Get the difference according to Sørensen–Dice.

👉 Note: you can pass bigrams (from n-gram) too, which will improve performance when you are comparing the same values multiple times.

value

Primary value (string, Array<String>, required).

other

Other value (string, Array<String>, required).

Returns

Difference (number).

The result is normalized to a number between 0 (completely different) and 1 (exactly the same).

CLI

Usage: dice-coefficient [options] <word> <word>

Sørensen–Dice coefficient

Options:

  -h, --help           output usage information
  -v, --version        output version number

Usage:

# output edit distance
$ dice-coefficient night nacht
# 0.25

# output edit distance from stdin
$ echo "saturday sunday" | dice-coefficient
# 0.3333333333333333

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.

Contribute

Yes please! See How to Contribute to Open Source.

Security

This package is safe.

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 02 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc