Skip to main content

Truncate strings intelligently without cutting words

Project description

philiprehberger-string-truncate

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

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.1.tar.gz (3.9 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.1.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_string_truncate-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b9ca9eca071891d2a4a94598ce40d0681fa5dcacb45bda77f1878dfe40a27927
MD5 ebf2ac1e2fa6b4f87d975cf365381bca
BLAKE2b-256 b268d48e6eb9987892d948cbc2272c349f6d436bc4fba16a7e25dc8b54cdfb54

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_string_truncate-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9b0a88695b61cdfe301959c40495b52b12c3fae62872fdc983fc1608beec371e
MD5 1833d4d19be8be843334bacfc4f84924
BLAKE2b-256 7c14631d656f7c863aa57569b5ead09c9154f6fb8e7091ab50121478e3c1d0f1

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