Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat [digits]: add p2e and e2p functions. #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
- [x] Digits
- [x] Validate Bank card number.
- [x] Find Bank's name by Card number.
- [X] Check Iranian Sheba(IBAN) validation and recognize bank information by sheba code.
- [X] Add and remove commas to numbers.
- [X] Find city and province name by national code(code-e Melli).
- [X] Validate Iranian national number(code-e Melli).
- [x] Check Iranian Sheba(IBAN) validation and recognize bank information by sheba code.
- [x] Add and remove commas to numbers.
- [x] Find city and province name by national code(code-e Melli).
- [x] Validate Iranian national number(code-e Melli).

#### How to use it?

Expand All @@ -40,7 +40,7 @@ And pass it
##### Bills

```go
result := bills.GetBillType(params) // تلفن ثابت
result := bills.GetBillType(params) // تلفن ثابت
amount := bills.GetCurrency(params) //120000
barcode := bills.GetBarCode(params) // 111775320014000012070160
verify := bills.VerifyBillID(params) //true
Expand All @@ -50,9 +50,11 @@ verify := bills.VerifyBillID(params) //true
##### Digits

```go
num2wordFa := digits.DigitToWord("۱۵۶۷۸۹") // صد پنجاه و شش هزار هفتصد هشتاد و نه
num2wordEn := digits.DigitToWord("156789") // صد پنجاه و شش هزار هفتصد هشتاد و نه
Negative := digits.DigitToWord("-156789") // منفی صد پنجاه و شش هزار هفتصد هشتاد و نه
num2wordFa := digits.DigitToWord("۱۵۶۷۸۹") // صد پنجاه و شش هزار هفتصد هشتاد و نه
num2wordEn := digits.DigitToWord("156789") // صد پنجاه و شش هزار هفتصد هشتاد و نه
Negative := digits.DigitToWord("-156789") // منفی صد پنجاه و شش هزار هفتصد هشتاد و نه
englishDigits := PersianToEnglish("۱۲۳۴۵۶۷۸۹۰") // 1234567890
persianDigits := EnglishToPersian("1234567890") // ۱۲۳۴۵۶۷۸۹۰
```

#### Bank
Expand All @@ -71,6 +73,7 @@ bank,error := CardInfo("6219861034529007") // saman, nil
```

###### Check Iranian Sheba

The types of results are :

```go
Expand Down Expand Up @@ -99,22 +102,24 @@ sheba := shebaCode.IsSheba() // { false }
addComma := digits.AddCommas(14555478854)
removeComma := digits.RemoveCommas("4,555,522,212,12")

fmt.Printf("\n ADD COMMA : %v \n", addComma) // 14,555,478,854
fmt.Printf("\n REMOVE COMMA : %v \n", removeComma)// 455552221212
fmt.Printf("\n ADD COMMA : %v \n", addComma) // 14,555,478,854
fmt.Printf("\n REMOVE COMMA : %v \n", removeComma)// 455552221212
```

###### Get Place and city By NationalID

```go
getPlaceByIranNationalId := city.GetPlaceByIranNationalId("0499370899")
fmt.Printf("\n Result : %v \n", getPlaceByIranNationalId)

```

###### Validate Iranian national number(code-e Melli)

```go
verifyIranianNationalId := national_id.Validate("0067749828")
verifyIranianNationalIdFalse := national_id.Validate("0684159415")

fmt.Printf("\n Validate NationalID : %v \n", verifyIranianNationalId) // true
fmt.Printf("\n Validate NationalIDFalse : %v \n", verifyIranianNationalIdFalse) // false
```
```
31 changes: 30 additions & 1 deletion digit/digit_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package digit

import "testing"
import (
"testing"
)

func TestDigitToWord(t *testing.T) {
num2word1 := DigitToWord("۱۵۶۷۸۹")
Expand Down Expand Up @@ -37,3 +39,30 @@ func TestRemoveCommas(t *testing.T) {
}

}

func TestEnglishToPersian(t *testing.T) {
// expect number 1234567890 to turn into ۱۲۳۴۵۶۷۸۹۰
persianDigits := EnglishToPersian("1234567890")
if persianDigits != "۱۲۳۴۵۶۷۸۹۰" {
t.Errorf("Wrong Converting English Digits To Persian: %v", persianDigits)
}

// expect misc characters to stay the same
persianDigitsWithMisc := EnglishToPersian("1!2@3#4$5%6^7&8*9(0)-=")
if persianDigitsWithMisc != "۱!۲@۳#۴$۵%۶^۷&۸*۹(۰)-=" {
t.Errorf("Wrong Converting Persian Digits To English: %v", persianDigitsWithMisc)
}
}

func TestPersianToEnglish(t *testing.T) {
// expect number 1234567890 to turn into ۱۲۳۴۵۶۷۸۹۰
englishDigits := PersianToEnglish("۱۲۳۴۵۶۷۸۹۰")
if englishDigits != "1234567890" {
t.Errorf("Wrong Converting Persian Digits To English: %v", englishDigits)
}
// expect misc characters to stay the same
englishDigitsWithMisc := PersianToEnglish("۱!۲@۳#۴$۵%۶^۷&۸*۹(۰)-=")
if englishDigitsWithMisc != "1!2@3#4$5%6^7&8*9(0)-=" {
t.Errorf("Wrong Converting Persian Digits To English: %v", englishDigitsWithMisc)
}
}
28 changes: 28 additions & 0 deletions digit/english_to_persian.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package digit

import "strings"

var englishToPersianMap = map[rune]rune{
'0': '۰',
'1': '۱',
'2': '۲',
'3': '۳',
'4': '۴',
'5': '۵',
'6': '۶',
'7': '۷',
'8': '۸',
'9': '۹',
}

func EnglishToPersian(input string) string {
var result strings.Builder
for _, char := range input {
if persChar, found := englishToPersianMap[char]; found {
result.WriteRune(persChar)
} else {
result.WriteRune(char)
}
}
return result.String()
}
28 changes: 28 additions & 0 deletions digit/persian_to_english.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package digit

import "strings"

var persianToEnglishMap = map[rune]rune{
'۰': '0',
'۱': '1',
'۲': '2',
'۳': '3',
'۴': '4',
'۵': '5',
'۶': '6',
'۷': '7',
'۸': '8',
'۹': '9',
}

func PersianToEnglish(input string) string {
var result strings.Builder
for _, char := range input {
if engChar, found := persianToEnglishMap[char]; found {
result.WriteRune(engChar)
} else {
result.WriteRune(char)
}
}
return result.String()
}