Metadata-Version: 2.4
Name: wordwrap
Version: 0.2.2
Summary: A simple library for wrapping text to a fixed column width.
Author: pigmonchu
Maintainer: pigmonchu
License: MIT
Project-URL: Homepage, https://github.com/pigmonchu/wordwrap
Project-URL: Documentation, https://github.com/pigmonchu/wordwrap#readme
Project-URL: Repository, https://github.com/pigmonchu/wordwrap
Project-URL: Bug Tracker, https://github.com/pigmonchu/wordwrap/issues
Project-URL: Changelog, https://github.com/pigmonchu/wordwrap/blob/main/CHANGELOG.md
Keywords: wordwrap,text,wrap,column,formatting,nlp,text-processing
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: General
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: black>=22.0.0; extra == "dev"
Requires-Dist: flake8>=4.0.0; extra == "dev"
Requires-Dist: mypy>=1.0.0; extra == "dev"
Requires-Dist: pre-commit>=2.20.0; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx>=5.0.0; extra == "docs"
Requires-Dist: sphinx-rtd-theme>=1.0.0; extra == "docs"
Provides-Extra: test
Requires-Dist: pytest>=7.0.0; extra == "test"
Requires-Dist: pytest-cov>=4.0.0; extra == "test"
Requires-Dist: pytest-mock>=3.10.0; extra == "test"
Dynamic: license-file
Dynamic: requires-python



# wordwrap

Wordwrap is a Python library for wrapping text to a fixed column width, designed for easy import and use in your own projects.

## Installation

Install from source (local):

```bash
pip install .
```

## Usage as a library

Import and use the main API:

```python
from wordwrap import WordWrap

result = WordWrap.wrap_text("This is a long line of text.", 10)
if result.is_success():
   print(result.value)  # Wrapped text with lines <= 10 chars
else:
   print(f"Error: {result.error}")
```

## API


# wordwrap

Wordwrap is a Python library for wrapping text to a fixed column width, designed for easy import and robust error handling.

## Installation

Install from PyPI:

```bash
pip install wordwrap
```

Or from source (local):

```bash
pip install .
```

## Usage

Import and use the main API:

```python
from wordwrap import WordWrap

result = WordWrap.wrap_text("This is a long line of text.", 10)
if result.is_success():
    print(result.value)  # Wrapped text with lines <= 10 chars
else:
    print(f"Error: {result.error}")
```

## API Reference

### WordWrap.wrap_text(text: str, column_width: int) -> Result

- Returns a `Result` object:
  - `.value`: Wrapped text (string)
  - `.error`: Error message (string)
- Input validation:
  - `text` must be a string
  - `column_width` must be a positive integer

## Features
- Wraps text to a specified column width, preserving words
- Handles long words and whitespace correctly
- Returns a Result object for error handling
- Python 3.8+

## Examples

```python
from wordwrap import WordWrap

# Example 1: Short text
result = WordWrap.wrap_text("word", 10)
print(result.value)  # "word"

# Example 2: Text exactly the column width
result = WordWrap.wrap_text("word123456", 10)
print(result.value)  # "word123456"

# Example 3: Text that requires splitting
result = WordWrap.wrap_text("a long line of text", 10)
print(result.value)  # "a long \nline of \ntext"

# Example 4: Long words
result = WordWrap.wrap_text("word superlongword text", 9)
print(result.value)  # "word \nsuperlong\nword text"

# Example 5: Multiple spaces
result = WordWrap.wrap_text("word    with   spaces", 10)
print(result.value)  # "word    \nwith   \nspaces"
```

## License
MIT

---

### Background

This library is inspired by the Word Wrap kata by Robert C. Martin (Uncle Bob).
