Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seankay/curtail
HTML tag-safe string truncation
https://github.com/seankay/curtail
Last synced: 2 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 (about 10 years ago)
- Default Branch: master
- Last Pushed: 2020-12-25T13:35:39.000Z (about 4 years ago)
- Last Synced: 2024-10-03T19:45:44.028Z (3 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
=======
[![Build Status](https://travis-ci.org/seankay/curtail.svg?branch=master)](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)