🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

flexibletitle

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flexibletitle

A flexible smart title case formatter for Python

1.0.0
PyPI
Maintainers
1

FlexibleTitle: Flexible Smart Title Case Formatter

FlexibleTitle is a Python library 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 Library

from flexibletitle import FlexibleTitle

Basic Usage

Single Exclusion Word

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

Multiple Exclusions as Separate Arguments

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

Exclusions as a List

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

Advanced Usage

Combining Lists and Strings

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

Empty Exclusions

If no exclusions are provided, FlexibleTitle behaves like a regular title case converter:

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

Dynamic Word Splitting

If exclusions contain multiple words in a single string, they are automatically split:

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

API Reference

Class: FlexibleTitle

Constructor

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

Method: to_flexible_title_case

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

Author

  • Name: Khalid Sulaiman Al-Mulaify
  • Email: khalidmfy@gmail.com
  • X Account: @Python__Task

License

This project is licensed under the MIT License.

Keywords

title case formatter flexible title string manipulation

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts