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

co-median

v1.2.1

Published

there are still edge cases which I simply have no more time to solve. Until we have time to come back to this problem, this library will remain in an unsupported state.

Downloads

639

Readme

discontinued

there are still edge cases which I simply have no more time to solve. Until we have time to come back to this problem, this library will remain in an unsupported state.

co-median

bi-directional wildcards

For the single directional wildcard, ie: test t*st, we adapted matcher to work for node 0.10 up to 8+ . We discarded the Map object as our cache and are using the very nice lru-cache module.

In the quest for the bi-directional wildcard, we have found a solution in converting the 2 search terms to a 2d matrix, which we iterate through to find diagonals, this is a bastardisation of Levenshtein's distance algorithm, with wildcards - we are also using the amazing pathfinding module to walk our diagonal matrix.

Please not this lib is built more around accuracy than performance, so doing lots of complex matches is probably not a great idea, this module is a good idea if your system needs fuzzy matching occassionally but most of the matches are fairly simple.

quickstart


npm i co-median --save

var expect = require('expect.js');
var Comedian = require('co-median');

var comedian = new Comedian({cache:1000});//caches replies, default is false

//same beginning and end, wildcard in the middle
expect(comedian.matches('/test*short','/test/*/short')).to.be(true);
expect(comedian.matches('/test*short','/test/*/*/short')).to.be(true);

//multiple wildcards * having no value ''
expect(comedian.matches('*/wi*com/*', '*/*/co*m*')).to.be(true);
expect(comedian.matches('*/wildcard*complex/*', '*/*/co*mplex*')).to.be(true);
expect(comedian.matches('*te*s*t/mat', '*t*e*s*t*')).to.be(true);
expect(comedian.matches('*te*s*t/mat', '*t*e*s*t*')).to.be(true);
expect(comedian.matches('*te*st/mat', '*te*st*')).to.be(true);

//exact match
expect(comedian.matches('/test/*/short','/test/*/short')).to.be(true);

//loose multiple matches
expect(comedian.matches('*e*ma*', '*test/mat')).to.be(true);

expect(comedian.matches('*i*g1', '*str*ing*')).to.be(true);
expect(comedian.matches('*ing1', '*ring*')).to.be(true);

// //general on one side
expect(comedian.matches('*ing', 'test/long string*')).to.be(true);
expect(comedian.matches('test/long string*', '*st*ing')).to.be(true);
expect(comedian.matches('test/lo*', 'test/long string*')).to.be(true);
expect(comedian.matches('*/test/match', '*st*')).to.be(true);

// //miscellaneous
expect(comedian.matches('*/test/match', '*st/match')).to.be(true);
expect(comedian.matches('/test/match*', '/test/match/*')).to.be(true);
expect(comedian.matches('/test/ma*', '*tes*/ma*')).to.be(true);
expect(comedian.matches('*test/match', '/test/mat*')).to.be(true);
expect(comedian.matches('/test/mat*', '*test/match')).to.be(true);
expect(comedian.matches('*test/match', '/test/match')).to.be(true);
expect(comedian.matches('/test/mat*', '/test/match')).to.be(true);

// varied lengths
expect(comedian.matches('*t', 'wai/*/*/*t')).to.be(true);
expect(comedian.matches('t*', 't/*/*/l')).to.be(true);

// debatable...
expect(comedian.matches('*w*', 's*at')).to.be(true);

// negatives:

//non matching end
expect(comedian.matches('*/test/match', '*st/blah')).to.be(false);
expect(comedian.matches('*test/match', '/test/ma*rch')).to.be(false);

//non matching beginning
expect(comedian.matches('test/ma*ch', '/tst/ma*rch')).to.be(false);
expect(comedian.matches('/test/match*', '/blah/match/*')).to.be(false);

//no wildcard in the middle, bad end
expect(comedian.matches('*test/match', '/test/mar*')).to.be(false);
expect(comedian.matches('*test/march', '/test/mat*')).to.be(false);

//complex both sides but not matching a discernable pattern
expect(comedian.matches('t*lle', '*william/*')).to.be(false);
expect(comedian.matches('*test/mat', '*pe*st*')).to.be(false);

//for more, have a look at the tests

performance:

node 8 (no caching)
  • 10000 bi-directional compares in 950 milliseconds
  • 10000 left wildcard compares in 254 milliseconds
  • 10000 right wildcard compares in 258 milliseconds
matched 10000 randomly generated bi-directional paths:
  • milliseconds::: 1131
  • matched 10000 items in 1131ms
  • average time per match in ms: 0.1131
  • matches per sec: 8841.732979664015
node 0.10 (no caching)
  • 10000 bi-directional compares in 1003 milliseconds
  • 10000 10000 left wildcard compares in 306 milliseconds
  • 10000 10000 right wildcard compares in 271 milliseconds
  • 10000 complex compares in 49382 milliseconds, ouch, no way around this though...
matched 10000 randomly generated bi-directional paths:
  • milliseconds::: 932
  • matched 10000 items in 932ms
  • average time per match in ms: 0.0932
  • matches per sec: 10729.613733905579

supported node versions:

v0.10 - v8

caveats and gotchas

  • bi-directional wildcard matches can be very slow, especially when there are lots of 's: ie: simple simle
  • synchronous/blocking (this may or may not be a caveat)
  • a wildcard is a placeholder for anything and nothing
  • this is quite experimental - if you want to use this to land aircraft or operate cranes, please test, test, test and get back to me if you find anything that doesnt work
  • an lru cache can be configured to cache replies, this will significantly speed up repeated requests for the same matches, but if the patterns are more random we would suggest you dont use the caching