INNER CODE UNIT · Python
normalize_string
lissy93/portainer-templates · lib/combine.py:27
def normalize_string(original, lowercase=True):
normalized = original.translate(str.maketrans('', '', string.punctuation)).replace(' ', '')
return normalized.lower() if lowercase else normalized.capitalize()
CATEGORY_ACRONYMS = {'ai', 'vpn', 'iot', 'nas', 'dns', 'ci', 'cd', 'tv', 'os', 'ip', 'sql',
'api', 'cms', 'ftp', 'rss', 'cctv', 'llm', 'osint', 'pdf', '3d'}
def normalize_category(c):
"""Split a category into words and title-case it for display"""
if not isinstance(c, str):
return ''
# Some sources namespace their categories, and the subtype is the useful half
c = c.rsplit(':', 1)[-1].strip() or c
words = [w for w in re.split(r'[^0-9a-zA-Z]+', c) if w]
label = ' '.join(w.upper() if w.lower() in CATEGORY_ACRONYMS else w.capitalize()
for w in words)
return 'edge' if label == 'Edge' else label