# `Braces.Filters`
[🔗](https://github.com/dbernheisel/braces/blob/v0.1.0/lib/braces/filters.ex#L1)

The filters, tests and operators of Jinja, Django, Nunjucks, Twig, Tera, Mailchimp, HubL and
Klaviyo, which those languages' modules render with. They're Handlebars helpers, so a
template converted to Handlebars renders with them too:

    {:ok, source} = Braces.Django.convert("Hi {{ first_name|default:'friend'|title }}")
    source
    #=> "Hi {{title (default first_name \"friend\")}}"

    Braces.Handlebars.render_to_string(Braces.Handlebars.compile!(source), %{}, helpers: Braces.Filters)
    #=> {:ok, "Hi Friend"}

Add your own helpers after them, `helpers: [Braces.Filters, MyApp.EmailHelpers]`, for
filters that aren't here: a filter is converted to a helper of the same name.

Values are true unless they're `nil`, `false`, `0`, `""`, `[]` or `%{}`, as in Python.
Comparisons compare numbers as numbers, and a number with a string that is a number, so
`"18"` equals `18`, as Mailchimp's merge fields and Klaviyo's `== 1` expect. Other values
are compared as strings.

## Helpers

- Comparisons: `eq`, `ne`, `gt`, `gte`, `lt`, `lte`, `in` (a list's element, a map's key,
  or a substring), `and`, `or`, `not`, and `is` for HubL's tests (`defined`, `undefined`,
  `none`, `truthy`, `even`, `odd`, `number`, `string`, `sequence`, `mapping`,
  `divisibleby`, `string_containing`, `string_startingwith`, `string_endingwith`, `empty`,
  `iterable`, `containing`, `boolean`, `true`, `false`, `integer`, `float`, `lower`,
  `upper`, `escaped`, `filter`, `test`).
- Text: `upper` (`upcase`), `lower` (`downcase`), `title`, `capitalize` (`capfirst`),
  `trim` (with `chars`), `truncate`, `truncate_after`, `replace` (`find_replace`),
  `striptags` (`strip_html`), `urlencode`, `escape` (`e`, `escape_html`), `safe`, `append`,
  `prepend`, `concat`, `split`, `string`, and Jinja's `wordcount`, `wordwrap`, `indent`,
  `center`, `format`, `filesizeformat`, `urlize` and `xmlattr`.
- Lists: `length` (`size`, `count`), `join`, `first`, `last`, `reverse`, and Jinja's
  `sort`, `list`, `unique`, `sum`, `min`, `max`, `batch`, `slice`, `map`, `select`,
  `reject`, `selectattr`, `rejectattr`, `groupby`, `dictsort` and `items`, with Jinja's
  keyword arguments as the hash: `{{sort people attribute="name"}}`. `groupby`, `dictsort`
  and `items` give `{key, value}` tuples.
- Numbers in words: `ordinal` (`3rd`), `number_words` (`three`) and `ordinal_words`
  (`third`), for numbers from 0 to 99.
- Numbers: `add` (`plus`), `subtract` (`minus`), `multiply`, `divide`, `modulo`, `round`,
  `abs`, `int` (with `default` and `base`), `float` (with `default`), `floatformat`.
- `default`: the value, or the fallback when the value isn't true. With `undefined: true`,
  as Jinja's `default` without its second argument, only when it's missing; with
  `empty: true`, as Twig's, when it's missing, `false`, `""`, `[]` or `%{}`; with `truth:`,
  when it's false by that language's rules, as `truthy`.
- `truthy`: whether a value is true, by Python's rules or a language's, `(truthy x "liquid")`.
- Dates: `date` formats a date with PHP's and Django's format characters, as
  `*|DATE:d/m/y|*` and Klaviyo's `|date:'F j, Y'`; `strftime` formats one with `%Y-%m-%d`;
  `now` is the current time in UTC; and
  `format_date_string` reads an ISO 8601 string.

# `abs`

# `add`

# `and`

# `and`

# `append`

# `batch`

The items in lists of `count`, the last filled with `fill` when it's given.

# `batch`

# `capfirst`

# `capitalize`

# `center`

The text in the middle of `width` characters, as Python's `center`.

# `center`

# `concat`

# `count`

# `date`

# `default`

# `dictsort`

A map's `{key, value}` pairs sorted by key, or `by: "value"`, as Jinja's `dictsort`.

# `divide`

# `downcase`

# `e`

# `empty_list`

An empty list, for a template with no literal for one.

# `empty_map`

An empty map, for a template with no literal for one.

# `eq`

# `escape`

# `escape_html`

# `filesizeformat`

A number of bytes as text, as Jinja's `filesizeformat`: `3.0 kB`, or with `binary`, `2.9 KiB`.

# `filesizeformat`

# `find_replace`

# `first`

# `float`

# `float`

# `floatformat`

# `floatformat`

# `floordiv`

`a // b`: the quotient rounded down, as Python's.

# `format`

The text with `%s`, `%d`, `%i`, `%f` and `%r` replaced by the arguments, as Python's `%`
formats them.

# `format`

# `format`

# `format`

# `format`

# `format_date_string`

# `groupby`

The items in groups by their `attribute`, as Jinja's `groupby`: `{grouper, items}` pairs in
the groupers' order, read as `group.grouper` and `group.list`, or in a loop as
`for grouper, items in …`; `default` for an item without it, and `case_sensitive`.

# `gt`

# `gte`

# `in`

# `indent`

# `indent`

Each line after the first indented by `width` spaces, or by `width` when it's text, as
Jinja's `indent`: `first` indents the first line too, and `blank` blank lines.

# `indent`

# `indent`

# `int`

# `int`

# `int`

# `is`

# `is`

# `items`

A map's `{key, value}` pairs, as Jinja's `items`.

# `join`

# `join`

# `keys`

A map's keys, or a list's indexes, as Twig's `keys` gives them.

# `last`

# `length`

# `liquid_limit`

A Liquid loop's `limit:`: the list's first `count` items.

# `liquid_limit`

# `liquid_offset`

A Liquid loop's `offset:`: the list after its first `count` items.

# `liquid_range`

Liquid's range, `(1..5)`: the integers from one to the other, both included.

# `list`

A list of the value's items: a map's keys, or a string's characters.

# `lower`

# `lt`

# `lte`

# `map`

Each item through a filter, `map("upper")`, or its `attribute`, `map(attribute="name")`,
with `default` for an item without it.

# `map`

# `map`

# `map`

# `max`

The largest item, as Jinja's `max`: `case_sensitive`, `attribute`.

# `min`

The smallest item, as Jinja's `min`: `case_sensitive`, `attribute`.

# `minus`

# `modulo`

# `multiply`

# `ne`

# `not`

# `now`

# `number_words`

# `or`

# `or`

# `ordinal`

# `ordinal_words`

# `plus`

# `power`

`a ** b`: `a` to the power `b`.

# `prepend`

# `reject`

The items a test is false for, `reject("odd")`, or that are false.

# `reject`

# `reject`

# `rejectattr`

The items whose `attribute` a test is false for, or is false.

# `rejectattr`

# `rejectattr`

# `replace`

# `replace`

# `reverse`

# `round`

# `round`

# `safe`

# `select`

The items a test is true for, `select("odd")`, or that are true.

# `select`

# `select`

# `selectattr`

The items whose `attribute` a test is true for, or is true.

# `selectattr`

# `selectattr`

# `size`

# `slice`

The items in `count` lists, as Jinja's `slice`, the shorter filled with `fill`.

# `slice`

# `sort`

A list sorted, as Jinja's `sort`: `reverse`, `case_sensitive` (false: "a" and "B" sort as
"a" and "b") and `attribute`, a key, a path, `"a.b"`, or keys, `"a,b"`, to sort items by.
Given in order or by name: `{{sort xs true}}`, `{{sort xs attribute="name"}}`. A map sorts its
keys.

# `sort`

# `sort`

# `sort`

# `split`

# `strftime`

Formats a date with `strftime`'s format, `%Y-%m-%d`, as Tera's, Liquid's and Python's dates do.

# `string`

The value as text.

# `strip_html`

# `striptags`

# `subtract`

# `sum`

The sum of the items, or of their `attribute`, from `start`.

# `sum`

# `title`

# `trim`

# `trim`

The text without spaces, or the characters of `chars`, at its ends.

# `truncate`

# `truncate`

# `truncate_after`

The first `length` characters, then `ending` when there were more, as Tera's `truncate`.

# `truncate_after`

# `truthy`

Whether a value is true by a language's rules, `"python"` when not given: see
`t:Braces.IR.truth/0`.

# `truthy`

# `unique`

The items without repeats, the first of each kept, as Jinja's `unique`: `case_sensitive`,
`attribute`.

# `upcase`

# `upper`

# `urlencode`

# `urlize`

# `urlize`

The text with its links, `http://`, `https://`, `www.` and domains, and email addresses as
`<a>` links, escaped, as Jinja's `urlize`: `trim_url_limit`, `rel` (`noopener`), `target`,
`nofollow` and `extra_schemes`.

# `wordcount`

How many words: runs of letters, digits and `_`.

# `wordwrap`

# `wordwrap`

The text in lines of at most `width` characters, as Jinja's `wordwrap`: each line of the
text wrapped on its own, joined with `wrapstring`, and words longer than a line broken
unless `break_long_words` is false.

# `wordwrap`

# `xmlattr`

A map as HTML attributes, as Jinja's `xmlattr`: ` key="value"` for each key whose value
isn't missing or `nil`, escaped.

# `xmlattr`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
