Coverage for src / lexigram / contracts / cli / naming.py: 62%
8 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-19 05:41 +0800
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-19 05:41 +0800
1"""Naming utilities for CLI code generation."""
3from __future__ import annotations
5import re
8def to_snake_case(name: str) -> str:
9 """Convert a PascalCase or camelCase string to snake_case.
11 Args:
12 name: The string to convert.
14 Returns:
15 The snake_case representation.
16 """
17 return re.sub(r"(?<!^)(?=[A-Z])", "_", name).lower()
20def to_camel_case(name: str) -> str:
21 """Convert snake_case to camelCase.
23 Args:
24 name: The snake_case string to convert.
26 Returns:
27 The camelCase representation.
28 """
29 components = name.split("_")
30 return components[0] + "".join(x.title() for x in components[1:])
33__all__ = ["to_camel_case", "to_snake_case"]