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

fuzzyurl

v0.9.0

Published

A library for non-strict parsing, construction, and wildcard-matching of URLs.

Downloads

6,624

Readme

Fuzzyurl

Build Status npm version

Non-strict parsing, composition, and wildcard matching of URLs in JavaScript.

Introduction

Fuzzyurl provides two related functions: non-strict parsing of URLs or URL-like strings into their component pieces (protocol, username, password, hostname, port, path, query, and fragment), and fuzzy matching of URLs and URL patterns.

Specifically, URLs that look like this:

[protocol ://] [username [: password] @] [hostname] [: port] [/ path] [? query] [# fragment]

Fuzzyurls can be constructed using some or all of the above fields, optionally replacing some or all of those fields with a * wildcard if you wish to use the Fuzzyurl as a URL mask.

Installation

For Node.js projects, place the following in package.json's dependencies object:

"fuzzyurl": "~> 0.9.0"

For in-browser usage:

<script src="path/to/fuzzyurl.min.js"></script>

Parsing URLs

> Fuzzyurl.fromString("https://api.example.com/users/123?full=true")
Fuzzyurl {
  protocol: 'https',
  username: undefined,
  password: undefined,
  hostname: 'api.example.com',
  port: undefined,
  path: '/users/123',
  query: 'full=true',
  fragment: undefined }

Constructing URLs

> var f = new Fuzzyurl({hostname: "example.com", protocol: "http", port: "8080"});
> f.toString()
'http://example.com:8080'

Matching URLs

Fuzzyurl supports wildcard matching:

  • * matches anything, including null.
  • foo* matches foo, foobar, foo/bar, etc.
  • *bar matches bar, foobar, foo/bar, etc.

Path and hostname matching allows the use of a greedier wildcard ** in addition to the naive wildcard *:

  • *.example.com matches filsrv-01.corp.example.com but not example.com.
  • **.example.com matches filsrv-01.corp.example.com and example.com.
  • /some/path/* matches /some/path/foo/bar and /some/path/ but not /some/path
  • /some/path/** matches /some/path/foo/bar and /some/path/ and /some/path

The Fuzzyurl.mask function aids in the creation of URL masks.

> Fuzzyurl.mask()
Fuzzyurl { protocol: '*', username: '*', password: '*', hostname: '*',
  port: '*', path: '*', query: '*', fragment: '*' }

> Fuzzyurl.matches(Fuzzyurl.mask(), "http://example.com:8080/foo/bar")
true

> var mask = Fuzzyurl.mask({path: "/a/b/**"})
> Fuzzyurl.matches(mask, "https://example.com/a/b/")
true
> Fuzzyurl.matches(mask, "git+ssh://[email protected]/a/b")
true
> Fuzzyurl.matches(mask, "https://example.com/a/bar")
false

Fuzzyurl.bestMatch, given a list of URL masks and a URL, will return the given mask which most closely matches the URL:

> var masks = ["/foo/*", "/foo/bar", Fuzzyurl.mask()];
> Fuzzyurl.bestMatch(masks, "http://example.com/foo/bar");
"/foo/bar"

If you'd prefer the array index of the matching mask, use Fuzzyurl.bestMatchIndex instead:

> Fuzzyurl.bestMatchIndex(masks, "http://example.com/foo/bar");
1

Contributors

Many thanks to the people who've sent pull requests and improved this code:

Authorship and License

Fuzzyurl is copyright 2015-2016, Pete Gamache.

Fuzzyurl is released under the MIT License. See LICENSE.txt.

If you got this far, you should probably follow me on Twitter: @gamache