PySpellCraft¶
spellcraft is a helper library that contains useful functions and “spells”, primarily designed for use by Dataclass Wizard.
This library aims to be Unicode-aware, internally consistent, and reasonably performant, providing convenient case conversion between common naming conventions.
Supported Cases¶
UpperCamelCase
lowerCamelCase
snake_case
kebab-case
SHOUTY_SNAKE_CASE
Title Case
SHOUTY-KEBAB-CASE
Train-Case
Note
Each spellcraft function has a _many counterpart that operates on a sequence of strings.
For example, the snake function converts a single string to snake case, while
snake_many converts a sequence of strings into a list of snake case strings.
The _many functions achieve high performance by taking advantage of Rust’s parallel features,
so you should use them in places where they make sense.
Installation¶
pip install spellcraft
Note: requires Python >= 3.9.
API¶
A Python module implemented in Rust.
- kebab(s)¶
Convert to kebab-case.
In kebab-case, word boundaries are indicated by hyphens.
Example
>>> from spellcraft import kebab >>> kebab("We are going to inherit the earth.") 'we-are-going-to-inherit-the-earth'
- kebab_many(strings)¶
Convert list of strings to kebab-case.
In kebab-case, word boundaries are indicated by hyphens.
Example
>>> from spellcraft import kebab_many >>> kebab_many(["We are going", "to inherit the earth."]) ['we-are-going', 'to-inherit-the-earth']
- lower_camel(s)¶
Convert to lowerCamelCase.
In lowerCamelCase, word boundaries are indicated by capital letters, excepting the first word.
Example
>>> from spellcraft import lower_camel >>> lower_camel("It is we who built these palaces and cities.") 'itIsWeWhoBuiltThesePalacesAndCities'
- lower_camel_many(strings)¶
Convert a list of strings to lowerCamelCase.
In lowerCamelCase, word boundaries are indicated by capital letters, excepting the first word.
Example
>>> from spellcraft import lower_camel_many >>> lower_camel_many(["It is we", "who built these"]) ['itIsWe', 'whoBuiltThese']
- shouty_kebab(s)¶
Convert to SHOUTY-KEBAB-CASE.
In SHOUTY-KEBAB-CASE, word boundaries are indicated by hyphens and all words are in uppercase.
Example
>>> from spellcraft import shouty_kebab >>> shouty_kebab("We are going to inherit the earth.") 'WE-ARE-GOING-TO-INHERIT-THE-EARTH'
- shouty_kebab_many(strings)¶
Convert a list of strings to SHOUTY-KEBAB-CASE.
In SHOUTY-KEBAB-CASE, word boundaries are indicated by hyphens and all words are in uppercase.
Example
>>> from spellcraft import shouty_kebab_many >>> shouty_kebab_many(["We are going", "to inherit the earth."]) ['WE-ARE-GOING', 'TO-INHERIT-THE-EARTH']
- shouty_snake(s)¶
Convert to SHOUTY_SNAKE_CASE.
In SHOUTY_SNAKE_CASE, word boundaries are indicated by underscores and all words are in uppercase.
Example
>>> from spellcraft import shouty_snake >>> shouty_snake("That world is growing in this minute.") 'THAT_WORLD_IS_GROWING_IN_THIS_MINUTE'
- shouty_snake_many(strings)¶
Convert a list of strings to SHOUTY_SNAKE_CASE.
In SHOUTY_SNAKE_CASE, word boundaries are indicated by underscores and all words are in uppercase.
Example
>>> from spellcraft import shouty_snake_many >>> shouty_snake_many(["That world is", "growing in this minute."]) ['THAT_WORLD_IS', 'GROWING_IN_THIS_MINUTE']
- snake(s)¶
Convert to snake_case.
In snake_case, word boundaries are indicated by underscores.
Example
>>> from spellcraft import snake >>> snake("We carry a new world here, in our hearts.") 'we_carry_a_new_world_here_in_our_hearts'
- snake_many(strings)¶
Convert a list of strings to snake_case.
In snake_case, word boundaries are indicated by underscores.
Example
>>> from spellcraft import snake_many >>> snake_many(["DeviceType", "fooBar"]) ['device_type', 'foo_bar']
- title(s)¶
Convert to Title Case.
In Title Case, word boundaries are indicated by spaces, and every word is capitalized.
Example
>>> from spellcraft import title >>> title("We have always lived in slums and holes in the wall.") 'We Have Always Lived In Slums And Holes In The Wall'
- title_many(strings)¶
Convert a list of strings to Title Case.
In Title Case, word boundaries are indicated by spaces, and every word is capitalized.
Example
>>> from spellcraft import title_many >>> title_many(["We have always", "lived in slums"]) ['We Have Always', 'Lived In Slums']
- upper_camel(s)¶
Convert to UpperCamelCase.
In UpperCamelCase, word boundaries are indicated by capital letters, including the first word.
Example
>>> from spellcraft import upper_camel >>> upper_camel("We are not in the least afraid of ruins.") 'WeAreNotInTheLeastAfraidOfRuins'
- upper_camel_many(strings)¶
Convert a list of strings to UpperCamelCase.
In UpperCamelCase, word boundaries are indicated by capital letters, including the first word.
Example
>>> from spellcraft import upper_camel_many >>> upper_camel_many(["We are not", "in the least"]) ['WeAreNot', 'InTheLeast']
Changes and License