Skip to main content

Truncate strings intelligently without cutting words

Project description

philiprehberger-string-truncate

Tests PyPI version License

Truncate strings intelligently without cutting words.

Installation

pip install philiprehberger-string-truncate

Usage

from philiprehberger_string_truncate import truncate, truncate_middle, truncate_path

truncate("Hello beautiful world", max_length=15)
# "Hello…"

truncate("Hello beautiful world", max_length=15, suffix="...")
# "Hello..."

truncate_middle("Hello beautiful world of code", max_length=20)
# "Hello bea…l of code"

truncate_path("/very/long/path/to/some/file.txt", max_length=25)
# "/very/long/.../file.txt"

API

  • truncate(text, max_length, suffix="…", break_words=False) — Word-boundary truncation
  • truncate_middle(text, max_length, separator="…") — Keep start and end
  • truncate_path(path, max_length, separator="/", placeholder="...") — Path-aware truncation

Development

pip install -e .
python -m pytest tests/ -v

License

MIT

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

philiprehberger_string_truncate-0.1.4.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file philiprehberger_string_truncate-0.1.4.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_string_truncate-0.1.4.tar.gz
Algorithm Hash digest
SHA256 28991ab3647b0d9394f3fa794a92ec9c00313c0242d45956cd3e95ce241b7aff
MD5 804b4f38f73b71077a769fcd42b0f053
BLAKE2b-256 99d8226795b126b73981333fd22cf00b49366015f462227177f67863fcd1b94a

See more details on using hashes here.

File details

Details for the file philiprehberger_string_truncate-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_string_truncate-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f07bad99883cfd52f34177b4650ebaf34b72a3ce50f14d951d18c020b6efe52c
MD5 7cad56805d5df83f919e3aad7a969ab2
BLAKE2b-256 eba0b0de44f1052ceb28a0c2df16a8b2ccb4b0b8cb201bdd3a46ab49ab65d62c

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