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.5.tar.gz (4.1 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.5.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_string_truncate-0.1.5.tar.gz
Algorithm Hash digest
SHA256 ffdb65423e9dfcfd8bbb8a844c52b7de479b1137d64c0a6dc05ea123d24b694e
MD5 119ace0d95b6251f755f3b892945e3d3
BLAKE2b-256 8aa0918f0db3c7c30099b5dcb5ac2e5df0aca96f165c1db6af892e56a08eac4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_string_truncate-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 761d6a8605bdae96ecb42af7cc3a6cd0ebc13131a09f280540d30bfcc95bf01a
MD5 8d7757bc48fe202816f32b2e64c56a2e
BLAKE2b-256 6386b62c5ab0e635ae4dd73ecf4e344e835082837c2d1818ce5012096013c562

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