Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bo-carey/urlglob
A simple yet powerful TypeScript library for URL globbing. Provides an easier alternative to regular expression for URL matching patterns.
https://github.com/bo-carey/urlglob
matching regex uri url
Last synced: 12 days ago
JSON representation
A simple yet powerful TypeScript library for URL globbing. Provides an easier alternative to regular expression for URL matching patterns.
- Host: GitHub
- URL: https://github.com/bo-carey/urlglob
- Owner: bo-carey
- License: mit
- Created: 2021-10-30T19:58:05.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-09T17:47:43.000Z (about 1 year ago)
- Last Synced: 2024-12-08T10:07:46.037Z (about 1 month ago)
- Topics: matching, regex, uri, url
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@bo-carey/urlglob
- Size: 329 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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:
```typescript
var { matchUrl } = require('@bo-carey/urlglob');
```The `matchUrl` function takes two arguments:
1. The URL you want to check.
2. The pattern you want to match it with.Here's an example usage:
```typescript
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:
1. `*` : Matches zero or more characters within a single URL section (e.g., domain or path).
2. `**` : 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.