Skip to main content

A simple tool for flexible smart title case formatting

Project description

SmartTitleTool: Flexible Smart Title Case Formatter

SmartTitleTool is a Python function designed to transform strings into flexible title case format while excluding specified words from capitalization. This simple yet powerful tool supports various input styles and offers unmatched flexibility for users with diverse formatting needs.

Features

  • Converts strings to a "flexible" title case format.
  • Allows exclusions for specific words (e.g., articles, prepositions).
  • Handles exclusions provided as:
    • A single word.
    • A list of words.
    • Multiple words as separate arguments.
  • Automatically normalizes exclusions to lowercase for consistency.

Importing the Function

from smarttitletool import SmartTitleTool

Example Usages

Example 1: Single exclusion word

formatter = SmartTitleTool("the")
result = formatter.to_smart_title_case("the quick brown fox jumps over the lazy dog")
print(result)  # Output: "The Quick Brown Fox Jumps Over The Lazy Dog"

Example 2: Multiple exclusions as separate arguments

formatter = SmartTitleTool("the", "over", "jumps")
result = formatter.to_smart_title_case("the quick brown fox jumps over the lazy dog")
print(result)  # Output: "The Quick Brown Fox Jumps over the Lazy Dog"

Example 3: Exclusions as a list

formatter = SmartTitleTool(["the", "over", "quick"])
result = formatter.to_smart_title_case("the quick brown fox jumps over the lazy dog")
print(result)  # Output: "The quick Brown Fox Jumps over the Lazy Dog"

Example 4: Combining lists and strings

formatter = SmartTitleTool(["the", "over"], "jumps")
result = formatter.to_smart_title_case("the quick brown fox jumps over the lazy dog")
print(result)  # Output: "The Quick Brown Fox jumps over the Lazy Dog"

Example 5: No exclusions

formatter = SmartTitleTool()
result = formatter.to_smart_title_case("the quick brown fox jumps over the lazy dog")
print(result)  # Output: "The Quick Brown Fox Jumps Over The Lazy Dog"

Example 6: Dynamic word splitting

formatter = SmartTitleTool("brown over quick")
result = formatter.to_smart_title_case("the quick brown fox jumps over the lazy dog")
print(result)  # Output: "The quick brown Fox Jumps over The Lazy Dog"

Example 7: Case insensitivity

formatter = SmartTitleTool("ThE", "OVer", "QUICK")
result = formatter.to_smart_title_case("the quick brown fox jumps over the lazy dog")
print(result)  # Output: "The quick Brown Fox Jumps over the Lazy Dog"

Example 8: First word always capitalized

formatter = SmartTitleTool("the", "and")
result = formatter.to_smart_title_case("and then there was light")
print(result)  # Output: "And Then There Was Light"

Example 9: Single word input

formatter = SmartTitleTool("the")
result = formatter.to_smart_title_case("fox")
print(result)  # Output: "Fox"

Example 10: Empty string input

formatter = SmartTitleTool("the")
result = formatter.to_smart_title_case("")
print(result)  # Output: ""

Example 11: Large input with many exclusions

exclusions = ["the", "over", "and", "a", "of", "in", "to", "on"]
formatter = SmartTitleTool(*exclusions)
text = "the history of art in the renaissance and its impact on society"
result = formatter.to_smart_title_case(text)
print(result)  # Output: "The History of Art in the Renaissance and Its Impact on Society"

API Reference

Function: SmartTitleTool

Constructor

SmartTitleTool(*exclusions)
  • exclusions (str, list, or multiple strings): Words to exclude from capitalization.

Method: to_smart_title_case

to_smart_title_case(text)
  • text (str): The input string to format.
  • Returns: A string formatted in flexible title case.

Author


License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smarttitletool-1.0.0.tar.gz (2.8 kB view details)

Uploaded Source

File details

Details for the file smarttitletool-1.0.0.tar.gz.

File metadata

  • Download URL: smarttitletool-1.0.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for smarttitletool-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ef688c17d81c2b0abda265fb8632c33dd12a50e28ab9959216745c8f1609d483
MD5 b8d59d5e67cb9d3c557a26aecec3ce18
BLAKE2b-256 d57d7925905ef4e5bd666521a6db0459fe58249c2526afc1ae106573dd7e5bfa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page