Formatting

The formatting helpers centralize string manipulation so your tools can produce consistent slugs, human-friendly labels, and tag suggestions.

Overview

StringOperator exposes slugification, casing helpers, and word-level transformations that bundle common rules for mushtags and filenames:

  • Slugification applies transliteration, delimiter normalization, and abbreviation handling to create URL-safe identifiers.

  • Case conversion covers camelCase, snake_case, and title-case variants plus reversals for finetuning display labels.

  • Word operations offer splitting, joining, and inflection helpers that respect existing abbreviations and brand-safe capitalizations.

  • Abbreviation expansion lets you replace short forms with full phrases or abbreviations sourced from config or code.

  • Tag suggestion helps derive consistent namespace/build tags from raw phrases or file paths.

Quick Start

from buvis.pybase.formatting import StringOperator

slug = StringOperator.slugify("BUVIS-CLI Utilities")
camel = StringOperator.camelize("cli_utilities")

print(slug)   # => "buvis-cli-utilities"
print(camel)  # => "CliUtilities"

API Reference

Helper Classes

class buvis.pybase.formatting.string_operator.string_case_tools.StringCaseTools

Bases: object

String case conversion utilities.

Static utility class for converting strings between naming conventions. Wraps the inflection library with BUVIS-specific field naming conventions.

static as_graphql_field_name(text: str) str

Convert a string to a GraphQL-style field name (PascalCase).

Parameters:

text – Text to convert into PascalCase.

Returns:

PascalCase string suitable for GraphQL fields.

Example

>>> StringCaseTools.as_graphql_field_name('some_value')
'SomeValue'
static as_note_field_name(text: str) str

Make a string safe for note field names (kebab-case).

Parameters:

text – Text to convert into a note field identifier.

Returns:

Kebab-case representation of the input text.

Example

>>> StringCaseTools.as_note_field_name('SomeValue')
'some-value'
static camelize(text: str) str

Convert a string into CamelCase, respecting hyphen separators.

Parameters:

text – Text containing hyphens or underscores.

Returns:

CamelCase representation of the input text.

Example

>>> StringCaseTools.camelize('some-name')
'SomeName'
static humanize(text: str) str

Turn an identifier into a human-readable phrase.

Parameters:

text – Lowercase string or identifier to make human readable.

Returns:

Human-readable string with spaces and capitalized words.

Example

>>> StringCaseTools.humanize('some_value')
'Some value'
static underscore(text: str) str

Convert a string into snake_case.

Parameters:

text – Text to convert.

Returns:

Snake_case version of the input text.

Example

>>> StringCaseTools.underscore('SomeValue')
'some_value'
class buvis.pybase.formatting.string_operator.word_level_tools.WordLevelTools

Bases: object

Word-level text manipulation utilities. Static utility class for singularization and pluralization. Wraps inflection library with domain-specific exceptions.

static pluralize(text: str) str

Pluralize text unless it matches an exception like ‘minutes’.

Parameters:

text – Word to pluralize.

Returns:

Plural form of text, or the original text when it is exempted.

Example

>>> WordLevelTools.pluralize('minutes')
'minutes'
>>> WordLevelTools.pluralize('cat')
'cats'
static singularize(text: str) str

Singularize text unless it matches an exception like ‘minutes’.

Parameters:

text – Word to singularize.

Returns:

Singular form of text, or the original text when it is exempted.

Example

>>> WordLevelTools.singularize('minutes')
'minutes'
>>> WordLevelTools.singularize('dogs')
'dog'
class buvis.pybase.formatting.string_operator.abbr.Abbr

Bases: object

Abbreviation replacement utility.

Provides static methods for expanding abbreviations in text with configurable expansion levels.

static replace_abbreviations(text: str = '', abbreviations: list[dict[str, str | None] | str] | None = None, level: int = 0) str

Expand abbreviations found in the provided text.

Parameters:
  • text – The text to process.

  • abbreviations – A list of dictionaries that map abbreviations to expansion strings, where an expansion can include an optional long form delimited by << and >> (e.g. {"API": "App<<Application Programming Interface>>"}).

  • level – Determines how much of the expansion to use (0=fix case, 1=short, 2=short+(abbr), 3=long, 4=long+(abbr)).

Returns:

A string where each abbreviation is replaced according to level.

Example:

>>> Abbr.replace_abbreviations("Use the API", [{"API": "App"}], 1)
'Use the App'