dan085 / RUTValidator

A Chilean RUT Validator for Swift 5

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RUTValidator

RUTValidator is a Library made in Swift to Validate and Format a Chilean RUT (Rol Unico Tributario)

Build Status Swift 5.0 License Carthage compatible CocoaPods Compatible
Platform PRs Welcome

RUTValidator is a Library made in Swift to Validate and Format a Chilean RUT (Rol Unico Tributario)

Features

  • RUT Validator

Requirements

  • iOS 11+
  • Xcode 11
  • Swift 5.0

Installation

CocoaPods

You can use CocoaPods to install RUTValidator by adding it to your Podfile:

platform :ios, '11.0'
use_frameworks!
pod 'RUTValidator'

To get the full benefits import RUTValidator wherever you need it

import RUTValidator

Carthage

Create a Cartfile that lists the framework and run carthage update. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/RUTValidator.framework to an iOS project.

github "devcarlos/RUTValidator"

Code Examples

import RUTValidator
//Test Example validateRUT
let unformattedRut = "19"
let formattedRut = "1-9"
let validator = RUTValidator.validateRUT(unformattedRut)

XCTAssertTrue(validator.isValid)
XCTAssertEqual(validator.formatted, formattedRut)
//Test Example formatRut
let realFormatedRut = RUTValidator.formatRut(unformattedRut)
XCTAssertEqual(formattedRut, realFormatedRut)
//Test Example getVerificationDigit
let bodyRut = "9043943"
let formattedRut = "9.043.943-k"
let rawRut = "9043943k"
let validator = RUTValidator.getVerificationDigit(rutBody: bodyRut)
XCTAssertTrue(validator.isValid)
XCTAssertEqual(validator.formatted, formattedRut)
XCTAssertEqual(validator.rawRut, rawRut)
//Test Example calculateVerificationDigit
let bodyRut = "9043943"
let dv = Int(10)
let calculatedDV = RUTValidator.calculateVerificationDigit(rutBody: bodyRut)
XCTAssertEqual(calculatedDV, dv)
//Test Example cleanRUT
let unformattedRut = "20.961.605-K"
let expectedCleanRut = "20961605K"
let cleanRut = RUTValidator.cleanRut(unformattedRut)
XCTAssertEqual(cleanRut, expectedCleanRut)

Contribute

We would love you for the contribution to RUTValidator, check the LICENSE file for more info.

Author

License

RUTValidator is distributed under the MIT license. See LICENSE for more information.

Meta

Build Status Swift 5.0 License Carthage compatible CocoaPods Compatible
Platform PRs Welcome

About

A Chilean RUT Validator for Swift 5

License:MIT License


Languages

Language:Swift 98.3%Language:Ruby 1.1%Language:Objective-C 0.7%