utils (case conversion helpers)
What it is
Small set of string helpers for converting arbitrary text into common identifier formats using regex tokenization.
Public API
to_pascal_case(text)- Converts
textintoPascalCaseby extracting alphanumeric tokens and capitalizing each.
- Converts
to_snake_case(text)- Converts
textintosnake_caseby extracting alphanumeric tokens, lowercasing them, and joining with_.
- Converts
to_kebab_case(text)- Converts
textintokebab-caseby extracting alphanumeric tokens, lowercasing them, and joining with-.
- Converts
Configuration/Dependencies
- Standard library only:
refor token extraction viare.findall(r"[A-Za-z0-9]+", text).
Usage
from naas_abi_cli.cli.new.utils import to_pascal_case, to_snake_case, to_kebab_case
s = "Hello, world! v2"
print(to_pascal_case(s)) # HelloWorldV2
print(to_snake_case(s)) # hello_world_v2
print(to_kebab_case(s)) # hello-world-v2Caveats
- Only ASCII letters and digits are considered tokens (
[A-Za-z0-9]+).- Other characters (spaces, punctuation, underscores, hyphens, non-ASCII letters) act as separators and are not preserved.