New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jaro-winkler

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jaro-winkler

A string similarity function using the Jaro-Winkler distance metric.

  • 0.2.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
39K
decreased by-30.01%
Maintainers
1
Weekly downloads
 
Created
Source

Jaro-Winkler

A string similarity function using the Jaro-Winkler distance metric. Returns a number between 0 and 1. A 0 being no similarity and a 1 being an exact match.

Read more about it on Wikipedia.

Install

Install in your Node project using npm as usual; npm install jaro-winkler. It also works in the browser, just include the source within index.js in your project however you prefer. Note that the distance function will be added to the global scope if it's not included with a tool like Browserify.

Example Usage

var distance = require('jaro-winkler');

distance('MARTHA', 'MARHTA');
// 0.961

distance('DWAYNE', 'DUANE');
// 0.84

distance('DIXON', 'DICKSONX');
// 0.814


// Case Insensitive

distance('MARTHA', 'MARTHA');
// 1

distance('mArThA', 'MaRtHa', { caseSensitive: false });
// 1

Sample App

Here's contrived sample of how you might utilize a distance metric in your own app. This shows how you might offer a helpful message when a user fat-fingers a command.

#!/usr/bin/env node

'use strict';

var distance = require('jaro-winkler');
var commands = ['open', 'close', 'save', 'revert', 'select', 'copy', 'duplicate', 'add', 'subtract'];
var rated    = [];
var args     = process.argv.slice(2);

commands.forEach(function(command) {
  rated.push({
    command: command,
    distance: distance(args[0], command)
  });
});

rated.sort(function(a, b) {
  if (a.distance < b.distance) {
    return 1;
  } else if (a.distance > b.distance) {
      return -1;
  } else {
    return 0;
  }
});

if (rated[0].distance === 1) {
  console.log("Running " + rated[0].command + "!");
} else {
  console.log("Did you mean " + rated[0].command + "?");
}

process.exit(0);

Keywords

FAQs

Package last updated on 04 Oct 2016

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