text
In Filters
Text-analysis filters: word counting, excerpting, and reading-time estimation. Strip HTML so callers can feed rendered post content directly.
import {
wordCount,
readingTime,
excerpt,
} from '@allons-y/dashly/filters/text';
wordCount(value)
Count whitespace-delimited words in a string. HTML tags are stripped before counting so rendered post content can be passed in directly.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string |
Returns
number
Examples
// Returns 5
wordCount('The quick brown fox jumps');
{{ post.content | wordCount }}
readingTime(value, wpm?)
Estimate reading time in minutes for a block of text. Strips HTML, counts
words, divides by wpm (default 200), and rounds to the nearest whole
minute with a floor of 1.
Accepts either a string (counted internally) or a pre-computed word count number.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string | number |
||
wpm
(optional)
|
number |
200 |
Words per minute. |
Returns
number
: Whole-minute estimate, minimum 1.
Examples
// Returns 3
readingTime('…a 600-word post…');
{{ post.content | readingTime }} min read
{{ 1200 | readingTime(250) }}
excerpt(value, n?, unit?)
Pull an excerpt from a string. Positive n returns the first N units;
negative n returns the last |N| units. HTML tags are stripped first.
Appends an ellipsis on the trimmed side when the input is actually cut.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string |
||
n
(optional)
|
number |
30 |
Word/char count. Negative for trailing slice. |
unit
(optional)
|
'words' | 'chars' |
'words' |
Returns
string
Examples
// "The quick brown fox jumps…"
excerpt('The quick brown fox jumps over the lazy dog', 5);
// "…over the lazy dog"
excerpt('The quick brown fox jumps over the lazy dog', -4);
{{ post.content | excerpt(40) }}
{{ post.content | excerpt(200, 'chars') }}