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: about 2 months ago
JSON representation

HTML tag-safe string truncation

Lists

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)