An open API service indexing awesome lists of open source software.

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

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)