https://github.com/dcmox/urlparser
Crafting URL regex from scratch is hard mmkay?
https://github.com/dcmox/urlparser
parser regex uri url
Last synced: 10 months ago
JSON representation
Crafting URL regex from scratch is hard mmkay?
- Host: GitHub
- URL: https://github.com/dcmox/urlparser
- Owner: dcmox
- License: apache-2.0
- Created: 2020-01-12T20:07:22.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-19T23:35:50.000Z (over 6 years ago)
- Last Synced: 2025-08-18T07:52:06.566Z (10 months ago)
- Topics: parser, regex, uri, url
- Language: TypeScript
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# urlparser
[](https://david-dm.org/dwyl/esta) [](https://badge.fury.io/js/urlparser-simple)
Parses HTTP(S) and (S)FTP URLs. Not sure why I bothered crafting my own REGEX to try and handle nearly all URL conditions but I did.
## Usage
```typescript
import { parseUri } from '../urlparser'
console.log(parseUri('https://user:password@www.google.com:8000/test/url?param=blah&blah[]=test#hash.tag'))
```
Returns:
```
{
"authority": "user:password",
"fragment": "hash.tag",
"host": "www.google.com",
"path": "test/url",
"port": 8000,
"query": "param=blah&blah[]=test#arr",
"request": "https://user:password@www.google.com:8000/test/url?param=blah&blah[]=test#hash.tag",
"scheme": "https",
"tld": "com",
"valid": true,
}
```
parseUri() accepts a second parameter "strict" (boolean) which enforces the standard ASCII character set for URLs if set to true.
## Bugs
Feel free to report bugs :)