Filters
Filters are plain functions registered with addFilter, so they work in
Nunjucks, Liquid, & 11ty.js (JavaScript) templates.
This entry re-exports every filter module; for narrower bundles, import
directly from a subpath (e.g. @allons-y/dashly/filters/dates).
arrays
Array-manipulation filters for Eleventy. Nunjucks & Liquid have native
first / last / reverse filters, but 11ty.js (JavaScript) templates &
Handlebars do not. Registering these via dashly makes them available in all
four, as checked by test/engines.test.js.
| Export | Description |
|---|---|
first(value, n?) |
Return the first item of an array, or the first n items if a count is supplied. |
last(value, n?) |
Return the last item of an array, or the last n items if a count is supplied. |
reverse(value) |
Reverse an array or a string without mutating the input. |
groupBy(value, keyOrFn) |
Group array items by a key, a dot-path, or a function. |
sortBy(value, keyOrFn, order?) |
Sort an array by a key, dot-path, or selector function, without mutating the input. |
chunk(value, size) |
Split an array into N-sized chunks. |
where(value, keyOrFn, expected?) |
Filter an array by a key/dot-path equality check. |
pluck(value, keyOrFn) |
Project an array of objects onto a single key or dot-path. |
dates
Date-related filters for Eleventy.
| Export | Description |
|---|---|
toISOString(date) |
Convert a date-like value to an ISO 8601 string. |
year(date) |
Extract the four-digit year from a date-like value. |
dateFormat(value, options?, locale?) |
Format a date using Intl.DateTimeFormat. |
longDate(value, locale?) |
Format a date as a long-form date (e.g. |
shortDate(value, locale?) |
Format a date as an abbreviated month-and-year (e.g. |
relativeDate(value, locale?, options?) |
Format a date as a locale-aware relative phrase (e.g. |
timeAgo(value, locale?, options?) |
Alias for relativeDate. |
debug
Debugging filters for rendering template data into output for inspection.
| Export | Description |
|---|---|
dump(value, indent?) |
Serialize a value as pretty-printed JSON. |
jsonify(value, indent?) |
Alias for dump. |
html
HTML-related filters for Eleventy.
cleanForRSSrequiresposthtmlas a peer dependency.renderMarkdownrequiresmarkdown-itas a peer dependency or a user-provided renderer instance.- Both are async & do not work in Handlebars; see each filter for why.
| Export | Description |
|---|---|
stripTags(value) |
Strip every HTML tag from a string, leaving only text content. |
nl2br(value) |
Replace newline characters with <br> tags. |
cleanForRSS(html, options?) |
Strip tags and elements that are unsafe or undesirable in RSS/Atom feeds. |
renderMarkdown(value, options?) |
numbers
Locale-aware number-formatting filters built on Intl.NumberFormat.
| Export | Description |
|---|---|
number(value, options?, locale?) |
Format a number using Intl.NumberFormat. |
currency(value, currencyCode?, locale?, options?) |
Format a number as a localized currency string. |
percent(value, options?) |
Format a number as a localized percentage. |
objects
Object-related filters for Eleventy.
| Export | Description |
|---|---|
keys(value) |
Return the enumerable keys of an object. |
strings
String-manipulation filters for Eleventy.
| Export | Description |
|---|---|
firstWord(value) |
Return the first whitespace-delimited word of a string. |
lastWord(value) |
Return the last whitespace-delimited word of a string. |
trim(value) |
Trim leading and trailing whitespace. |
stripWhitespace(value) |
Remove all whitespace characters from a string. |
digitsOnly(value) |
Strip every non-digit character from a string. |
capitalize(value) |
Uppercase the first character of a string and lowercase the rest. |
title(value) |
Title-case a string by uppercasing the first letter of each whitespace- delimited word and lowercasing the rest. |
tags
Tag-list helpers for Eleventy. Use to clean Eleventy's system-tag noise
(all, post, posts, etc.) out of a tag list before rendering it.
| Export | Description |
|---|---|
tags(tagList, extraExclude?, defaultExclude?) |
Filter an array of tag strings to exclude system tags and any additional names supplied either as plugin defaults or as a per-call extra list. |
text
Text-analysis filters: word counting, excerpting, and reading-time estimation. Strip HTML so callers can feed rendered post content directly.
| Export | Description |
|---|---|
wordCount(value) |
Count whitespace-delimited words in a string. |
readingTime(value, wpm?) |
Estimate reading time in minutes for a block of text. |
excerpt(value, n?, unit?) |
Pull an excerpt from a string. |
urls
URL-related filters for Eleventy.
| Export | Description |
|---|---|
validateURL(url) |
Ensure a URL is safe to render. |
absoluteUrl(path, baseUrl?) |
Resolve a path or URL against a base, producing an absolute URL. |