Skip to content

Commit ca80cc4

Browse files
fmichel-adistaarthurdejong
authored andcommitted
Add fr.siren.format() function
1 parent b3a42a1 commit ca80cc4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

stdnum/fr/siren.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
InvalidChecksum: ...
3535
>>> to_tva('443 121 975')
3636
'46 443 121 975'
37+
>>> format('404833048')
38+
'404 833 048'
3739
"""
3840

3941
from __future__ import annotations
@@ -83,3 +85,9 @@ def to_tva(number: str) -> str:
8385
int(compact(number) + '12') % 97,
8486
' ' if ' ' in number else '',
8587
number)
88+
89+
90+
def format(number: str, separator: str = ' ') -> str:
91+
"""Reformat the number to the standard presentation format."""
92+
number = compact(number)
93+
return separator.join((number[:3], number[3:6], number[6:]))

0 commit comments

Comments
 (0)