Files
buttonplus-esphome-generator/src/buttonplus_generator/utils.py
T
2026-05-12 13:04:34 +02:00

15 lines
298 B
Python

import re
def slugify(input : str) -> str:
s = input.lower()
s = re.sub(r'\s+', '_', s)
s = re.sub(r'[^a-z0-9_]+', '', s)
s = re.sub(r'_+', '_', s)
s = s.strip('_')
if not s:
s = 'buttonplus'
while len(s) > 1 and s[0].isdigit():
s = s[1:]
return s