andreyvit / urlmatch.js

URL host/port/path matching (kind of like fnmatch)
1 stars 1 forks source link

urlmatch.js

Synopsis:

var urlmatch = require('urlmatch');
if (urlmatch(pattern, url)) { ... }

Example:

if (urlmatch("livereload.com", "http://livereload.com/help/")) {
  console.log("It works!");
}

Pattern syntax:

See the spec below for more examples.

Installation

npm install urlmatch

Running tests

npm install               # just once
npm test                  # see package.json for the test command
REPORTER=dot npm test     # override the reporter

Spec

urlmatch
  with pattern 'livereload.com'
    ✓ should match 'http://livereload.com'
    ✓ should match 'http://livereload.com/'
    ✓ should match 'http://livereload.com:80'
    ✓ should match 'http://livereload.com:3000'
    ✓ should match 'http://livereload.com/help/'
    ✓ should match 'https://livereload.com'
    ✓ shouldn't match 'http://example.com/'
    ✓ shouldn't match 'http://foo.livereload.com'
    ✓ shouldn't match 'https://foo.livereload.com/'
  with pattern 'http://livereload.com'
    ✓ should match 'http://livereload.com'
    ✓ should match 'http://livereload.com/'
    ✓ should match 'http://livereload.com:80'
    ✓ should match 'http://livereload.com:3000'
    ✓ should match 'http://livereload.com/help/'
    ✓ shouldn't match 'http://example.com/'
    ✓ shouldn't match 'https://livereload.com'
    ✓ shouldn't match 'https://foo.livereload.com/'
    ✓ shouldn't match 'http://foo.bar.livereload.com'
    ✓ shouldn't match 'http://foo.bar.livereload.com/help/'
  with pattern 'https://livereload.com'
    ✓ should match 'https://livereload.com'
    ✓ shouldn't match 'http://example.com/'
    ✓ shouldn't match 'http://livereload.com'
  with pattern 'livereload.com:3000'
    ✓ should match 'http://livereload.com:3000'
    ✓ should match 'http://livereload.com:3000/help/'
    ✓ shouldn't match 'http://example.com/'
    ✓ shouldn't match 'http://foo.bar.livereload.com'
    ✓ shouldn't match 'http://foo.bar.livereload.com/help/'
    ✓ shouldn't match 'https://livereload.com'
    ✓ shouldn't match 'http://livereload.com/'
    ✓ shouldn't match 'http://livereload.com:80'
  with pattern 'livereload.com:80'
    ✓ should match 'http://livereload.com/'
    ✓ should match 'http://livereload.com:80'
    ✓ should match 'http://livereload.com/help/'
    ✓ should match 'http://livereload.com:80'
    ✓ should match 'http://livereload.com:80/help/'
    ✓ shouldn't match 'http://example.com/'
    ✓ shouldn't match 'https://livereload.com'
    ✓ shouldn't match 'http://livereload.com:3000'
    ✓ shouldn't match 'http://foo.bar.livereload.com'
    ✓ shouldn't match 'http://foo.bar.livereload.com/help/'
  with pattern '*.livereload.com'
    ✓ should match 'http://livereload.com/'
    ✓ should match 'https://livereload.com'
    ✓ should match 'http://foo.livereload.com'
    ✓ should match 'https://foo.livereload.com'
    ✓ should match 'http://foo.bar.livereload.com'
    ✓ shouldn't match 'http://example.com/'
  with pattern 'livereload.com/help'
    ✓ should match 'http://livereload.com/help/index.html'
    ✓ should match 'https://livereload.com/help/index.html'
    ✓ should match 'http://livereload.com:3000/help/index.html'
    ✓ should match 'http://livereload.com:3000/help/index.html'
    ✓ should match 'http://livereload.com:3000/help-topics/index.html'
    ✓ shouldn't match 'http://livereload.com/'
    ✓ shouldn't match 'http://example.com/'
    ✓ shouldn't match 'http://example.com/help/index.html'
    ✓ shouldn't match 'http://foo.livereload.com/help/index.html'

License

© 2012, Andrey Tarantsov. Distributed under the MIT license.