checkdigit
Advanced tools
| # /usr/bin/env python | ||
| # This file is part of checkdigit. | ||
| # checkdigit is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU General Public License as published by | ||
| # the Free Software Foundation, either version 3 of the License, or | ||
| # (at your option) any later version. | ||
| # checkdigit is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with checkdigit. If not, see <http://www.gnu.org/licenses/>. | ||
| """Data cleansing. | ||
| This module contains functions that help to format data so that it can be interpreted easier. | ||
| """ | ||
| def cleanse(data: str) -> str: | ||
| """Removes Hyphens and Spaces so that data can be parsed.""" | ||
| return data.replace("-", "").replace(" ", "") | ||
| def convert(digit: int, barcode: str = "isbn") -> str: | ||
| """Converts digits to strings and replaces 10.""" | ||
| if digit == 10: | ||
| return "X" if barcode == "isbn" else "0" | ||
| return "0" if digit == 11 else str(digit) |
| # Marker file for PEP 561. checkdigit uses inline types. |
@@ -15,1 +15,11 @@ # /usr/bin/env python | ||
| # along with checkdigit. If not, see <http://www.gnu.org/licenses/>. | ||
| """A check digit library for data validation. | ||
| This Python library contains various functions relating to Luhn, ISBN, UPC and many other codes. | ||
| It is able to validate blocks of data, as well as calulate missing digits and check digits. | ||
| For more information, please look at the GitHub page for this library: | ||
| https://github.com/harens/checkdigit | ||
| """ |
+22
-9
@@ -16,5 +16,15 @@ # /usr/bin/env python | ||
| from checkdigit.data import cleanse, convert | ||
| """ISBN Validation Functions. | ||
| ISBN codes are product identifiers used predominantly for books. | ||
| For more information, please look at the wiki page for this module: | ||
| https://github.com/harens/checkdigit/wiki/đ-ISBN | ||
| Note that the ISBN-13 functions can also be used for EAN-13 and Bookland codes | ||
| """ | ||
| from checkdigit._data import cleanse, convert | ||
| # WARNING: Data beginning with 0 must be as a string due to PEP 3127 | ||
@@ -24,3 +34,3 @@ | ||
| def calculate10(data: str) -> str: | ||
| """Calculates ISBN-10 Check Digit | ||
| """Calculates ISBN-10 Check Digit. | ||
@@ -44,3 +54,3 @@ Args: | ||
| def validate10(data: str) -> bool: | ||
| """Validates ISBN-10 | ||
| """Validates ISBN-10. | ||
@@ -51,3 +61,4 @@ Args: | ||
| Returns: | ||
| bool: A boolean representing whether the check digit validates the data or not | ||
| bool: A boolean representing whether the | ||
| check digit validates the data or not | ||
@@ -60,3 +71,3 @@ """ | ||
| def calculate13(data: str, barcode: str = "isbn") -> str: | ||
| """Calculates ISBN-13 Check Digit | ||
| """Calculates ISBN-13 Check Digit. | ||
@@ -86,3 +97,3 @@ Args: | ||
| def validate13(data: str) -> bool: | ||
| """Validates ISBN-13 | ||
| """Validates ISBN-13. | ||
@@ -101,6 +112,7 @@ Args: | ||
| def missing(data: str) -> str: | ||
| """Calculates a missing digit in an ISBN Code | ||
| """Calculates a missing digit in an ISBN Code. | ||
| Args: | ||
| data: A string of characters representing a full ISBN code with a question mark representing a missing character | ||
| data: A string of characters representing a full ISBN code | ||
| with a question mark representing a missing character | ||
@@ -114,3 +126,4 @@ Returns: | ||
| option = convert(poss_digit) | ||
| # Depending on the size of the data, the relevant validating function tests it with the generated number | ||
| # Depending on the size of the data, the relevant validating function | ||
| # tests it with the generated number | ||
| # If this fails, the next number is tried | ||
@@ -117,0 +130,0 @@ if (len(data) == 10 and validate10(data.replace("?", option))) or ( |
+14
-5
@@ -17,5 +17,13 @@ # /usr/bin/env python | ||
| from checkdigit.data import cleanse, convert | ||
| """Luhn Validation Functions. | ||
| The luhn algorithm has a variety of applications, including in credit cards and IMEI numbers. | ||
| For more information, please look at the wiki page for this module: | ||
| https://github.com/harens/checkdigit/wiki/đł-Luhn | ||
| """ | ||
| from checkdigit._data import cleanse, convert | ||
| # WARNING: Data beginning with 0 must be as a string due to PEP 3127 | ||
@@ -25,3 +33,3 @@ | ||
| def calculate(data: str) -> str: | ||
| """Calculates the luhn check digit | ||
| """Calculates the luhn check digit. | ||
@@ -54,3 +62,3 @@ Args: | ||
| def validate(data: str) -> bool: | ||
| """Validates a luhn check digit | ||
| """Validates a luhn check digit. | ||
@@ -71,6 +79,7 @@ Args: | ||
| def missing(data: str) -> str: | ||
| """Calculates a missing digit in a luhn code | ||
| """Calculates a missing digit in a luhn code. | ||
| Args: | ||
| data: A string of characters representing a full luhn code with a question mark for a missing character | ||
| data: A string of characters representing a full luhn code | ||
| with a question mark for a missing character | ||
@@ -77,0 +86,0 @@ Returns: |
+10
-2
@@ -16,5 +16,13 @@ # /usr/bin/env python | ||
| from checkdigit.data import cleanse | ||
| """Parity Validation Functions. | ||
| A parity bit is added to the end of a block of binary as a form of data validation. | ||
| For more information, please look at the wiki page for this module: | ||
| https://github.com/harens/checkdigit/wiki/1%EF%B8%8FâŁ-Parity-Bits | ||
| """ | ||
| from checkdigit._data import cleanse | ||
| # WARNING: Data beginning with 0 must be as a string due to PEP 3127 | ||
@@ -24,3 +32,3 @@ | ||
| def calculate(data: str, even: bool = True) -> str: | ||
| """Adds a parity bit onto the end of a block of data | ||
| """Adds a parity bit onto the end of a block of data. | ||
@@ -27,0 +35,0 @@ Args: |
+12
-3
@@ -16,5 +16,14 @@ # /usr/bin/env python | ||
| """Parity Validation Functions. | ||
| UPC-A codes are the main variant of Universal Product Codes. | ||
| They contain 12 digits and are mainly used for product identification. | ||
| For more information, please look at the wiki page for this module: | ||
| https://github.com/harens/checkdigit/wiki/đŚ-UPC-A | ||
| """ | ||
| from checkdigit import isbn | ||
| # WARNING: Data beginning with 0 must be as a string due to PEP 3127 | ||
@@ -30,3 +39,3 @@ | ||
| def calculate(data: str) -> str: | ||
| """Calculates UPC Check Digits | ||
| """Calculates UPC Check Digits. | ||
@@ -43,3 +52,3 @@ Args: | ||
| def validate(data: str) -> bool: | ||
| """Determines if the calculated check digit of the data is the last digit given | ||
| """Determines if the calculated check digit of the data is the last digit given. | ||
@@ -46,0 +55,0 @@ Args: |
+46
-11
| Metadata-Version: 2.1 | ||
| Name: checkdigit | ||
| Version: 0.1 | ||
| Version: 0.1.1 | ||
| Summary: A check digit library for data validation | ||
@@ -13,3 +13,6 @@ Home-page: https://github.com/harens/checkdigit | ||
| Requires-Python: >=3.6,<4.0 | ||
| Classifier: Intended Audience :: Developers | ||
| Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+) | ||
| Classifier: Natural Language :: English | ||
| Classifier: Operating System :: OS Independent | ||
| Classifier: Programming Language :: Python :: 3 | ||
@@ -20,2 +23,3 @@ Classifier: Programming Language :: Python :: 3.6 | ||
| Classifier: Programming Language :: Python :: 3.9 | ||
| Classifier: Typing :: Typed | ||
| Project-URL: Bug Tracker, https://github.com/harens/checkdigit/issues | ||
@@ -28,25 +32,56 @@ Project-URL: Documentation, https://github.com/harens/checkdigit/wiki | ||
| A check digit library for data validation | ||
| A check digit library for data validation. | ||
| | Test Status | [](https://github.com/harens/checkdigit/actions) [](https://codecov.io/gh/harens/checkdigit) | | ||
| | Test Status | [](https://github.com/harens/checkdigit/actions) [](https://codecov.io/gh/harens/checkdigit) | | ||
| |:--|:--| | ||
| | __Version Info__ | [](https://pypi.org/project/checkdigit/) [](https://github.com/harens/checkdigit/releases) [](https://pypi.org/project/checkdigit/) | | ||
| | __Code Analysis__ |[](https://codeclimate.com/github/harens/checkdigit) [](https://www.codefactor.io/repository/github/harens/checkdigit)| | ||
| | __Code Analysis__ |[](https://codeclimate.com/github/harens/checkdigit) [](https://www.codefactor.io/repository/github/harens/checkdigit) [](https://lgtm.com/projects/g/harens/checkdigit/)| | ||
| ## đ¨ Installation | ||
| ```shell | ||
| pip install checkdigit | ||
| ``` | ||
| Or download the project [here](https://github.com/harens/checkdigit/archive/master.zip) | ||
| Or download the project [here](https://github.com/harens/checkdigit/archive/master.zip). | ||
| ## ⨠Features | ||
| * Contains various functions relating to __Luhn, ISBN and UPC codes__ | ||
| * Extensive __in-code comments and docstrings__ to explain how the functions work | ||
| * Written in __pure Python__ with __no dependencies__ required to run the program | ||
| * Contains various functions relating to __Luhn, ISBN, UPC and many other codes__. | ||
| * Extensive __in-code comments and docstrings__ to explain how the functions work. | ||
| * Written in __pure Python__ with __no dependencies__ required to run the program. | ||
| Check out the [documentation](https://github.com/harens/checkdigit/wiki) for more details on how to use the library | ||
| Check out the [documentation](https://github.com/harens/checkdigit/wiki) for more details on how to use the library. | ||
| ## License | ||
| This project is licensed under the [GNU General Public License v3.0](https://github.com/harens/checkdigit/blob/master/LICENSE) | ||
| ## đď¸ Contributing | ||
| Any change, big or small, that you think can help improve this project is more than welcome đ. | ||
| As well as this, feel free to open an issue with any new suggestions or bug reports. Every contribution is valued. | ||
| For smaller tasks (that are still really appreciated đ), be sure to check the [good first issue](https://github.com/harens/checkdigit/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) tag. | ||
| ## đť Setup | ||
| Clone the project and install the dev dependencies: | ||
| ```shell | ||
| git clone https://github.com/harens/checkdigit | ||
| cd checkdigit | ||
| poetry install | ||
| ``` | ||
| If you want to send a PR, please run the following: | ||
| ```bash | ||
| bash ./scripts/format.sh # Format files | ||
| bash ./scripts/tests.sh # Run tests | ||
| # NB shellcheck is not installed by poetry | ||
| shellcheck scripts/*.sh | ||
| ``` | ||
| ## đ License | ||
| This project is licensed under [GPL-3.0-or-later](https://github.com/harens/checkdigit/blob/master/LICENSE). | ||
+12
-2
| [tool.poetry] | ||
| name = "checkdigit" | ||
| version = "0.1" | ||
| version = "0.1.1" | ||
| description = "A check digit library for data validation" | ||
@@ -9,3 +9,10 @@ authors = ["harens <harensdeveloper@gmail.com>"] | ||
| license = "GPL-3.0-or-later" | ||
| include = ["checkdigit/py.typed"] | ||
| keywords = ["Check Digits", "Validation", "ISBN"] | ||
| classifiers = [ | ||
| "Natural Language :: English", | ||
| "Operating System :: OS Independent", | ||
| "Intended Audience :: Developers", | ||
| 'Typing :: Typed' | ||
| ] | ||
@@ -23,6 +30,9 @@ homepage = "https://github.com/harens/checkdigit" | ||
| [tool.poetry.dev-dependencies] | ||
| error404 = "^1.1.7" | ||
| error404 = "^1.1.8a0" | ||
| pylint = "^2.6.0" | ||
| mypy = "^0.790" | ||
| black = "^20.8b1" | ||
| isort = "^5.6.4" | ||
| pydocstyle = "^5.1.1" | ||
| coverage = "^5.3" | ||
@@ -29,0 +39,0 @@ [tool.coverage.run] |
+41
-10
| # checkdigit | ||
| A check digit library for data validation | ||
| A check digit library for data validation. | ||
| | Test Status | [](https://github.com/harens/checkdigit/actions) [](https://codecov.io/gh/harens/checkdigit) | | ||
| | Test Status | [](https://github.com/harens/checkdigit/actions) [](https://codecov.io/gh/harens/checkdigit) | | ||
| |:--|:--| | ||
| | __Version Info__ | [](https://pypi.org/project/checkdigit/) [](https://github.com/harens/checkdigit/releases) [](https://pypi.org/project/checkdigit/) | | ||
| | __Code Analysis__ |[](https://codeclimate.com/github/harens/checkdigit) [](https://www.codefactor.io/repository/github/harens/checkdigit)| | ||
| | __Code Analysis__ |[](https://codeclimate.com/github/harens/checkdigit) [](https://www.codefactor.io/repository/github/harens/checkdigit) [](https://lgtm.com/projects/g/harens/checkdigit/)| | ||
| ## đ¨ Installation | ||
| ```shell | ||
| pip install checkdigit | ||
| ``` | ||
| Or download the project [here](https://github.com/harens/checkdigit/archive/master.zip) | ||
| Or download the project [here](https://github.com/harens/checkdigit/archive/master.zip). | ||
| ## ⨠Features | ||
| * Contains various functions relating to __Luhn, ISBN and UPC codes__ | ||
| * Extensive __in-code comments and docstrings__ to explain how the functions work | ||
| * Written in __pure Python__ with __no dependencies__ required to run the program | ||
| * Contains various functions relating to __Luhn, ISBN, UPC and many other codes__. | ||
| * Extensive __in-code comments and docstrings__ to explain how the functions work. | ||
| * Written in __pure Python__ with __no dependencies__ required to run the program. | ||
| Check out the [documentation](https://github.com/harens/checkdigit/wiki) for more details on how to use the library | ||
| Check out the [documentation](https://github.com/harens/checkdigit/wiki) for more details on how to use the library. | ||
| ## License | ||
| This project is licensed under the [GNU General Public License v3.0](https://github.com/harens/checkdigit/blob/master/LICENSE) | ||
| ## đď¸ Contributing | ||
| Any change, big or small, that you think can help improve this project is more than welcome đ. | ||
| As well as this, feel free to open an issue with any new suggestions or bug reports. Every contribution is valued. | ||
| For smaller tasks (that are still really appreciated đ), be sure to check the [good first issue](https://github.com/harens/checkdigit/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) tag. | ||
| ## đť Setup | ||
| Clone the project and install the dev dependencies: | ||
| ```shell | ||
| git clone https://github.com/harens/checkdigit | ||
| cd checkdigit | ||
| poetry install | ||
| ``` | ||
| If you want to send a PR, please run the following: | ||
| ```bash | ||
| bash ./scripts/format.sh # Format files | ||
| bash ./scripts/tests.sh # Run tests | ||
| # NB shellcheck is not installed by poetry | ||
| shellcheck scripts/*.sh | ||
| ``` | ||
| ## đ License | ||
| This project is licensed under [GPL-3.0-or-later](https://github.com/harens/checkdigit/blob/master/LICENSE). |
+2
-2
@@ -12,5 +12,5 @@ # -*- coding: utf-8 -*- | ||
| 'name': 'checkdigit', | ||
| 'version': '0.1', | ||
| 'version': '0.1.1', | ||
| 'description': 'A check digit library for data validation', | ||
| 'long_description': '# checkdigit\n\nA check digit library for data validation\n \n| Test Status | [](https://github.com/harens/checkdigit/actions) [](https://codecov.io/gh/harens/checkdigit) |\n|:--|:--|\n| __Version Info__ | [](https://pypi.org/project/checkdigit/) [](https://github.com/harens/checkdigit/releases) [](https://pypi.org/project/checkdigit/) |\n| __Code Analysis__ |[](https://codeclimate.com/github/harens/checkdigit) [](https://www.codefactor.io/repository/github/harens/checkdigit)|\n\n## đ¨ Installation\n```shell\npip install checkdigit\n```\nOr download the project [here](https://github.com/harens/checkdigit/archive/master.zip)\n\n## ⨠Features\n\n* Contains various functions relating to __Luhn, ISBN and UPC codes__\n* Extensive __in-code comments and docstrings__ to explain how the functions work\n* Written in __pure Python__ with __no dependencies__ required to run the program\n\nCheck out the [documentation](https://github.com/harens/checkdigit/wiki) for more details on how to use the library\n\n## License\nThis project is licensed under the [GNU General Public License v3.0](https://github.com/harens/checkdigit/blob/master/LICENSE)\n', | ||
| 'long_description': '# checkdigit\n\nA check digit library for data validation.\n \n| Test Status | [](https://github.com/harens/checkdigit/actions) [](https://codecov.io/gh/harens/checkdigit) |\n|:--|:--|\n| __Version Info__ | [](https://pypi.org/project/checkdigit/) [](https://github.com/harens/checkdigit/releases) [](https://pypi.org/project/checkdigit/) |\n| __Code Analysis__ |[](https://codeclimate.com/github/harens/checkdigit) [](https://www.codefactor.io/repository/github/harens/checkdigit) [](https://lgtm.com/projects/g/harens/checkdigit/)|\n\n## đ¨ Installation\n\n```shell\npip install checkdigit\n```\n\nOr download the project [here](https://github.com/harens/checkdigit/archive/master.zip).\n\n## ⨠Features\n\n* Contains various functions relating to __Luhn, ISBN, UPC and many other codes__.\n* Extensive __in-code comments and docstrings__ to explain how the functions work.\n* Written in __pure Python__ with __no dependencies__ required to run the program.\n\nCheck out the [documentation](https://github.com/harens/checkdigit/wiki) for more details on how to use the library.\n\n## đď¸ Contributing\n\nAny change, big or small, that you think can help improve this project is more than welcome đ.\n\nAs well as this, feel free to open an issue with any new suggestions or bug reports. Every contribution is valued.\n\nFor smaller tasks (that are still really appreciated đ), be sure to check the [good first issue](https://github.com/harens/checkdigit/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) tag.\n\n## đť Setup\n\nClone the project and install the dev dependencies:\n\n```shell\ngit clone https://github.com/harens/checkdigit\ncd checkdigit\npoetry install\n```\n\nIf you want to send a PR, please run the following:\n\n```bash\nbash ./scripts/format.sh # Format files\nbash ./scripts/tests.sh # Run tests\n\n# NB shellcheck is not installed by poetry\nshellcheck scripts/*.sh\n```\n\n## đ License\n\nThis project is licensed under [GPL-3.0-or-later](https://github.com/harens/checkdigit/blob/master/LICENSE).\n', | ||
| 'author': 'harens', | ||
@@ -17,0 +17,0 @@ 'author_email': 'harensdeveloper@gmail.com', |
| # /usr/bin/env python | ||
| # This file is part of checkdigit. | ||
| # checkdigit is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU General Public License as published by | ||
| # the Free Software Foundation, either version 3 of the License, or | ||
| # (at your option) any later version. | ||
| # checkdigit is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with checkdigit. If not, see <http://www.gnu.org/licenses/>. | ||
| def cleanse(data: str) -> str: | ||
| """Removes Hyphens and Spaces so that data can be parsed""" | ||
| return data.replace("-", "").replace(" ", "") | ||
| def convert(digit: int, barcode: str = "isbn") -> str: | ||
| """Converts digits to strings and replaces 10""" | ||
| if digit == 10: | ||
| return "X" if barcode == "isbn" else "0" | ||
| return "0" if digit == 11 else str(digit) |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
59178
9.38%12
9.09%303
14.34%