npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

approx-match

v1.0.5

Published

approximate-match

Downloads

4

Readme

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)