# utils


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Word Operations

------------------------------------------------------------------------

<a
href="https://github.com/cj-mills/cjm-transcript-source-select/blob/main/cjm_transcript_source_select/utils.py#L13"
target="_blank" style="float:right; font-size:smaller">source</a>

### count_words

``` python

def count_words(
    text:str, # Text to count words in
)->int: # Word count

```

*Count the number of whitespace-delimited words in text.*

## Date Formatting

------------------------------------------------------------------------

<a
href="https://github.com/cj-mills/cjm-transcript-source-select/blob/main/cjm_transcript_source_select/utils.py#L22"
target="_blank" style="float:right; font-size:smaller">source</a>

### format_date

``` python

def format_date(
    created_at:str, # ISO date string, Unix timestamp, or similar
)->str: # Formatted date for display

```

*Format a date string for human-readable display (e.g., ‘Jan 20,
2026’).*

## Filename Formatting

------------------------------------------------------------------------

<a
href="https://github.com/cj-mills/cjm-transcript-source-select/blob/main/cjm_transcript_source_select/utils.py#L59"
target="_blank" style="float:right; font-size:smaller">source</a>

### format_audio_filename

``` python

def format_audio_filename(
    audio_path:str, # Full path to audio file
)->str: # Shortened filename for display

```

*Extract and format the filename from a path.*

## Tests

``` python
assert count_words("") == 0
assert count_words("hello") == 1
assert count_words("The art of war") == 4
print("count_words tests passed")
```

``` python
assert format_date("") == "Unknown"
assert format_date(None) == "Unknown"
assert format_date("2026-01-20") == "Jan 20, 2026"
assert format_date("2026-01-20 14:30:00") == "Jan 20, 2026"
print("format_date tests passed")
```

``` python
assert format_audio_filename("/home/user/audio/test.wav") == "test.wav"
assert format_audio_filename("Unknown") == "Unknown Source"
assert format_audio_filename("") == "Unknown Source"
print("format_audio_filename tests passed")
```
