Repository: brazilian-utils/brutils-python (2023-03-31 ~ 2023-04-01)

problem_statement: Add `formatCPF` method
In order to make it with the same API as [js brutils](https://brazilian-utils.com.br/#/utilities?id=formatcpf)
date: 2023-03-31
patch: diff --git a/README.md b/README.md
index a276ce4..62563a8 100644
--- a/README.md
+++ b/README.md
@@ -51,9 +51,9 @@ False
 
 ### What if I want to format a numbers only string?
 ```
->>> cpf.display('00011122233')
+>>> from brutils import format_cpf, format_cnpj
+>>> format_cpf('00011122233')
 '000.111.222-33'
->>> from brutils import format_cnpj
 >>> format_cnpj('00111222000100')
 '00.111.222/0001-00'
 ```
diff --git a/README_PT_BR.md b/README_PT_BR.md
index 107f607..5b852f3 100644
--- a/README_PT_BR.md
+++ b/README_PT_BR.md
@@ -54,9 +54,9 @@ False
 
 ### E se eu quiser formatar uma string numérica?
 ```
->>> cpf.display('00011122233')
+>>> from brutils import format_cpf, format_cnpj
+>>> format_cpf('00011122233')
 '000.111.222-33'
->>> from brutils import format_cnpj
 >>> format_cnpj('00111222000100')
 '00.111.222/0001-00'
 ```
diff --git a/brutils/__init__.py b/brutils/__init__.py
index bace502..b6f839a 100644
--- a/brutils/__init__.py
+++ b/brutils/__init__.py
@@ -1,2 +1,2 @@
-from brutils.cpf import is_valid as is_valid_cpf
+from brutils.cpf import is_valid as is_valid_cpf, format_cpf
 from brutils.cnpj import is_valid as is_valid_cnpj, format_cnpj
diff --git a/brutils/cpf.py b/brutils/cpf.py
index b8d3ead..5013f8c 100644
--- a/brutils/cpf.py
+++ b/brutils/cpf.py
@@ -26,6 +26,14 @@ def display(cpf):  # type: (str) -> str
     return "{}.{}.{}-{}".format(cpf[:3], cpf[3:6], cpf[6:9], cpf[9:])
 
 
+def format_cpf(cpf):  # type: (str) -> str
+    """
+    Will format an adequately formatted numbers-only CPF string,
+    adding in standard formatting visual aid symbols for display.
+    """
+    return display(cpf)
+
+
 # CALCULATORS
 #############
 

test_patch: diff --git a/tests/test_cpf.py b/tests/test_cpf.py
index 782161d..ddb53e7 100644
--- a/tests/test_cpf.py
+++ b/tests/test_cpf.py
@@ -16,6 +16,7 @@ from brutils.cpf import (
     validate,
     generate,
     is_valid,
+    format_cpf,
 )
 from unittest import TestCase, main
 
@@ -35,6 +36,12 @@ class CPF(TestCase):
         assert display("0000000000a") is None
         assert display("000000000000") is None
 
+    def test_format_cpf(self):
+        assert format_cpf("00000000011") == "000.000.000-11"
+        assert format_cpf("00000000000") is None
+        assert format_cpf("0000000000a") is None
+        assert format_cpf("000000000000") is None
+
     def test_hashdigit(self):
         assert hashdigit("000000000", 10) == 0
         assert hashdigit("0000000000", 11) == 0


----

problem_statement: Add `parse_cnpj` method
To map `sieve` to `parse_cnpj` in order to make the name compatible with the [js brutils](https://brazilian-utils.com.br/#/utilities)
date: 2023-04-01
patch: diff --git a/README.md b/README.md
index 62563a8..0be88a4 100644
--- a/README.md
+++ b/README.md
@@ -72,3 +72,5 @@ False
 ```
 python3 -m unittest discover tests/
 ```
+>>> from brutils import parse_cpf, parse_cnpj
+>>> parse_cnpj('00.111.222/0001-00')
\ No newline at end of file
diff --git a/README_PT_BR.md b/README_PT_BR.md
index 5b852f3..1021687 100644
--- a/README_PT_BR.md
+++ b/README_PT_BR.md
@@ -75,3 +75,5 @@ False
 ```
 python3 -m unittest discover tests/
 ```
+>>> from brutils import parse_cpf, parse_cnpj
+>>> parse_cnpj('00.111.222/0001-00')
\ No newline at end of file
diff --git a/brutils/__init__.py b/brutils/__init__.py
index b6f839a..74f35ba 100644
--- a/brutils/__init__.py
+++ b/brutils/__init__.py
@@ -1,2 +1,7 @@
 from brutils.cpf import is_valid as is_valid_cpf, format_cpf
 from brutils.cnpj import is_valid as is_valid_cnpj, format_cnpj
+from brutils.cnpj import (
+    is_valid as is_valid_cnpj,
+    format_cnpj,
+    parse as parse_cnpj,
+)
\ No newline at end of file
diff --git a/brutils/cnpj.py b/brutils/cnpj.py
index 39bdcb8..9e64e2b 100644
--- a/brutils/cnpj.py
+++ b/brutils/cnpj.py
@@ -16,6 +16,16 @@ def sieve(dirty):  # type: (str) -> str
     return "".join(filter(lambda char: char not in "./-", dirty))
 
 
+def parse(dirty):  # type: (str) -> str
+    """
+    Filters out CNPJ formatting symbols. Symbols that are not used
+    in the CNPJ formatting are left unfiltered on purpose so that
+    if fails other tests, because their presence indicate that the
+    input was somehow corrupted.
+    """
+    return sieve(dirty)
+
+
 def display(cnpj):  # type: (str) -> str
     """
     Will format an adequately formatted numbers-only CNPJ string,

test_patch: diff --git a/tests/test_cnpj.py b/tests/test_cnpj.py
index 78e18b9..7f95949 100644
--- a/tests/test_cnpj.py
+++ b/tests/test_cnpj.py
@@ -17,6 +17,7 @@ from brutils.cnpj import (
     generate,
     is_valid,
     format_cnpj,
+    parse,
 )
 from unittest import TestCase, main
 
@@ -30,6 +31,14 @@ class CNPJ(TestCase):
         assert sieve("ab.c1.--.2-3/09.-1-./6/-.*.-!*&#") == "abc1230916*!*&#"
         assert sieve("/...---.../") == ""
 
+    def test_parse(self):
+        assert parse("00000000000") == "00000000000"
+        assert parse("12.345.678/0001-90") == "12345678000190"
+        assert parse("134..2435/.-1892.-") == "13424351892"
+        assert parse("abc1230916*!*&#") == "abc1230916*!*&#"
+        assert parse("ab.c1.--.2-3/09.-1-./6/-.*.-!*&#") == "abc1230916*!*&#"
+        assert parse("/...---.../") == ""
+
     def test_display(self):
         assert display("00000000000109") == "00.000.000/0001-09"
         assert display("00000000000000") is None


----

problem_statement: Add `parse_cpf` method
To map `sieve` to `parse_cpf` in order to make the name compatible with the [js brutils](https://brazilian-utils.com.br/#/utilities)
date: 2023-04-01
patch: diff --git a/README.md b/README.md
index 0be88a4..3a5feb8 100644
--- a/README.md
+++ b/README.md
@@ -39,7 +39,8 @@ False
 
 ### What if my string has formatting symbols in it?
 ```
->>> cpf.sieve('000.111.222-33')
+>>> from brutils import parse_cpf
+>>> parse_cpf('000.111.222-33')
 '00011122233'
 >>> cnpj.sieve('00.111.222/0001-00')
 '00111222000100'
diff --git a/README_PT_BR.md b/README_PT_BR.md
index 1021687..ec5efd9 100644
--- a/README_PT_BR.md
+++ b/README_PT_BR.md
@@ -41,7 +41,8 @@ False
 
 ### E se a minha string estiver formatada com simbolos?
 ```
->>> cpf.sieve('000.111.222-33')
+>>> from brutils import parse_cpf
+>>> parse_cpf('000.111.222-33')
 '00011122233'
 >>> cnpj.sieve('00.111.222/0001-00')
 '00111222000100'
diff --git a/brutils/__init__.py b/brutils/__init__.py
index 74f35ba..f85263f 100644
--- a/brutils/__init__.py
+++ b/brutils/__init__.py
@@ -1,4 +1,4 @@
-from brutils.cpf import is_valid as is_valid_cpf, format_cpf
+from brutils.cpf import is_valid as is_valid_cpf, format_cpf, parse as parse_cpf
 from brutils.cnpj import is_valid as is_valid_cnpj, format_cnpj
 from brutils.cnpj import (
     is_valid as is_valid_cnpj,
diff --git a/brutils/cpf.py b/brutils/cpf.py
index 5013f8c..20df337 100644
--- a/brutils/cpf.py
+++ b/brutils/cpf.py
@@ -16,6 +16,17 @@ def sieve(dirty):  # type: (str) -> str
     return "".join(filter(lambda char: char not in ".-", dirty))
 
 
+def parse(dirty):  # type: (str) -> str
+    """
+    Filters out CPF formatting symbols. Symbols that are not used
+    in the CPF formatting are left unfiltered on purpose so that
+    if fails other tests, because their presence indicate that the
+    input was somehow corrupted.
+    """
+
+    return sieve(dirty)
+
+
 def display(cpf):  # type: (str) -> str
     """
     Will format an adequately formatted numbers-only CPF string,

test_patch: diff --git a/tests/test_cpf.py b/tests/test_cpf.py
index ddb53e7..03ed793 100644
--- a/tests/test_cpf.py
+++ b/tests/test_cpf.py
@@ -17,6 +17,7 @@ from brutils.cpf import (
     generate,
     is_valid,
     format_cpf,
+    parse,
 )
 from unittest import TestCase, main
 
@@ -30,6 +31,14 @@ class CPF(TestCase):
         assert sieve("ab.c1.--.2-309.-1-.6-.*.-!*&#") == "abc1230916*!*&#"
         assert sieve("...---...") == ""
 
+    def test_parse(self):
+        assert parse("00000000000") == "00000000000"
+        assert parse("123.456.789-10") == "12345678910"
+        assert parse("134..2435.-1892.-") == "13424351892"
+        assert parse("abc1230916*!*&#") == "abc1230916*!*&#"
+        assert parse("ab.c1.--.2-309.-1-.6-.*.-!*&#") == "abc1230916*!*&#"
+        assert parse("...---...") == ""
+
     def test_display(self):
         assert display("00000000011") == "000.000.000-11"
         assert display("00000000000") is None