https://github.com/twodayslate/addressurl
Useful extension for URL to support IP and email addresses
https://github.com/twodayslate/addressurl
email ip ipv4 ipv6 network swift swift-package
Last synced: 11 months ago
JSON representation
Useful extension for URL to support IP and email addresses
- Host: GitHub
- URL: https://github.com/twodayslate/addressurl
- Owner: twodayslate
- Created: 2020-02-16T19:05:17.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-08-20T02:26:31.000Z (almost 4 years ago)
- Last Synced: 2024-05-01T22:11:26.515Z (about 2 years ago)
- Topics: email, ip, ipv4, ipv6, network, swift, swift-package
- Language: Swift
- Homepage:
- Size: 16.6 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AddressURL
A simple Swift Package that extends URL with some helpful functions for IP and email address
Requires iOS 12.0+ since the [Network](https://developer.apple.com/documentation/network) API is used.
For domain information check out [TLDExtractSwift](https://github.com/gumob/TLDExtractSwift).
## Usage
IP Address can be converted to URLs
```swift
IPv4Address("8.8.8.8").url.with(component: .scheme("https")!.absoluteString // https://8.8.8.8
IPv6Address("::").url.with(component: .scheme("https")!.absoluteString // https://[::]
```
Alternativly you can get an IP Address from a URL
```swift
let url = URL(string: "https://8.8.8.8")
url.ipv4Address // 8.8.8.8
let url2 = URL(string: "https://[::]")
url.ipv6Address // ::
```
Specific URLComponents can be changed
```swift
let url = URL(string: "https://zac.gorak.us")
url.with(component: .scheme("ftp") // ftp://zac.gorak.us
```
Email addresses
```swift
let url = URL(email: "hello@gorak.us")
url.absoluteString // mailto://hello@gorak.us
url.emailAddress // hello@gorak.us
```
Email address parsing is handled by [EmailValidator](https://github.com/evanrobertson/EmailValidator)