RUTValidator is a Library made in Swift to Validate and Format a Chilean RUT (Rol Unico Tributario)
RUTValidator is a Library made in Swift to Validate and Format a Chilean RUT (Rol Unico Tributario)
- RUT Validator
- iOS 11+
- Xcode 11
- Swift 5.0
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
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"
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)
We would love you for the contribution to RUTValidator, check the LICENSE
file for more info.
- Magno Cardona aka Magno por la Chucha (acidfilez@gmail.com)
- Carlos Alcala aka Charles Xavier (Profesori) (carlos.alcala@me.com)
RUTValidator is distributed under the MIT license. See LICENSE
for more information.