Metadata-Version: 2.4
Name: formatted-join
Version: 1.1.1
Summary: Utility for joining string lists with flexible separator formatting.
Project-URL: Homepage, https://github.com/sashsinha/formatted-join
Project-URL: Documentation, https://github.com/sashsinha/formatted-join/blob/main/README.md
Project-URL: Repository, https://github.com/sashsinha/formatted-join.git
Author-email: Sash Sinha <sashsinha1@gmail.com>
Maintainer-email: Sash Sinha <sashsinha1@gmail.com>
License: MIT License
        
        Copyright (c) 2024 Sash Sinha
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: comma,join,separators,utilities
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python
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: Programming Language :: Python :: 3.13
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Provides-Extra: dev
Requires-Dist: mypy>=1.13.0; extra == 'dev'
Requires-Dist: ruff>=0.7.4; extra == 'dev'
Provides-Extra: test
Requires-Dist: parameterized; extra == 'test'
Description-Content-Type: text/markdown

<h1 align="center">Formatted Join ✅</h1>

<h3 align="center">Effortlessly join string sequences with flexible separator formatting for clear, polished output</h3>

<br/>

<p align="center">
<a href="https://raw.githubusercontent.com/sashsinha/formatted-join/main/LICENCE"><img alt="License: MIT" src="https://raw.githubusercontent.com/sashsinha/formatted-join/main/license.svg"></a>
<a href="https://pypi.org/project/formatted-join/"><img alt="PyPI" src="https://img.shields.io/pypi/v/formatted-join"></a>
<a href="https://pypi.org/project/formatted-join/"><img alt="PyPI Status" src="https://img.shields.io/pypi/status/formatted-join"></a>
<a href="https://pepy.tech/project/formatted-join"><img alt="Downloads" src="https://pepy.tech/badge/formatted-join"></a>
</p>

### Installation

#### PyPI
```
pip install formatted-join
```

#### [`uv`](https://github.com/astral-sh/uv)
```
uv add formatted-join
```

### Usage Examples

#### `formatted_join(items: Sequence[str], separator=', ', final_separator=' and ', use_penultimate_separator=True) -> str`
Joins items with flexible separator configuraton.
```py
>>> from formatted_join import formatted_join
>>> formatted_join(['Hello', 'World'])
'Hello and World'
>>> formatted_join(('A', 'B', 'C'))
'A, B, and C'
>>> formatted_join(['X', 'Y', 'Z', 'W'], separator=' | ', final_separator=' & ')
'X | Y | Z & W'
>>> formatted_join(['Solo'])
'Solo'
>>> formatted_join(['', ''])
' and '
>>> formatted_join(
...     items=['Alpha', 'Bravo', 'Charlie', 'Delta'],
...     separator=' | ',
...     final_separator=' & ',
...     use_penultimate_separator=False
... )
'Alpha | Bravo | Charlie & Delta'
>>> formatted_join(['One', 'Two'], final_separator=' ~ ')
'One ~ Two'
```

---

#### `formatted_join_conjunction(items: Sequence[str], language: str = 'en') -> str`
Joins items using a comma and localized* “and” before the last item.
```py
>>> from formatted_join import formatted_join_conjunction
>>> formatted_join_conjunction(['Spring', 'Summer'])
'Spring and Summer'
>>> formatted_join_conjunction(['One', 'Two', 'Three'])
'One, Two, and Three'
>>> formatted_join_conjunction(['Motorcycle', 'Bus', 'Car', language='en'])
'Motorcycle, Bus, and Car'
>>> formatted_join_conjunction(['Motorcycle', 'Bus', 'Car', language='de'])
'Motorcycle, Bus und Car'
```

---

#### `formatted_join_disjunction(items: Sequence[str], language: str = 'en') -> str`
Joins items using a comma and localized* “or” before the last item.
```py
>>> from formatted_join import formatted_join_disjunction
>>> formatted_join_disjunction(['Monday', 'Tuesday'])
'Monday or Tuesday'
>>> formatted_join_disjunction(['X', 'Y', 'Z'])
'X, Y, or Z'
>>> formatted_join_disjunction(['Motorcycle', 'Bus', 'Car', language='en'])
'Motorcycle, Bus, or Car'
>>> formatted_join_disjunction(['Motorcycle', 'Bus', 'Car', language='de'])
'Motorcycle, Bus oder Car'
```

---

#### `formatted_join_unit(items: Sequence[str]) -> str`
Joins items with commas only (no distinct final separator).
```py
>>> from formatted_join import formatted_join_unit
>>> formatted_join_unit(['A'])
'A'
>>> formatted_join_unit(['A', 'B', 'C', 'D'])
'A, B, C, D'
```

---

#### `formatted_join_narrow(items: Sequence[str]) -> str`
Joins items with a single space separating each.
```py
>>> from formatted_join import formatted_join_narrow
>>> formatted_join_narrow(['Only'])
'Only'
>>> formatted_join_narrow(['A', 'B', 'C'])
'A B C'
>>> formatted_join_narrow(['Line1', '-', 'Line2'])
'Line1 - Line2'
```

---- 

#### * Supported languages for `formatted_join_[conjunction|disjunction]`:

| language | and | or   | separator | has penultimate separator |
| -------- | --- | ---- | --------- | ------------------------- |
| en       | and | or   | `', '`    | yes                       |
| de       | und | oder | `', '`    | no                        |

### Development
- Install Dependencies:
  - `uv sync && uv pip install -r pyproject.toml --extra dev`
- Run formater:
  - `uv run ruff check --select I --fix && uv run ruff format`
- Run type checking:
  - `uv run mypy .`
- Run unit tests:
  - `uv run formatted_join_test.py`
