string_caseconv¶
shortfx.fxString.string_caseconv
¶
String Case Conversion Functions.
This module provides functions for converting strings between different naming conventions commonly used in programming and URL generation.
Key Features: - camelCase, PascalCase, snake_case, kebab-case conversions - URL-friendly slug generation - Intelligent title case - CONSTANT_CASE conversion
Functions¶
to_camel_case(text: str) -> str
¶
Converts a string to camelCase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string in any naming convention. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The string in camelCase format. |
Example
to_camel_case("hello world") 'helloWorld' to_camel_case("some_variable_name") 'someVariableName' to_camel_case("PascalCase") 'pascalCase'
Complexity: O(n)
Source code in shortfx/fxString/string_caseconv.py
to_constant_case(text: str) -> str
¶
Converts a string to CONSTANT_CASE (screaming snake case).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string in any naming convention. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The string in CONSTANT_CASE format. |
Example
to_constant_case("hello world") 'HELLO_WORLD' to_constant_case("maxRetries") 'MAX_RETRIES'
Complexity: O(n)
Source code in shortfx/fxString/string_caseconv.py
to_kebab_case(text: str) -> str
¶
Converts a string to kebab-case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string in any naming convention. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The string in kebab-case format. |
Example
to_kebab_case("Hello World") 'hello-world' to_kebab_case("camelCaseText") 'camel-case-text'
Complexity: O(n)
Source code in shortfx/fxString/string_caseconv.py
to_pascal_case(text: str) -> str
¶
Converts a string to PascalCase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string in any naming convention. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The string in PascalCase format. |
Example
to_pascal_case("hello world") 'HelloWorld' to_pascal_case("some_variable_name") 'SomeVariableName'
Complexity: O(n)
Source code in shortfx/fxString/string_caseconv.py
to_slug(text: str, separator: str = '-') -> str
¶
Converts a string to a URL-friendly slug.
Removes accents, special characters, and converts spaces to the separator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string to slugify. |
required |
separator
|
str
|
The character used between words. |
'-'
|
Returns:
| Type | Description |
|---|---|
str
|
A URL-safe slug string. |
Example
to_slug("Café Résumé!") 'cafe-resume' to_slug("Hello World 2024", separator="_") 'hello_world_2024'
Complexity: O(n)
Source code in shortfx/fxString/string_caseconv.py
to_snake_case(text: str) -> str
¶
Converts a string to snake_case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string in any naming convention. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The string in snake_case format. |
Example
to_snake_case("Hello World") 'hello_world' to_snake_case("camelCaseText") 'camel_case_text'
Complexity: O(n)
Source code in shortfx/fxString/string_caseconv.py
to_title_case(text: str) -> str
¶
Converts a string to smart Title Case.
Capitalizes the first letter of each word except articles and prepositions (English and Spanish). The first and last words are always capitalized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The string in Title Case. |
Example
to_title_case("the lord of the rings") 'The Lord of the Rings' to_title_case("el señor de los anillos") 'El Señor de los Anillos'
Complexity: O(n)