Swiftpack.co - tokopedia/ios-supervalidator as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by tokopedia.
tokopedia/ios-supervalidator 0.1.0
SuperValidator is option-based validator for Swift.
⭐️ 3
🕓 3 weeks ago
iOS
.package(url: "https://github.com/tokopedia/ios-supervalidator.git", from: "0.1.0")

CoverImage

SuperValidator

SuperValidator is option-based validator for Swift.

Installation

Pods

To install via Pods just add this to your podfile.

pod 'SuperValidator', :git => 'https://github.com/tokopedia/ios-supervalidator.git'

Swift Package Manager

To install via SPM just press '+' sign in Xcode list of packages and paste repo address: 'https://github.com/tokopedia/ios-supervalidator' into the search field and click Add Package:

SPM installation

Basic Usage

Return a boolean value

let validator = SuperValidator.shared
let url = "https://www.tokopedia.com/shop/test"
let isURL = validateURL(url, options: .init())
print(isURL) // true

With custom options. For detail explanation here.

let validator = SuperValidator.shared
let url = "https://www.tokopedia.com/shop/test"
let options = SuperValidator.Option.URL = .init(
	protocols: ["https", "http"],
	requireProtocol: true,
	requireValidProtocol: true,
	paths: ["/shop/{shopSlug}"],
	allowQueryComponents: false,
	domainWhitelist: [#"(www\.)?(tokopedia\.com)"#],
	domainBlacklist: [],
	fqdn: .init()
)

let isURL = validator.isURL(url, options: options)
print(isURL) // true

Return result success or error with reasons

let validator = SuperValidator.shared
let url = "https://www.tokopedia.com/shop/test"
let result = validateURL(url, options: .init())

switch result {
case let .failure(error):
    switch error {
    case .notUrl:
        print("Please enter an url")
    case .containsWhitespace:
        print("Can't have whitespace")
    case .containsQueryComponents:
        print("Can't contains query components")
    case .invalidProtocol:
        print("Only allow HTTPS")
    case .noProtocol:
        print("Please provide protocol / scheme")
    case .invalidPath:
        print("Url path is invalid")
    case .invalidDomain:
        print("Wrong domain")
    case .blacklistedDomain:
        print("Domain not allowed")
    case .invalidFQDN:
        print("Enter a valid url")
    }

case .success: break
}

Validators

Help

If you want to discuss the SuperValidator or have a question about how to use it to solve your video player problem, you can start a topic in the issues tab of this repo

Future Plans

  • Bind with TextField
  • Bind with Rx
  • More incoming validators

Credits

SuperValidator is written and maintaned by Tokopedia iOS Superman Squad. Alvin Matthew Pratama actively works to maintain SuperValidator. Thanks to Christopher Teddy Mienarto for helps creating email, phone number and more incoming validators.

License

This library is released under the Apache license. See LICENSE for details.

GitHub

link
Stars: 3
Last commit: 6 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

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