GithubHelp home page GithubHelp logo

persian-tools / swift-persian-tools Goto Github PK

View Code? Open in Web Editor NEW
22.0 4.0 3.0 46 KB

Swift version of Persian Tools

License: MIT License

Ruby 5.99% Swift 93.56% Objective-C 0.46%
number-to-words add-remove-comma validate-iranian-nationalid bill-calculator iban-validation validate-card-number

swift-persian-tools's Introduction

Swift Persian tools

Swift version of Persian Tools

Build Status codecov GitHub license PRs Welcome


Features

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate SwiftPersianTools into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'SwiftPersianTools', '1.1.0'

Usage

Convert Numbers to Persian words

import SwiftPersianTools

let number: Int = 1546
number.convertToPersianText()   /// "یک هزار و پانصد و چهل و شش"

Add and remove commas to numbers

import SwiftPersianTools

let strNumber = "9423511"
strNumber.addComma()   /// "۹٬۴۲۳٬۵۱۱"

let strNumber = "9,423,511"
strNumber.removeComma()   /// "9423511"

Convert Persian numbers to Arabic or English numbers and vice versa

import SwiftPersianTools

"123۴۵۶".digitsEntoFa()   /// "۱۲۳۴۵۶"
"٤٥٦".digitsEntoFa()      /// "٤٥٦"
"12۴۵۶3".digitsEntoFa()   /// "۱۲۴۵۶۳"


"1234567891".digitsEntoAr() /// "۱۲۳٤٥٦۷۸۹۱"
"123٤٥٦".digitsEntoAr()     /// "۱۲۳٤٥٦"

"۱۲۳۴۵۶".digitsFatoEn()  /// "123456"
"456".digitsFatoEn()     /// "456"
"۱۲۴۵۶۳".digitsFatoEn()  /// "124563"

"٠١٢٣٤٥٦٧٨٩".digitsArtoFa()        /// "٠١٢٣۴۵۶٧٨٩"
"۸۹123۴٥".digitsArtoFa()           /// "۸۹123۴۵"
"Text ٠١٢٣٤٥٦٧٨٩".digitsArtoFa()   /// "Text ٠١٢٣۴۵۶٧٨٩"

"۰۱۲۳٤٥٦۷۸۹".digitsArtoEn()   /// "0123456789"
"۸۹123٤٥".digitsArtoEn()      /// "8912345"

Validate Iranian national number(code-e Melli)

import SwiftPersianTools

var codeMelli = "0499370899"
codeMelli.isValidIranianNationallCode()   /// true

codeMelli = "0963695398"
codeMelli.isValidIranianNationallCode()   /// true

codeMelli = "0067749828"
codeMelli.isValidIranianNationallCode()   /// true

codeMelli = "0684159415"
codeMelli.isValidIranianNationallCode()   /// false

Find city and province name by national-id(code-e Melli)

import SwiftPersianTools

var nationalId = "0499370899"
nationalId.getPlaceByIranNationalId()?.city   /// "شهرری"

nationalId = "0790419904"
nationalId.getPlaceByIranNationalId()?.city   /// "سبزوار"

"0084575948".getPlaceByIranNationalId()?.city /// "تهران مرکزی"

"0060495219".getPlaceByIranNationalId()?.city /// "تهران مرکزی"

"0671658506".getPlaceByIranNationalId()?.city /// "بجنورد"

"0643005846".getPlaceByIranNationalId()?.city /// "بیرجند"

"0906582709".getPlaceByIranNationalId()?.city /// "کاشمر"

"0451727304".getPlaceByIranNationalId()?.city /// "شمیران"

"0371359058".getPlaceByIranNationalId()?.city /// "قم"

Bank number validation

import SwiftPersianTools

var cardNumber = "6037701689095443"
cardNumber.verifyCardNumber()   /// true

cardNumber = "6219861034529007"
cardNumber.verifyCardNumber()   /// true

cardNumber = "6219861034529008"
cardNumber.verifyCardNumber()   /// false

"6219861034529007002229988112233".verifyCardNumber()   /// false

Find Bank's name by Card number

import SwiftPersianTools

var cardNumber = "6219861034529007"
cardNumber.getBankNameFromCardNumber()   /// بانک سامان

Bill calculator

Method Description Return type
getResult Result of bill calculated information BillResult
getAmount Calculate Bill amount by payment id and bill id which entered by the Bill constructor Double
getType Get Bill provider type name String
getBarcode Calculate and get Bill's barcode String
verifyBill Validate entered both Bill id and payment id, and return true if bill id and payment id relation was true Bool
verifyBillId Validate entered Bill id Bool
verifyBillPayment Validate entered Bill payment id Bool
import SwiftPersianTools

var bill = Bill(billId: "7748317800142", billPayment: "1770160").getResult()

Bill(billId: "1117753200140", billPayment: "12070160").getAmount()       /// 120000

Bill(billId: "1117753200140", billPayment: "12070160", currency: .toman) /// 12000

Bill(billId: "7748317800142", billPayment: "12070160").getType()         /// تلفن ثابت

Bill(billId: "9174639504124", billPayment: "12070160").getType()         /// برق

Bill(billId: "2050327604613", billPayment: "12070160").getType()         /// آب

Bill(billId: "9100074409151", billPayment: "12070160").getType()         /// تلفن همراه

Bill(billId: "7748317800105", billPayment: "12070160").getType()         /// unknown

Bill(billId: "7748317800142", billPayment: "1770160").getBarcode()       /// "77483178001420001770160"

Bill(billId: "7748317800142", billPayment: "1770160").verifyBillPayment() /// true

Bill(billId: "9174639504124", billPayment: "12908197").verifyBillPayment() /// false

Bill(billId: "7748317800142", billPayment: "1770160").verifyBillId       /// true

Bill(billId: "2234322344613", billPayment: "1070189").verifyBillId       /// false

Iranian Sheba(IBAN)

  • Check validation
import SwiftPersianTools

var sheba = "IR820540102680020817909002"
sheba.validateIranianSheba()   /// true

sheba = "IR01234567890123456789"
sheba.validateIranianSheba()   /// false

License

MIT

swift-persian-tools's People

Contributors

ali-master avatar behrad-kzm avatar saeed-rz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.