Skip to content

Commit

Permalink
fix: some typo
Browse files Browse the repository at this point in the history
  • Loading branch information
ali77gh committed Apr 6, 2024
1 parent f0b3b0b commit 661743d
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 49 deletions.
18 changes: 9 additions & 9 deletions src/bill/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
//! use rust_persian_tools::bill::BillType;
//!
//! let bill_id = BillID::new("77483178", "001", BillType::Tel).unwrap();
//! let payment_id = PaymentID::new(17, 7, 1, &bill_id).unwrap(); // Thousands are ommited from amount
//! let payment_id = PaymentID::new(17, 7, 1, &bill_id).unwrap(); // Thousands are omitted from amount
//! let bill = Bill::new(bill_id, payment_id).unwrap();
//! assert_eq!(bill.get_bill_type(), BillType::Tel); // Fixed Landline
//! assert_eq!(bill.get_bill_id(), "7748317800142");
Expand Down Expand Up @@ -81,7 +81,7 @@ pub enum BillError {
InvalidBillIDYear,
#[error("Bill Period is not parable")]
InvalidBillIDPeriod,
#[error("Checksome doesnt match")]
#[error("Checksum doesn't match")]
InvalidBillChecksum,
#[error("Bill Type is not parsable")]
InvalidBillType,
Expand Down Expand Up @@ -122,7 +122,7 @@ pub enum BillType {
Tax = 7,
/// جریمه راهنمایی و رانندگی
/// Service Type Code: 8
DrivingOffence = 8,
DrivingOffense = 8,
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down Expand Up @@ -203,7 +203,7 @@ impl BillID {
}
}
impl ToString for BillID {
/// Returns String representaion of Bill ID
/// Returns String representation of Bill ID
fn to_string(&self) -> String {
format!(
"{}{:03}{:1}{:1}",
Expand Down Expand Up @@ -285,7 +285,7 @@ impl std::str::FromStr for PaymentID {
}

impl ToString for PaymentID {
/// Returns String representaion of Bill ID
/// Returns String representation of Bill ID
fn to_string(&self) -> String {
format!(
"{}{}{:02}{}{}",
Expand Down Expand Up @@ -328,7 +328,7 @@ impl PaymentID {
}

/// Container for Both Bill and Payment IDs \
/// You must use this type to extract all informations about the bill
/// You must use this type to extract all information about the bill
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub struct Bill {
Expand All @@ -341,7 +341,7 @@ impl std::str::FromStr for Bill {
/// Loads Bill ID and Payment ID form barcode \
/// Barcode format is: \[Bill ID\]\[Payment ID\] \
/// Barcode Must be exactly 26 chars \
/// This also checks validity of the relation between Bill and Patyment IDs (checksum2)
/// This also checks validity of the relation between Bill and Payment IDs (checksum2)
fn from_str(barcode: &str) -> std::result::Result<Bill, BillError> {
if barcode.len() != 26 {
return Err(BillError::InvalidBarcodeLength);
Expand Down Expand Up @@ -546,7 +546,7 @@ mod tests {
// The Bill ID from typescript version seems to be wrong
// https://github.com/persian-tools/persian-tools/blob/f47fc0261aa5680cde6e03b87905a1273c91de92/test/bill.spec.ts#L36
// Bill ID 9100074409151 is invalid! checksum must be 3 so valid Bill ID is 9100074409153
// So Correct Paymenet ID sould also be changed to 12908199 in turn
// So Correct Payment ID should also be changed to 12908199 in turn
assert_eq!(
Bill::new(
BillID::from_str("9100074409153").unwrap(),
Expand Down Expand Up @@ -596,7 +596,7 @@ mod tests {
)
.is_ok());
// This test is supposed to test Payment ID so the Bill ID should be valid
// Bill id 2234322344613 from typescript vertsion
// Bill id 2234322344613 from typescript version
// https://github.com/persian-tools/persian-tools/blob/f47fc0261aa5680cde6e03b87905a1273c91de92/test/bill.spec.ts#L79
// is not valid, so it is changed to 2234322344617 to be valid so only Payment ID is checked
assert!(Bill::new(
Expand Down
2 changes: 1 addition & 1 deletion src/get_bank_name_by_card_number/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn get_bank_name_by_card_number(
let digits = digits.as_ref();

if digits.len() >= 6 {
// slicing "&digits[0..6]" is safe because we are cheking length
// slicing "&digits[0..6]" is safe because we are checking length
if let Some(x) = get_bank_code(&digits[0..6]) {
Ok(x)
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/national_id/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ pub fn verify_iranian_national_id(code: impl AsRef<str>) -> Result<(), NationalI

let code_str = &("00".to_owned() + code_str)[length + 2 - 10..];

// this unrwap is safe because if the code_str length is not in the 8..=10 range , it would return NationalIdError::Length
// this unwrap is safe because if the code_str length is not in the 8..=10 range , it would return NationalIdError::Length
if code_str[3..9].parse::<u64>().unwrap() == 0 {
return Err(NationalIdError::Invalid);
}

let mut sum = (0usize..9).fold(0, |sum, i| {
// this unrwap is safe because if the code_str length is not in the 8..=10 range , it would return NationalIdError::Length
// this unwrap is safe because if the code_str length is not in the 8..=10 range , it would return NationalIdError::Length
sum + code_str[i..i + 1].parse::<usize>().unwrap() * (10 - i)
});

Expand Down
4 changes: 2 additions & 2 deletions src/number_plate/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use thiserror::Error;
pub enum PlateNumberError {
#[error("plate numbers must be 7 or 8 digits long")]
InvalidPlateDigitLength,
#[error("invalid plate charchter length (7 for motorcucles, 8 for cars)")]
#[error("invalid plate char length (7 for motorcycles, 8 for cars)")]
InvalidPlateCharacterLength,
#[error("invalid plate charchter {0:?}")]
#[error("invalid plate char {0:?}")]
InvalidPlateCharacter(String),
#[error("invalid motorcycle province code {0:?}")]
MotorcycleProvinceNotFound(String),
Expand Down
6 changes: 3 additions & 3 deletions src/number_plate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub fn get_plate_info(plate: impl AsRef<str>) -> Result<Plate, PlateNumberError>

let (numbers, char): (String, String) = plate.chars().partition(|c| c.is_numeric());

// if its a car plate and it has no charachter
// if its a motocyle plate and it has charachters
// if its a car plate and it has no character
// if its a motorcycle plate and it has characters
if (numbers.len() == 7 && char.len() != 1) && (numbers.len() == 8 && !char.is_empty()) {
return Err(PlateNumberError::InvalidPlateCharacterLength);
}
Expand Down Expand Up @@ -152,7 +152,7 @@ mod tests {
}

#[test]
fn should_return_invalid_for_false_car_charachter() {
fn should_return_invalid_for_false_car_character() {
let plate_result = get_plate_info("1214547f");
assert!(plate_result.is_err());
}
Expand Down
10 changes: 5 additions & 5 deletions src/phone_number/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn is_phone_valid(phone_number: impl AsRef<str>) -> Result<(), PhoneNumberEr
/// and `None` is returned if no valid prefix is found.
///
/// # Warning
/// This function is desgined to only works for Iran phone number prefixes ("+98", "98", "0098", "0")
/// This function is designed to only works for Iran phone number prefixes ("+98", "98", "0098", "0")
///
///
/// # Examples
Expand Down Expand Up @@ -92,8 +92,8 @@ pub fn phone_number_normalizer(
is_phone_valid(phone_number)?;

if let Ok(prefix) = get_phone_prefix(phone_number) {
let (_, splited) = phone_number.split_at(prefix.len());
return Ok(format!("{new_prefix}{splited}"));
let (_, splitted) = phone_number.split_at(prefix.len());
return Ok(format!("{new_prefix}{splitted}"));
}

Ok(format!("{new_prefix}{phone_number}"))
Expand Down Expand Up @@ -139,7 +139,7 @@ mod tests {
}

#[test]
fn test_phone_number_normilizer() {
fn test_phone_number_normalizer() {
// normalize to 0

assert_eq!(
Expand Down Expand Up @@ -189,7 +189,7 @@ mod tests {
}

#[test]
fn test_phone_number_normilizer_invalid_phone() {
fn test_phone_number_normalizer_invalid_phone() {
assert!(phone_number_normalizer("09132222", "+98").is_err());
assert!(phone_number_normalizer("9191282819921", "0").is_err());
}
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/sheba/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use self::{
bank_info::{get_bank_info, ShebaResult},
chacksum::sheba_iso7064_mod97,
checksum::sheba_iso7064_mod97,
};

pub mod bank_info;
mod chacksum;
mod checksum;
pub mod errors;
pub use errors::ShebaValidationError;

Expand Down
28 changes: 14 additions & 14 deletions src/time_diff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl TimeDiff {
/// Converts a valid datetime to timestamp
///
/// # Warning
/// This function is desgined to only works for these date time formats :
/// This function is designed to only works for these date time formats :
///
///
/// - `%Y-%m-%d %H:%M:%S`: Sortable format
Expand Down Expand Up @@ -176,7 +176,7 @@ pub fn convert_to_timestamp(datetime: impl AsRef<str>) -> Result<i64, TimeAgoErr
/// Converts datetime to Chrono `DateTime<Local>`
///
/// # Warning
/// This function is desgined to only works for these date time formats :
/// This function is designed to only works for these date time formats :
///
/// - `%Y-%m-%d %H:%M:%S`: Sortable format
/// - `%Y/%m/%d %H:%M:%S`: Sortable format
Expand Down Expand Up @@ -231,20 +231,20 @@ pub fn get_current_timestamp() -> i64 {
}

/// datetime argument can be a integer as timestamp or a string as datetime
/// Returns a [TimeDiff] stuct based on how much time is remaining or passed based on the givin datetime\
/// The [TimeDiff] stuct has two methods , `short_form()` & `long_form()` \
/// Returns a [TimeDiff] struct based on how much time is remaining or passed based on the givin datetime\
/// The [TimeDiff] struct has two methods , `short_form()` & `long_form()` \
///
/// the `short_form()` returns a short desciption about time diffrence\
/// the `short_form()` returns a short description about time difference\
/// - 5 دقیقه قبل
/// - حدود 2 هفته بعد
///
/// the `long_form()` returns a long and exact desciption about time diffrence\
/// the `long_form()` returns a long and exact description about time difference\
/// - 6 سال و 6 ماه و 10 روز و 12 دقیقه و 37 ثانیه بعد
///
/// also there are some other methords like `short_form_fa_digits()` or `short_form_ar_digits()` that is the same as `short_form()` but with farsi or arabic digits
/// also there are some other methods like `short_form_fa_digits()` or `short_form_ar_digits()` that is the same as `short_form()` but with farsi or arabic digits
///
/// # Warning
/// This function is desgined to only works for these date time formats if you send datetime argument as datetime string :
/// This function is designed to only works for these date time formats if you send datetime argument as datetime string :
///
/// - `%Y-%m-%d %H:%M:%S`: Sortable format
/// - `%Y/%m/%d %H:%M:%S`: Sortable format
Expand Down Expand Up @@ -299,19 +299,19 @@ pub fn time_diff_now(datetime: impl Into<Timestamp>) -> Result<TimeDiff, TimeAgo
}

/// start & end arguments can be a integer as timestamp or a string as datetime
/// Returns a [TimeDiff] stuct based on how much time is remaining or passed based on the diffrence between two datetime\
/// The [TimeDiff] stuct has two main methods , `short_form()` & `long_form()` \
/// the `short_form()` returns a short desciption about time diffrence\
/// Returns a [TimeDiff] struct based on how much time is remaining or passed based on the diffrence between two datetime\
/// The [TimeDiff] struct has two main methods , `short_form()` & `long_form()` \
/// the `short_form()` returns a short description about time difference\
/// - 5 دقیقه قبل
/// - حدود 2 هفته بعد
///
/// the `long_form()` returns a long and exact desciption about time diffrence\
/// the `long_form()` returns a long and exact description about time difference\
/// - 6 سال و 6 ماه و 10 روز و 12 دقیقه و 37 ثانیه بعد
///
/// also there are some other methords like `short_form_fa_digits()` or `short_form_ar_digits()` that is the same as `short_form()` but with farsi or arabic digits
/// also there are some other methods like `short_form_fa_digits()` or `short_form_ar_digits()` that is the same as `short_form()` but with farsi or arabic digits
///
/// # Warning
/// This function is desgined to only works for these datetime formats if you send start or end as datetime string:
/// This function is designed to only works for these datetime formats if you send start or end as datetime string:
///
/// - `%Y-%m-%d %H:%M:%S`: Sortable format
/// - `%Y/%m/%d %H:%M:%S`: Sortable format
Expand Down
4 changes: 2 additions & 2 deletions src/verity_card_number/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use errors::VerifyCardNumberError;
/// Err(VerifyCardNumberError::InvalidLength)
/// );
/// ```
/// safty: sum max posible value is 144 which is smaller than u8:MAX = 2^8 = 255
/// safety: sum max possible value is 144 which is smaller than u8:MAX = 2^8 = 255
pub fn verify_card_number(digits: impl AsRef<str>) -> Result<(), VerifyCardNumberError> {
let digits = digits.as_ref();

Expand Down Expand Up @@ -68,7 +68,7 @@ mod add_ordinal_suffix_tests {
Err(VerifyCardNumberError::InvalidDigit)
);
assert_eq!(
verify_card_number("6219861034529008"), // sumcheck
verify_card_number("6219861034529008"), // checksum
Err(VerifyCardNumberError::InvalidCardNumber)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/words_to_number/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub(super) fn get_unit_number(unit: &str) -> Option<i64> {
})
}

pub(super) fn get_magnitute_number(unit: &str) -> Option<i64> {
pub(super) fn get_magnitude_number(unit: &str) -> Option<i64> {
Some(match unit {
"هزار" => 1000,
"میلیون" => 1000000,
Expand Down
16 changes: 8 additions & 8 deletions src/words_to_number/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
remove_ordinal_suffix::remove_ordinal_suffix,
};

use self::constants::{get_magnitute_number, get_unit_number, NEGATIVE_PREFIX};
use self::constants::{get_magnitude_number, get_unit_number, NEGATIVE_PREFIX};
pub use self::errors::WordsToNumberError;

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down Expand Up @@ -36,17 +36,17 @@ impl Default for Options {

fn calculate(tokens: Vec<String>) -> Result<i64, WordsToNumberError> {
let mut sum = 0;
let mut is_negetive = false;
let mut is_negative = false;

for token in tokens {
if token == NEGATIVE_PREFIX {
// check negetive token
is_negetive = true;
// check negative token
is_negative = true;
} else if let Some(value) = get_unit_number(&token) {
// if token is a valid number
sum += value;
} else if let Some(value) = get_magnitute_number(&token) {
// if token is a magnitute valid number
} else if let Some(value) = get_magnitude_number(&token) {
// if token is a magnitude valid number
if sum == 0 {
sum = value;
} else {
Expand All @@ -59,7 +59,7 @@ fn calculate(tokens: Vec<String>) -> Result<i64, WordsToNumberError> {
}
}

if is_negetive {
if is_negative {
Ok(-sum)
} else {
Ok(sum)
Expand Down Expand Up @@ -104,7 +104,7 @@ pub fn words_to_number(words: impl AsRef<str>) -> Result<i64, WordsToNumberError

/// returns a number as [String] if the givin input is a standard persian number text otherwise it would return a error
///
/// first you need to create a [Options] struct , you may also use ```Options::defualt()```
/// first you need to create a [Options] struct , you may also use ```Options::default()```
///
/// ordinal suffix is supported for example "منفی سی اُم"
///
Expand Down

0 comments on commit 661743d

Please sign in to comment.