Skip to content

Commit

Permalink
Refactor code and improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
codeperfectplus committed Jun 2, 2024
1 parent 13449dc commit 2aae414
Show file tree
Hide file tree
Showing 44 changed files with 119 additions and 114 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to Validator.py
# Contributing to Sanatio

We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:

Expand Down
2 changes: 1 addition & 1 deletion ROADMAP.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Validator.py is simple python tool to validate Document/String/Number/Date/Email/Username/Password.
Sanatio is simple python tool to validate Document/String/Number/Date/Email/Username/Password.

Currently it supports following Document validation: Few countries added in initial release. More countries will be added in future release.

Expand Down
4 changes: 2 additions & 2 deletions docs/date/date.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ The following functions are used to validate dates. They return a boolean value

.. code:: python
from sanatio import Validator
from sanatio import Sanatio
val = Validator()
val = Sanatio()
:code:`IsDate()` Returns true if the value is a valid date.
args: value
Expand Down
4 changes: 2 additions & 2 deletions docs/document/aadhar_card.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ aadhar card is 12 digit number.

.. code:: python
from sanatio import Validator
from sanatio import Sanatio
val = Validator()
val = Sanatio()
:code:`isAadharCard(value)` - check if the value is a valid aadhar card number.
>>> val.isAadharCard('9284 9436 2499')
Expand Down
4 changes: 2 additions & 2 deletions docs/document/card.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ boolean value.

.. code:: python
from sanatio import Validator
from sanatio import Sanatio
val = Validator()
val = Sanatio()
:code:`isCreditCard(value)` - Checks if the value is a valid credit card number.

Expand Down
4 changes: 2 additions & 2 deletions docs/document/licenseplate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Check if a license plate is valid or not.

.. code:: python
from sanatio import Validator
from sanatio import Sanatio
val = Validator()
val = Sanatio()
:code:`isLicensePlate()` - Check if a license plate is valid or not.
args: value
Expand Down
4 changes: 2 additions & 2 deletions docs/document/mobilenumber.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ mobile number ranges published by the ITU-T E.164. The list is updated

.. code:: python
from sanatio import Validator
from sanatio import Sanatio
val = Validator()
val = Sanatio()
:code:`isMobilePhone(value, locale)` - checks if the string is a valid mobile phone number.

Expand Down
4 changes: 2 additions & 2 deletions docs/document/passport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ This module provides a validation for passport numbers.

.. code:: python
from sanatio import Validator
from sanatio import Sanatio
val = Validator()
val = Sanatio()
:code:`isPassportNumber(value, locale):` - Return True if the string is a valid passport number.
Args: value, locale
Expand Down
4 changes: 2 additions & 2 deletions docs/document/postalcode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ The following functions are used to validate postal codes.

.. code:: python
from sanatio import Validator
from sanatio import Sanatio
val = Validator()
val = Sanatio()
:code:`isPostalCode(value, locale)` - return true if the postal code is valid for the country
args: value, locale
Expand Down
4 changes: 2 additions & 2 deletions docs/email/email.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ The following functions are used to validate email addresses.

.. code:: python
from sanatio import Validator
from sanatio import Sanatio
val = Validator()
val = Sanatio()
:code:`isEmail()` - Returns true if the email address is valid, false otherwise.
args: value, checkDNS
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. rst-class:: hide-header

Welcome to Validator.py's documentation!
Welcome to Sanatio's documentation!
=====================================


Expand Down
4 changes: 2 additions & 2 deletions docs/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Usage-Examples

.. code:: python
from sanatio import Validator
val = Validator()
from sanatio import Sanatio
val = Sanatio()


# Check if the string is equal to the given value
Expand Down
4 changes: 2 additions & 2 deletions docs/number/number_validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ The following functions are used to validate numbers.

.. code:: python
from sanatio import Validator
from sanatio import Sanatio
val = Validator()
val = Sanatio()
:code:`isDecimal(value)`
Returns true if the value is a decimal number.
Expand Down
4 changes: 2 additions & 2 deletions docs/other/other.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ The following functions are used to

.. code:: python
from sanatio import Validator
from sanatio import Sanatio
val = Validator()
val = Sanatio()
:code:`isEan13` - Check if the value is a valid EAN13 number
Returns true if the value is a valid EAN13 number
Expand Down
4 changes: 2 additions & 2 deletions docs/password/password.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ The password validation is done by the function isStrongPassword().

.. code:: python
from sanatio import Validator
from sanatio import Sanatio
val = Validator()
val = Sanatio()
:code:`isStrongPassword(value)`
Returns true if the password is strong enough, false otherwise.
Expand Down
1 change: 1 addition & 0 deletions docs/research/checksum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Document Algorithm
=========== =========
Credit Card Luhn
Aadhar card Verhoeff
Ean13 Ean13 checksum
=========== =========

References
Expand Down
4 changes: 2 additions & 2 deletions docs/string/string_validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ The following functions are used to validate strings.

.. code:: python
from sanatio import Validator
from sanatio import Sanatio
val = Validator()
val = Sanatio()
:code:`equals(value1, value2, ignoreCase)`
Returns true if the two strings are equal.
Expand Down
4 changes: 2 additions & 2 deletions docs/username/username.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ The following validation rules are applied to the username:

.. code:: python
from sanatio import Validator
from sanatio import Sanatio
val = Validator()
val = Sanatio()
:code:`isDiscordUsername(value)` - Checks if the username is a valid Discord username.
>>> val.isDiscordUsername('test#1234')
Expand Down
2 changes: 1 addition & 1 deletion sanatio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from sanatio.main import Validator
from sanatio.main import Sanatio

__all__ = ['Validator']
10 changes: 7 additions & 3 deletions sanatio/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
from sanatio.password_validator import PasswordValidator
from sanatio.string_validator import StringValidator
from sanatio.username_validator import UsernameValidator
from warnings import warn


class Validator(StringValidator, DocumentValidator, UsernameValidator, NumberValidator,
DateValidator, EmailValidator, PasswordValidator, OtherValidator, ArrayValidator):
class Sanatio(ArrayValidator, DateValidator, DocumentValidator, EmailValidator, NumberValidator, OtherValidator, PasswordValidator, StringValidator, UsernameValidator):
""" Sanatio class for validating the data """
def __init__(self):
super().__init__()
class Validator(Sanatio):
""" Validator class for validating the data """
def __init__(self):
super().__init__()
warn("Validator class is deprecated, use Sanatio class instead", DeprecationWarning)
66 changes: 33 additions & 33 deletions sanatio/string_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,39 +50,6 @@ def contains(self, value: str, substring: str, ignoreCase: bool=False) -> bool:

return False

def trim(self, value):
""" trim string """
if self.isvalidString(value):
return value.strip()

def ltrim(self, value):
if self.isvalidString(value):
return value.lstrip()

def rtrim(self, value):
if self.isvalidString(value):
return value.rstrip()

def toUpperCase(self, value):
""" convert string to upper case """
if self.isvalidString(value):
return value.upper()

def toLowerCase(self, value):
""" convert string to lower case """
if self.isvalidString(value):
return value.lower()

def removeSpaces(self, value):
""" remove spaces from string """
if self.isvalidString(value):
return value.replace(" ", "")

def removeSymbols(self, value):
""" remove symbols from string """
if self.isvalidString(value):
return re.sub(r'[^\w\s]', '', value)

def levenshtein_distance(self, value1, value2):
""" calculate distance between two strings """
distance = levenshtein_distance(value1, value2)
Expand Down Expand Up @@ -118,6 +85,39 @@ def is_equals(self, value1: str, value2: str, ignoreCase: bool=False)-> bool:
return True

return False

def trim(self, value):
""" trim string """
if self.isvalidString(value):
return value.strip()

def ltrim(self, value):
if self.isvalidString(value):
return value.lstrip()

def rtrim(self, value):
if self.isvalidString(value):
return value.rstrip()

def toUpperCase(self, value):
""" convert string to upper case """
if self.isvalidString(value):
return value.upper()

def toLowerCase(self, value):
""" convert string to lower case """
if self.isvalidString(value):
return value.lower()

def removeSpaces(self, value):
""" remove spaces from string """
if self.isvalidString(value):
return value.replace(" ", "")

def removeSymbols(self, value):
""" remove symbols from string """
if self.isvalidString(value):
return re.sub(r'[^\w\s]', '', value)

def removeNonASCII(self, value):
""" remove non ASCII characters from string """
Expand Down
4 changes: 2 additions & 2 deletions tests/array_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
import unittest
sys.path.append('.')
from sanatio import Validator
validator = Validator()
from sanatio import Sanatio
validator = Sanatio()


class ArrayTest(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/date_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import datetime
import unittest
sys.path.append('.')
from sanatio import Validator
from sanatio import Sanatio

validator = Validator()
validator = Sanatio()


class DateTest(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/document/aadhar_card_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
import unittest
sys.path.append('.')
from sanatio import Validator
from sanatio import Sanatio

validator = Validator()
validator = Sanatio()


class AadharCardTest(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/document/credit_card_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
import unittest
sys.path.append('.')
from sanatio import Validator
from sanatio import Sanatio

validator = Validator()
validator = Sanatio()


class CreditCardTest(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/document/driving_license_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
import unittest
sys.path.append('.')
from sanatio import Validator
from sanatio import Sanatio

validator = Validator()
validator = Sanatio()


class DrivingLicenseTest(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/document/license_plate_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
import unittest
sys.path.append('.')
from sanatio import Validator
from sanatio import Sanatio

validator = Validator()
validator = Sanatio()


class LicensePlateTest(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/document/mobilephone_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
import unittest
sys.path.append('.')
from sanatio import Validator
from sanatio import Sanatio

validator = Validator()
validator = Sanatio()


class MobilePhoneTest(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/document/passport_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
import unittest
sys.path.append('.')
from sanatio import Validator
from sanatio import Sanatio

validator = Validator()
validator = Sanatio()


class PassportTest(unittest.TestCase):
Expand Down
Loading

0 comments on commit 2aae414

Please sign in to comment.