Skip to main content

A Python package for intelligent title case conversion and text formatting

Project description

Title Fix

A Python package for intelligent title case conversion and text formatting. This package provides a comprehensive solution for converting text between different case styles while maintaining proper capitalization rules and offering additional text analysis features.

Features

  • Multiple case conversion options:

    • Title Case (follows standard style guidelines)
    • Sentence case
    • UPPERCASE
    • lowercase
    • First Letter Case
    • AlTeRnAtInG cAsE
    • tOGGLE cAsE
  • Citation Style Support:

    • APA (American Psychological Association)
    • Chicago Manual of Style
    • AP (Associated Press)
    • MLA (Modern Language Association)
    • NYT (New York Times)
  • Additional features:

    • Word and character count
    • Straight quotes conversion
    • Quick copy functionality
    • Headline scoring
    • Input validation and error handling

Installation

pip install title-fix

Usage

Basic Usage

from title_fix import title_fix

# Simple title case conversion (using default APA style)
result = title_fix("this is a test title")
print(result["text"])  # Output: "This Is a Test Title"

# Get word and character count
print(result["word_count"])  # Output: 5
print(result["char_count"])  # Output: 20

Citation Styles

# APA Style (default) - capitalizes words with 4+ letters
result = title_fix("the theory of relativity in physics", style="apa")
print(result["text"])  # Output: "The Theory of Relativity in Physics"

# Chicago Style - capitalizes all major words
result = title_fix("the theory of relativity in physics", style="chicago")
print(result["text"])  # Output: "The Theory of Relativity in Physics"

# AP Style - capitalizes words with 4+ letters
result = title_fix("the theory of relativity in physics", style="ap")
print(result["text"])  # Output: "The Theory of Relativity in Physics"

# MLA Style - capitalizes all principal words
result = title_fix("the theory of relativity in physics", style="mla")
print(result["text"])  # Output: "The Theory of Relativity in Physics"

# NYT Style - capitalizes words with 5+ letters
result = title_fix("the theory of relativity in physics", style="nyt")
print(result["text"])  # Output: "The Theory of Relativity in Physics"

Different Case Styles

# Sentence case
result = title_fix("THIS IS A TEST.", case_type="sentence")
print(result["text"])  # Output: "This is a test."

# UPPERCASE
result = title_fix("test text", case_type="upper")
print(result["text"])  # Output: "TEST TEXT"

# lowercase
result = title_fix("TEST TEXT", case_type="lower")
print(result["text"])  # Output: "test text"

# First Letter Case
result = title_fix("test text", case_type="first")
print(result["text"])  # Output: "Test Text"

# AlTeRnAtInG cAsE
result = title_fix("test text", case_type="alt")
print(result["text"])  # Output: "TeSt TeXt"

# tOGGLE cAsE
result = title_fix("Test Text", case_type="toggle")
print(result["text"])  # Output: "tEST tEXT"

Additional Features

# Convert curly quotes to straight quotes
result = title_fix("test with quotes", straight_quotes=True)
print(result["text"])  # Converts any curly quotes to straight quotes

# Get headline score (0-100 based on best practices)
result = title_fix("How to Write the Perfect Headline in 7 Steps")
print(result["headline_score"])  # Output: 75

# Get available options
from title_fix import get_supported_styles, get_supported_case_types
print(get_supported_styles())     # ['apa', 'chicago', 'ap', 'mla', 'nyt']
print(get_supported_case_types()) # ['title', 'sentence', 'upper', 'lower', 'first', 'alt', 'toggle']

Special Handling

The package intelligently handles various text elements:

# Roman numerals
result = title_fix("world war ii and chapter iv")
print(result["text"])  # Output: "World war II and Chapter IV"

# Acronyms
result = title_fix("nasa, fbi, and cia collaboration")
print(result["text"])  # Output: "NASA, FBI, and CIA Collaboration"

# Hyphenated words
result = title_fix("well-known state-of-the-art solution")
print(result["text"])  # Output: "Well-Known State-of-the-art Solution"

# Subtitles after colons
result = title_fix("main title: a subtitle here")
print(result["text"])  # Output: "Main Title: A Subtitle Here"

Citation Style Rules

Each citation style follows specific rules for capitalization:

APA Style

  • Capitalize first word and first word after colons
  • Capitalize all major words with 4+ letters
  • Capitalize both parts of hyphenated major words
  • Always capitalize: proper nouns, acronyms, and verbs

Chicago Style

  • Capitalize first and last words
  • Capitalize all major words regardless of length
  • Lowercase articles (a, an, the), coordinating conjunctions, and prepositions
  • Capitalize both parts of hyphenated words

AP Style

  • Capitalize words with 4+ letters
  • Capitalize first and last words
  • Always capitalize: proper nouns, acronyms
  • Special handling for AP-specific terms

MLA Style

  • Capitalize first word and all principal words
  • Capitalize verbs (including is, are, was, were)
  • Lowercase articles, prepositions, and coordinating conjunctions
  • Capitalize both parts of hyphenated major words

NYT Style

  • Capitalize words with 5+ letters
  • Always capitalize proper nouns and acronyms
  • More conservative with capitalization of short words
  • Capitalize first and last words

Headline Score

The headline score is calculated based on several factors:

  • Optimal length (40-60 characters scores highest)
  • Word count (6-10 words ideal)
  • Use of power words (how, why, what, when, top, best, new, ultimate, complete, guide)
  • Use of emotional words (amazing, incredible, shocking, secret, proven)
  • Presence of numbers
  • Overall structure and readability

A score of 100 indicates an optimal headline according to common best practices. Scores above 70 are generally considered good.

Error Handling

The package includes comprehensive input validation:

from title_fix import validate_input

# Validate parameters before processing
try:
    validate_input("test text", "title", "apa")  # Valid
    validate_input("test text", "invalid", "apa")  # Raises ValueError
except ValueError as e:
    print(f"Validation error: {e}")

API Reference

Main Function

title_fix(text, case_type="title", style="apa", straight_quotes=False, quick_copy=True)

Parameters:

  • text (str): Input text to process
  • case_type (str): One of "title", "sentence", "upper", "lower", "first", "alt", "toggle"
  • style (str): Citation style for title case - "apa", "chicago", "ap", "mla", "nyt"
  • straight_quotes (bool): Convert curly quotes to straight quotes
  • quick_copy (bool): Enable quick copy functionality

Returns:

  • Dictionary with keys: text, word_count, char_count, headline_score, quick_copy, case_type, style

Utility Functions

  • get_supported_styles(): Returns list of supported citation styles
  • get_supported_case_types(): Returns list of supported case types
  • validate_input(text, case_type, style): Validates input parameters

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

title_fix-0.0.1.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

title_fix-0.0.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file title_fix-0.0.1.tar.gz.

File metadata

  • Download URL: title_fix-0.0.1.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for title_fix-0.0.1.tar.gz
Algorithm Hash digest
SHA256 ab70caa3dbf17d13e221301edb26df01bb83020c31de5da1d54c6b03cbb4374b
MD5 278981a26f658451e57483c5bad0c024
BLAKE2b-256 2d4a7a2b57c84aa78bc5063fae963771476efa9b3f1562f6ba58e4676a4c4179

See more details on using hashes here.

File details

Details for the file title_fix-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: title_fix-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for title_fix-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f83487b5682326a3f8e55a463831877b9d7961b801e0b3eb79539a60754c5ca7
MD5 8a03cb198a4d3718106d082acad219c1
BLAKE2b-256 8d08a50b48e60844cef303a3a617d718311d3c1f4fa9939c04ace2f94c21dba1

See more details on using hashes here.

Supported by

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