https://github.com/seankay/curtail
HTML tag-safe string truncation
https://github.com/seankay/curtail
Last synced: 8 months ago
JSON representation
HTML tag-safe string truncation
- Host: GitHub
- URL: https://github.com/seankay/curtail
- Owner: seankay
- License: mit
- Created: 2014-12-07T04:25:55.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2020-12-25T13:35:39.000Z (almost 5 years ago)
- Last Synced: 2025-02-09T01:34:40.762Z (9 months ago)
- Language: Elixir
- Size: 27.3 KB
- Stars: 32
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - HTML tag-safe string truncation. (Text and Numbers)
- fucking-awesome-elixir - curtail - HTML tag-safe string truncation. (Text and Numbers)
- awesome-elixir - curtail - HTML tag-safe string truncation. (Text and Numbers)
README
Curtail
=======
[](https://travis-ci.org/seankay/curtail)
HTML tag safe string truncation.
Installation
=====
```elixir
def deps do
[ {:curtail, "~> 2.0"} ]
end
```
Usage
======
### Options
* length (default: 100)
* omission (default: "...")
* word_boundary (default: "~r/\S/")
* break_token (default: nil)
Truncate using default options:
```elixir
iex> Curtail.truncate("
Truncate me!
")
"Truncate me!
"
```
Truncate with custom length:
```elixir
iex> Curtail.truncate("
Truncate me!
", length: 12)
"Truncate...
"
```
Truncate without omission string:
```elixir
iex> Curtail.truncate("
Truncate me!
", omission: "", length: 8)
"Truncate
"
```
Truncate with custom word_boundary:
```elixir
iex> Curtail.truncate("
Truncate. Me!
", word_boundary: ~r/\S[\.]/, length: 12, omission: "")
"Truncate.
"
```
Truncate without word boundary:
```elixir
iex> Curtail.truncate("
Truncate me
", word_boundary: false, length: 7)
"Trun...
"
```
Truncate with custom break_token:
```elixir
iex> Curtail.truncate("
This should be truncated here!!
", break_token: "")
"This should be truncated here
"
```
License
=======
Released under [MIT License.](http://opensource.org/licenses/MIT)