Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
fuzzyurl
Advanced tools
Readme
Non-strict parsing, composition, and wildcard matching of URLs in JavaScript.
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.
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>
> 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 }
> var f = new Fuzzyurl({hostname: "example.com", protocol: "http", port: "8080"});
> f.toString()
'http://example.com:8080'
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://jen@example.com/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
Many thanks to the people who've sent pull requests and improved this code:
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
FAQs
A library for non-strict parsing, construction, and wildcard-matching of URLs.
The npm package fuzzyurl receives a total of 407 weekly downloads. As such, fuzzyurl popularity was classified as not popular.
We found that fuzzyurl demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.