diff --git a/src/bill/mod.rs b/src/bill/mod.rs index 588e656..e25522a 100644 --- a/src/bill/mod.rs +++ b/src/bill/mod.rs @@ -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"); @@ -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, @@ -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))] @@ -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}", @@ -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}{}{}", @@ -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 { @@ -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 { if barcode.len() != 26 { return Err(BillError::InvalidBarcodeLength); @@ -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(), @@ -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( diff --git a/src/get_bank_name_by_card_number/mod.rs b/src/get_bank_name_by_card_number/mod.rs index c7a898b..59015e2 100644 --- a/src/get_bank_name_by_card_number/mod.rs +++ b/src/get_bank_name_by_card_number/mod.rs @@ -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 { diff --git a/src/national_id/mod.rs b/src/national_id/mod.rs index 107ef68..ff451cc 100644 --- a/src/national_id/mod.rs +++ b/src/national_id/mod.rs @@ -114,13 +114,13 @@ pub fn verify_iranian_national_id(code: impl AsRef) -> 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::().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::().unwrap() * (10 - i) }); diff --git a/src/number_plate/errors.rs b/src/number_plate/errors.rs index 621058d..97b0625 100644 --- a/src/number_plate/errors.rs +++ b/src/number_plate/errors.rs @@ -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), diff --git a/src/number_plate/mod.rs b/src/number_plate/mod.rs index 0487b27..9ce55d4 100644 --- a/src/number_plate/mod.rs +++ b/src/number_plate/mod.rs @@ -13,8 +13,8 @@ pub fn get_plate_info(plate: impl AsRef) -> Result 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); } @@ -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()); } diff --git a/src/phone_number/mod.rs b/src/phone_number/mod.rs index 8859067..45e5853 100644 --- a/src/phone_number/mod.rs +++ b/src/phone_number/mod.rs @@ -44,7 +44,7 @@ pub fn is_phone_valid(phone_number: impl AsRef) -> 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 @@ -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}")) @@ -139,7 +139,7 @@ mod tests { } #[test] - fn test_phone_number_normilizer() { + fn test_phone_number_normalizer() { // normalize to 0 assert_eq!( @@ -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()); } diff --git a/src/sheba/chacksum.rs b/src/sheba/checksum.rs similarity index 100% rename from src/sheba/chacksum.rs rename to src/sheba/checksum.rs diff --git a/src/sheba/mod.rs b/src/sheba/mod.rs index e3f1f4a..eb89086 100644 --- a/src/sheba/mod.rs +++ b/src/sheba/mod.rs @@ -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; diff --git a/src/time_diff/mod.rs b/src/time_diff/mod.rs index 1ca0471..b1fc476 100644 --- a/src/time_diff/mod.rs +++ b/src/time_diff/mod.rs @@ -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 @@ -176,7 +176,7 @@ pub fn convert_to_timestamp(datetime: impl AsRef) -> Result` /// /// # 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 @@ -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 @@ -299,19 +299,19 @@ pub fn time_diff_now(datetime: impl Into) -> Result) -> Result<(), VerifyCardNumberError> { let digits = digits.as_ref(); @@ -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) ); } diff --git a/src/words_to_number/constants.rs b/src/words_to_number/constants.rs index d89c81f..5ae267f 100644 --- a/src/words_to_number/constants.rs +++ b/src/words_to_number/constants.rs @@ -45,7 +45,7 @@ pub(super) fn get_unit_number(unit: &str) -> Option { }) } -pub(super) fn get_magnitute_number(unit: &str) -> Option { +pub(super) fn get_magnitude_number(unit: &str) -> Option { Some(match unit { "هزار" => 1000, "میلیون" => 1000000, diff --git a/src/words_to_number/mod.rs b/src/words_to_number/mod.rs index 8b7e30a..bf977d7 100644 --- a/src/words_to_number/mod.rs +++ b/src/words_to_number/mod.rs @@ -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))] @@ -36,17 +36,17 @@ impl Default for Options { fn calculate(tokens: Vec) -> Result { 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 { @@ -59,7 +59,7 @@ fn calculate(tokens: Vec) -> Result { } } - if is_negetive { + if is_negative { Ok(-sum) } else { Ok(sum) @@ -104,7 +104,7 @@ pub fn words_to_number(words: impl AsRef) -> Result