@bo-carey/urlglob
v1.2.1
Published
A lightweight TypeScript library for matching URLs with glob patterns
Downloads
9
Maintainers
Readme
@bo-carey/urlglob
A simple yet powerful TypeScript library for URL globbing. Provides an easier alternative to regular expression for URL matching patterns.
Installation
You can install this library using npm:
npm install @bo-carey/urlglob
How to use
First, import the matchUrl
function from the library:
var { matchUrl } = require('@bo-carey/urlglob');
The matchUrl
function takes two arguments:
- The URL you want to check.
- The pattern you want to match it with.
Here's an example usage:
var doesMatch = matchUrl('http://google.com', 'http://google.*');
console.log(doesMatch); // Prints true or false
Matching symbols
This library supports two types of globbing symbols:
*
: Matches zero or more characters within a single URL section (e.g., domain or path).**
: Matches zero or more characters across URL sections.
For example, the pattern http://google.*
would match 'http://google.com' or 'http://google.net', but would not match 'http://google.com/example'.
For more complex patterns or to match across URL sections, you can use **
. For example, the pattern http://google.**
would match 'http://google.com', 'http://google.net/example', 'http://google.com/example/example2', and so on.
Notes
Remember, the patterns are converted to regular expressions behind the scenes, but the advantage of using this library is that the globbing patterns are much simpler to write and understand for common use cases.