1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2026-04-24 20:56:11 +02:00

add normalize_key() function and tests

This commit is contained in:
Kelly Brazil
2024-02-02 15:14:30 -08:00
parent c05fa7e9cd
commit b65f37e075
5 changed files with 88 additions and 1 deletions
+27
View File
@@ -7,6 +7,7 @@
* [compatibility](#jc.utils.compatibility)
* [has\_data](#jc.utils.has_data)
* [remove\_quotes](#jc.utils.remove_quotes)
* [normalize\_key](#jc.utils.normalize_key)
* [convert\_to\_int](#jc.utils.convert_to_int)
* [convert\_to\_float](#jc.utils.convert_to_float)
* [convert\_to\_bool](#jc.utils.convert_to_bool)
@@ -134,6 +135,32 @@ def remove_quotes(data: str) -> str
Remove single or double quotes surrounding a string. If no quotes are
found then the string is returned unmodified.
Parameters:
data: (string) Input value
Returns:
string
<a id="jc.utils.normalize_key"></a>
### normalize\_key
```python
def normalize_key(data: str) -> str
```
Normalize a key name by shifting to lower-case and converting special
characters to underscores.
Special characters are defined as `space` and the following:
!"#$%&'()*+,-./:;<=>?@[\]^`{|}~
This is a lossy algorithm. Repeating and trailing underscores are
removed.
Parameters:
data: (string) Input value