Metadata-Version: 2.4
Name: txtkit
Version: 0.1.0
Summary: 轻量中文文本处理小工具：字符统计、词频、清洗、按显示宽度截断
Author-email: reverend114 <reverend114@example.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/reverend114/txtkit
Project-URL: Source, https://github.com/reverend114/txtkit
Keywords: text,chinese,clean,word-frequency,文本处理
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Natural Language :: Chinese (Simplified)
Classifier: Topic :: Text Processing
Classifier: Intended Audience :: Developers
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# txtkit

轻量中文文本处理小工具，纯标准库实现，无第三方依赖。

## 功能

| 函数 | 说明 |
| --- | --- |
| `count_chars(text)` | 统计汉字 / 字母 / 数字 / 空白 / 其他字符数量 |
| `word_freq(text, top=5, min_len=1)` | 统计词频，按次数降序 |
| `clean(text, lower, remove_punct, squeeze_space)` | 清洗文本：转小写、去标点、压缩空白 |
| `dedup_lines(text, keep_blank=False)` | 按行去重，保留首次出现顺序 |
| `text_width(text)` | 按显示宽度计算长度（全角算 2） |
| `truncate(text, width=20, suffix="…")` | 按显示宽度截断并加省略符 |

## 安装

```bash
pip install txtkit
```

从源码安装：

```bash
pip install .
```

## 使用

```python
from txtkit import count_chars, word_freq, clean, truncate

# 字符统计
print(count_chars("Python 很好用！2026"))
# {'total': 15, 'hanzi': 3, 'letters': 6, 'digits': 4, 'spaces': 1, 'others': 1}

# 词频
print(word_freq("我爱 Python 我爱 编程", top=2))
# [('我爱', 2), ('python', 1)]

# 清洗
print(clean("  你 好 \t 世界  ！ ", remove_punct=True))
# 你 好 世界

# 按显示宽度截断（列对齐时常需要）
print(truncate("中华人民共和国万岁", 10))
# 中华人民…
```

## 自测

```bash
python tests/test_txttool.py
```

## 许可证

MIT License，详见 [LICENSE](LICENSE)。
