aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/built-in/index.rst18
-rw-r--r--docs/built-in/zip_locales.rst717
-rw-r--r--src/edify/library/__init__.py1
-rw-r--r--src/edify/library/guid.py14
-rw-r--r--tests/test_guid.py11
5 files changed, 44 insertions, 717 deletions
diff --git a/docs/built-in/index.rst b/docs/built-in/index.rst
index e28e515..91b5d4e 100644
--- a/docs/built-in/index.rst
+++ b/docs/built-in/index.rst
@@ -944,3 +944,21 @@ By default, the ``zip`` function matches ZIP codes for "US". Here's an example o
zip('123456', locale='IN') # returns True
If you supply an Invalid or empty value in the ``locale`` argument, the function will raise a ``ValueError`` exception. Similarly, if you supply another data type in the ``locale`` argument, the function will raise a ``TypeError`` exception.
+
+
+guid(guid: str)
+---------------
+
+The ``guid`` function validates a GUID (Globally Unique Identifier) string. The function returns ``True`` if the string is a valid GUID, and ``False`` otherwise.
+
+Here's an example of how to use the ``guid`` function:
+
+.. code-block:: python
+ from edify.library import guid
+
+ guid('6ba7b810-9dad-11d1-80b4-00c04fd430c8') # returns True
+ guid('{51d52cf1-83c9-4f02-b117-703ecb728b74}') # returns True
+ guid('{51d52cf1-83c9-4f02-b117-703ecb728-b74}') # returns False
+
+
+
diff --git a/docs/built-in/zip_locales.rst b/docs/built-in/zip_locales.rst
deleted file mode 100644
index 92670b1..0000000
--- a/docs/built-in/zip_locales.rst
+++ /dev/null
@@ -1,717 +0,0 @@
-.. list-table::
- :header-rows: 1
-
- * - Country
- - Locale
-
- * - Afghanistan
- - AF
-
- * - Albania
- - AL
-
- * - Algeria
- - DZ
-
- * - American Samoa
- - AS
-
- * - Andorra
- - AD
-
- * - Angola
- - AO
-
- * - Anguilla
- - AI
-
- * - Antigua and Barbuda
- - AG
-
- * - Argentina
- - AR
-
- * - Armenia
- - AM
-
- * - Aruba
- - AW
-
- * - Australia
- - AU
-
- * - Austria
- - AT
-
- * - Azerbaijan
- - AZ
-
- * - Bahamas
- - BS
-
- * - Bahrain
- - BH
-
- * - Bangladesh
- - BD
-
- * - Barbados
- - BB
-
- * - Belarus
- - BY
-
- * - Belgium
- - BE
-
- * - Belize
- - BZ
-
- * - Benin
- - BJ
-
- * - Bermuda
- - BM
-
- * - Bhutan
- - BT
-
- * - Bolivia
- - BO
-
- * - Bonaire
- - BQ
-
- * - Bosnia and Herzegovina
- - BA
-
- * - Botswana
- - BW
-
- * - Brazil
- - BR
-
- * - Brunei
- - BN
-
- * - Bulgaria
- - BG
-
- * - Burkina Faso
- - BF
-
- * - Burundi
- - BI
-
- * - Cambodia
- - KH
-
- * - Cameroon
- - CM
-
- * - Canada
- - CA
-
- * - Canary Islands
- - CI
-
- * - Cape Verde
- - CV
-
- * - Cayman Islands
- - KY
-
- * - Central African Republic
- - CF
-
- * - Chad
- - TD
-
- * - Channel Islands
- - CI
-
- * - Chile
- - CL
-
- * - China, People's Republic
- - CN
-
- * - Colombia
- - CO
-
- * - Comoros
- - KM
-
- * - Congo
- - CG
-
- * - Congo, The Democratic Republic of
- - CD
-
- * - Cook Islands
- - CK
-
- * - Costa Rica
- - CR
-
- * - Côte d'Ivoire
- - CI
-
- * - Croatia
- - HR
-
- * - Cuba
- - CU
-
- * - Curacao
- - CW
-
- * - Cyprus
- - CY
-
- * - Czech Republic
- - CZ
-
- * - Denmark
- - DK
-
- * - Djibouti
- - DJ
-
- * - Dominica
- - DM
-
- * - Dominican Republic
- - DO
-
- * - East Timor
- - TL
-
- * - Ecuador
- - EC
-
- * - Egypt
- - EG
-
- * - El Salvador
- - SV
-
- * - Eritrea
- - ER
-
- * - Estonia
- - EE
-
- * - Ethiopia
- - ET
-
- * - Falkland Islands
- - FK
-
- * - Faroe Islands
- - FO
-
- * - Fiji
- - FJ
-
- * - Finland
- - FI
-
- * - France
- - FR
-
- * - French Polynesia
- - PF
-
- * - Gabon
- - GA
-
- * - Gambia
- - GM
-
- * - Georgia
- - GE
-
- * - Germany
- - DE
-
- * - Ghana
- - GH
-
- * - Gibraltar
- - GI
-
- * - Greece
- - GR
-
- * - Greenland
- - GL
-
- * - Grenada
- - GD
-
- * - Guadeloupe
- - GP
-
- * - Guam
- - GU
-
- * - Guatemala
- - GT
-
- * - Guernsey
- - GG
-
- * - Guinea-Bissau
- - GW
-
- * - Guinea-Equatorial
- - GQ
-
- * - Guinea Republic
- - GN
-
- * - Guyana (British)
- - GY
-
- * - Guyana (French)
- - GF
-
- * - Haiti
- - HT
-
- * - Honduras
- - HN
-
- * - Hong Kong
- - HK
-
- * - Hungary
- - HU
-
- * - Iceland
- - IS
-
- * - India
- - IN
-
- * - Indonesia
- - ID
-
- * - Iran
- - IR
-
- * - Iraq
- - IQ
-
- * - Ireland, Republic of
- - IE
-
- * - Islas Malvinas
- - FK
-
- * - Israel
- - IL
-
- * - Italy
- - IT
-
- * - Ivory Coast
- - CI
-
- * - Jamaica
- - JM
-
- * - Japan
- - JP
-
- * - Jersey
- - JE
-
- * - Jordan
- - JO
-
- * - Kazakhstan
- - KZ
-
- * - Kenya
- - KE
-
- * - Kiribati
- - KI
-
- * - Korea, Republic of
- - KR
-
- * - Korea, The D.P.R of
- - KP
-
- * - Kosovo
- - XK
-
- * - Kuwait
- - KW
-
- * - Kyrgyzstan
- - KG
-
- * - Laos
- - LA
-
- * - Latvia
- - LV
-
- * - Lebanon
- - LB
-
- * - Lesotho
- - LS
-
- * - Liberia
- - LR
-
- * - Libya
- - LY
-
- * - Liechtenstein
- - LI
-
- * - Lithuania
- - LT
-
- * - Luxembourg
- - LU
-
- * - Macau
- - MO
-
- * - Macedonia, Republic of
- - MK
-
- * - Madagascar
- - MG
-
- * - Malawi
- - MW
-
- * - Malaysia
- - MY
-
- * - Maldives
- - MV
-
- * - Mali
- - ML
-
- * - Malta
- - MT
-
- * - Marshall Islands
- - MH
-
- * - Martinique
- - MQ
-
- * - Mauritania
- - MR
-
- * - Mauritius
- - MU
-
- * - Mayotte
- - YT
-
- * - Mexico
- - MX
-
- * - Moldova, Republic of
- - MD
-
- * - Monaco
- - MC
-
- * - Mongolia
- - MN
-
- * - Montenegro
- - ME
-
- * - Montserrat
- - MS
-
- * - Morocco
- - MA
-
- * - Mozambique
- - MZ
-
- * - Myanmar
- - MM
-
- * - Namibia
- - NA
-
- * - Nauru
- - NR
-
- * - Nepal
- - NP
-
- * - Netherlands
- - NL
-
- * - New Caledonia
- - NC
-
- * - New Zealand
- - NZ
-
- * - Nicaragua
- - NI
-
- * - Niger
- - NE
-
- * - Nigeria
- - NG
-
- * - Niue
- - NU
-
- * - Northern Mariana Islands
- - MP
-
- * - Norway
- - NO
-
- * - Oman
- - OM
-
- * - Pakistan
- - PK
-
- * - Palau
- - PW
-
- * - Panama
- - PA
-
- * - Papua New Guinea
- - PG
-
- * - Paraguay
- - PY
-
- * - Peru
- - PE
-
- * - Philippines
- - PH
-
- * - Poland
- - PL
-
- * - Portugal
- - PT
-
- * - Puerto Rico
- - PR
-
- * - Qatar
- - QA
-
- * - Réunion
- - RE
-
- * - Romania
- - RO
-
- * - Russian Federation
- - RU
-
- * - Rwanda
- - RW
-
- * - Saipan
- - MP
-
- * - Samoa
- - WS
-
- * - Sao Tome and Principe
- - ST
-
- * - Saudi Arabia
- - SA
-
- * - Senegal
- - SN
-
- * - Serbia
- - RS
-
- * - Seychelles
- - SC
-
- * - Sierra Leone
- - SL
-
- * - Singapore
- - SG
-
- * - Slovakia
- - SK
-
- * - Slovenia
- - SI
-
- * - Solomon Islands
- - SB
-
- * - Somalia
- - SO
-
- * - South Africa
- - ZA
-
- * - South Sudan
- - SS
-
- * - Spain
- - ES
-
- * - Sri Lanka
- - LK
-
- * - St. Barthélemy
- - BL
-
- * - St. Croix
- - VI
-
- * - St. Eustatius
- - SE
-
- * - St. Helena
- - SH
-
- * - St. John
- - AG
-
- * - St. Kitts and Nevis
- - KN
-
- * - St. Lucia
- - LC
-
- * - St. Maarten
- - SX
-
- * - St. Thomas
- - VI
-
- * - St. Vincent and the Grenadines
- - VC
-
- * - Sudan
- - SD
-
- * - Suriname
- - SR
-
- * - Swaziland
- - SZ
-
- * - Sweden
- - SE
-
- * - Switzerland
- - CH
-
- * - Syria
- - SY
-
- * - Tahiti
- - PF
-
- * - Taiwan
- - TW
-
- * - Tanzania
- - TZ
-
- * - Thailand
- - TH
-
- * - Togo
- - TG
-
- * - Tonga
- - TO
-
- * - Tortola
- - VG
-
- * - Trinidad and Tobago
- - TT
-
- * - Tunisia
- - TN
-
- * - Turkey
- - TR
-
- * - Turkmenistan
- - TM
-
- * - Turks and Caicos Islands
- - TC
-
- * - Tuvalu
- - TV
-
- * - Uganda
- - UG
-
- * - Ukraine
- - UA
-
- * - United Arab Emirates
- - AE
-
- * - United Kingdom
- - GB
-
- * - United States of America
- - US
-
- * - Uruguay
- - UY
-
- * - Uzbekistan
- - UZ
-
- * - Vanuatu
- - VU
-
- * - Venezuela
- - VE
-
- * - Vietnam
- - VN
-
- * - Virgin Islands (British)
- - VG
-
- * - Virgin Islands (US)
- - VI
-
- * - Yemen
- - YE
-
- * - Zambia
- - ZM
-
- * - Zimbabwe
- - ZW
- \ No newline at end of file
diff --git a/src/edify/library/__init__.py b/src/edify/library/__init__.py
index d048a8c..fe1f116 100644
--- a/src/edify/library/__init__.py
+++ b/src/edify/library/__init__.py
@@ -11,3 +11,4 @@ from .phone import phone_number
from .url import url
from .uuid import uuid
from .zip import zip
+from .guid import guid
diff --git a/src/edify/library/guid.py b/src/edify/library/guid.py
new file mode 100644
index 0000000..a9fb45a
--- /dev/null
+++ b/src/edify/library/guid.py
@@ -0,0 +1,14 @@
+import re
+
+pattern = "^(?:\\{{0,1}(?:[0-9a-fA-F]){8}-(?:[0-9a-fA-F]){4}-(?:[0-9a-fA-F]){4}-(?:[0-9a-fA-F]){4}-(?:[0-9a-fA-F]){12}\\}{0,1})$"
+
+def guid(guid: str) -> bool:
+ """Check if the given string is a valid GUID.
+
+ Args:
+ guid (str): The string to check.
+
+ Returns:
+ bool: True if the string is a valid GUID, False otherwise.
+ """
+ return bool(re.match(pattern, guid))
diff --git a/tests/test_guid.py b/tests/test_guid.py
new file mode 100644
index 0000000..bc0cb1a
--- /dev/null
+++ b/tests/test_guid.py
@@ -0,0 +1,11 @@
+from edify.library import guid
+
+def test_valid_guids():
+ guids = {
+ "6ba7b810-9dad-11d1-80b4-00c04fd430c8": True,
+ '{51d52cf1-83c9-4f02-b117-703ecb728b74}' : True,
+ '{51d52cf1-83c9-4f02-b117-703ecb728-b74}' : False
+ }
+ for guid_string, expectation in guids.items():
+ assert guid(guid_string) == expectation
+