Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jc3213/matchpattern.js
A Javascript library that manages mach patterns for matching urls
https://github.com/jc3213/matchpattern.js
javascript javascript-library match-pattern url-matching
Last synced: 6 days ago
JSON representation
A Javascript library that manages mach patterns for matching urls
- Host: GitHub
- URL: https://github.com/jc3213/matchpattern.js
- Owner: jc3213
- License: lgpl-2.1
- Created: 2024-05-31T03:41:48.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-01-08T03:59:49.000Z (27 days ago)
- Last Synced: 2025-01-08T04:31:00.975Z (27 days ago)
- Topics: javascript, javascript-library, match-pattern, url-matching
- Language: JavaScript
- Homepage: https://jc3213.github.io/matchpattern.js/
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Usage
### Download
[Latest](https://jc3213.github.io/matchpattern.js/matchpattern.js)### HTML
```HTML```
### TamperMonkey
```javascript
// @require https://jc3213.github.io/matchpattern.js/matchpattern.js
```## Method
- [create](#create)
- [generate](#generate)### create
```javascript
let pattern = MatchPattern.create("www.example.com"); // *.example.com
```
- [pattern](#pattern)
- `string`
- url
- `string`
- `https://www.example.com/pathname`
- `www.example.com`
- `*.example.com`#### pattern
- `*.example.com`
- Matches `www.example.com`, `example.com`
- Doesn't Match `test-example.com`, `www.example.com.cn`
- `example.*`
- Matches `example.com`, `example.co.uk`
- Doesen't Match `www.example.com`, `example-test.com`| Match Pattern | Target Hostname |
| :-: | :-: |
| \ | All hostnames |
| www.university.org.eu
\*.university.org.eu
\*.org.eu | www.university.org.eu |
| doc.university.org.eu
doc.university.org.*
doc.university.* | doc.university.org.eu |
| 192.168.1.\*
192.168.\*
192.\* | 192.168.1.1 |### generate
```javascript
let { regexp, string } = MatchPattern.generate( [ patternA, patternB, ..., patternZ ] );
```
- [regexp](#regexp)
- `Regular Expression`
- `/^(patternA|patternB|...|patternZ)$/i`
- string
- `string`
- `^(patternA|patternB|...|patternZ)$`
- pattern
- `string`
- `*.some.host`
- `192.168.*`
- Don't support ipv6 though