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

approx-match

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

approx-match

approximate-match

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Build Status

approximate-match

Provides approximate string matching. Works intuitively well, compared to say Levenshtein edit distance. Specially works with human typing abbreviations.

Example

var ApproxMatch = require('approximate-match')
var ap = new ApproxMatch;
ap.add('Northwestern University')
ap.match('Nwstrn Univ.') // Northerwestern University

Corpus adding and corpus association

Individual string items that are searched within the corpus can be associated with an object, so that those associations can be retrieved upon matching.

.add(string,value)

Here we associate {foo:'bar'} with "University of Notre Dame"

approx.add('University of Notre Dame',{foo:'bar})

.add(string1, string2, ... value)

We can also add multiple strings as a corpus to associate to a single value

approx.add('UND', 'Notre Dame', 'ND Fighting Irish', {foo:'bar'})

.addObject(object)

If you add an object its fields will be searched over

approx.addObject({key1:'foo', key2:'bar',key3:'baz})
approx.match('foo')
// {key1:'foo', key2:'bar',key3:'baz}

Note that adding an object precludes it from having an associated return object. This may change in the future.

Matching

Ease of Use of the .match function. Weather your corpus has a mix of both string items and objects, .match will search across all of them.

Example:

ap.addObject({foo:'gabby', bar:'cupid'})
ap.addObject({foo:'monsoon', bar:'annie'})
res = ap.match('monsoon')
assert.deepEqual(res[0],{ metric: 7, corpus: { foo: 'monsoon', bar: 'annie' } })
res = ap.match('Northwest')
assert.deepEqual(res[0], { metric: 9, corpus: 'Northwestern University' })

.match(string)

// matching it
approx.match("N'wstrn")
// Northewestern University

If there was an associated object it will be returned as well

.match(string,list)

You can specify certain fields if the internal matching encounters an object The text to be matched will be matched against the keys ordered together.

approx.addObject({ name: 'Abilene Christian University',
mascot: 'Wildcats',
city: 'Abilene',
state: 'Texas'})

approx.match('Abilene Wildcats', ['name','mascot'])
// 'Abilene Wildcats' will be matched against 'Abilene Christian University Wildcats'
// and return that object

Other Methods

.metric(string1,string2)

Want a metric between N'WSTRN and NORTHWESTERN UNIVERSITY?

var ApproxMatch = require('approximate-match')
var ap = new ApproxMatch;
ap.metric("N'wstrn", "Northerwestern University")
// 8

.setMetric

You can use your own metric or use the convenience metrics available on the require object

var ApproxMatch = require('approximate-match'); var ap = new ApproxMatch;

This is the default, metric_with_discard

ap.setMetric(ApproxMatch.metric_with_discard)

or this metric rewards continual letter-by-letter matching

ap.setMetric(ApproxMatch.metric)

FAQs

Package last updated on 27 Sep 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