Swiftpack.co - ssb-swift/StringIsValidDomain as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by ssb-swift.
ssb-swift/StringIsValidDomain 1.0.1
Validate domain names in Swift
⭐️ 0
🕓 2 years ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/ssb-swift/StringIsValidDomain.git", from: "1.0.1")

StringIsValidDomain

Validate domain names in Swift | is-valid-domain

Demo

https://lab.miguelmota.com/is-valid-domain

Install

Add the following to the Package.swift dependencies:

.package(url: "https://github.com/ssb-swift/StringIsValidDomain", from: "1.0.0")

Or add the package in Xcode.

Usage

import StringIsValidDomain

"example.com".isValidDomain())                                          // true
"foo.example.com".isValidDomain())                                      // true
"bar.foo.example.com".isValidDomain())                                  // true
"exa-mple.co.uk".isValidDomain())                                       // true
"xn--80ak6aa92e.com".isValidDomain())                                   // true
"_dnslink.ipfs.io".isValidDomain())                                     // true
"exa_mple.com".isValidDomain())                                         // false
"-example.co.uk".isValidDomain())                                       // false
"example".isValidDomain())                                              // false
"ex*mple.com".isValidDomain())                                          // false
"*.example.com".isValidDomain())                                        // false
"*.com".isValidDomain())                                                // false

"foo.example.com".isValidDomain([.subdomain: true])                     // true
"foo.example.com".isValidDomain([.subdomain: false])                    // false
"*.example.com".isValidDomain([.wildcard: false])                       // false
"*.example.com".isValidDomain([.wildcard: true])                        // true
"*.example.com".isValidDomain([.subdomain: false, .wildcard: true])     // false
"はじめよう.みんな".isValidDomain()                                         // false
"はじめよう.みんな".isValidDomain([.allowUnicode: true])                    // true

View more examples.

Contributing

swift-format

This project uses [swift-format][swift-format] for automatic code formatting as a pre-commit hook; Use the following instructions to set up swift-format for your environment:

Install swift-format

cd <repository-location>
git clone -b swift-5.4-branch https://github.com/apple/swift-format.git
cd swift-format
swift build

Add switf-format to your PATH

export PATH=$PATH:~/<repository-location>/swift-format/.build/x86_64-apple-macosx/debug

Don't forget to reload your Terminal configuration.

Create the Git hook

  • Create the pre-commit file in the project's .git/hooks directory.
touch .git/hooks/pre-commit
  • Give the file execution rights:
sudo chmod +x .git/hooks/pre-commit
  • Add the following script to the pre-commit file and save the changes:
#!/bin/bash
swift-format --version 1>/dev/null 2>&1
if [ $? -eq 0 ]
then
    git diff --diff-filter=d --staged --name-only | grep -e '\(.*\).swift$' | while read line; do
        swift-format -i "${line}";
        git add "$line";
    done
fi

Now, every time you commit new changes in the project, swift-format will automatically format them before committing them.

FAQ

  • Q: Why is trailing dot . in domain names verified as true?

    • A: Fully qualified domain names allow the trailing dot which represents the root zone. More info here and here.

GitHub

link
Stars: 0
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

Release Notes

Release v1.0.1
2 years ago
  • Parse labels to String on initialization

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics