strings
In Filters
String-manipulation filters for Eleventy.
import {
firstWord,
lastWord,
trim,
stripWhitespace,
digitsOnly,
capitalize,
title,
} from '@allons-y/dashly/filters/strings';
firstWord(value)
Return the first whitespace-delimited word of a string.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string |
Returns
string | undefined
lastWord(value)
Return the last whitespace-delimited word of a string.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string |
Returns
string | undefined
trim(value)
Trim leading and trailing whitespace.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string |
Returns
string | undefined
stripWhitespace(value)
Remove all whitespace characters from a string.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string |
Returns
string | undefined
digitsOnly(value)
Strip every non-digit character from a string. Useful for phone-number normalization before formatting.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string |
Returns
string | undefined
capitalize(value)
Uppercase the first character of a string and lowercase the rest. Matches
the semantics of Nunjucks/Liquid capitalize.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string |
Returns
string | undefined
Examples
// 'Hello world'
capitalize('hello WORLD');
{{ heading | capitalize }}
title(value)
Title-case a string by uppercasing the first letter of each whitespace- delimited word and lowercasing the rest. Useful for converting slugs or raw labels into display headings.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string |
Returns
string | undefined
Examples
// 'The Quick Brown Fox'
title('the QUICK brown fox');
{{ tag | title }}