You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to see if I could use LiquidJS filters outside of .liquid templates (well, shimming them into Nunjucks templates using Eleventy, as a proof of concept), but this caught me a bit by surprise:
What was a bit surprising is that I got an object back with urlDecode instead of the actual filter name, url_decode. Attempting to use some of of these mixed case filters unsurprisingly throws errors:
[11ty] > undefined filter: stripHtml
So if I'm trying to manually add these filters into Nunjucks templates, I either have to name each one with the underscore variant, or else slugify the provided filter names myself using something like @sindresorhus/slugify with a custom separator:
Feel free to close this. I know it's a pretty bizarre edge case, but thought it might be worth documenting here, and fixing it is possibly a breaking change in case somebody is already relying on the current.stripNewlines vs proposed strip_newlines object key naming.
The text was updated successfully, but these errors were encountered:
Actually that's because liquid filter names are not always valid identifier (I mean default) in JavaScript. And this repo use snakeCase convention for variable naming.
Here's the 1:1 conversion from filter function name to template name:
I was trying to see if I could use LiquidJS filters outside of .liquid templates (well, shimming them into Nunjucks templates using Eleventy, as a proof of concept), but this caught me a bit by surprise:
OUTPUT
What was a bit surprising is that I got an object back with
urlDecode
instead of the actual filter name,url_decode
. Attempting to use some of of these mixed case filters unsurprisingly throws errors:So if I'm trying to manually add these filters into Nunjucks templates, I either have to name each one with the underscore variant, or else slugify the provided filter names myself using something like @sindresorhus/slugify with a custom separator:
OUTPUT
require("liquidjs").filters
NAMEDefault
default
abs
abs
append
append
atLeast
at_least
atMost
at_most
capitalize
capitalize
ceil
ceil
compact
compact
concat
concat
date
date
dividedBy
divided_by
downcase
downcase
escape
escape
escapeOnce
escape_once
first
first
floor
floor
join
join
json
json
last
last
lstrip
lstrip
map
map
minus
minus
modulo
modulo
newlineToBr
newline_to_br
plus
plus
prepend
prepend
remove
remove
removeFirst
remove_first
replace
replace
replaceFirst
replace_first
reverse
reverse
round
round
rstrip
rstrip
size
size
slice
slice
sort
sort
sortNatural
sort_natural
split
split
strip
strip
stripHtml
strip_html
stripNewlines
strip_newlines
times
times
truncate
truncate
truncatewords
truncatewords
uniq
uniq
upcase
upcase
urlDecode
url_decode
urlEncode
url_encode
where
where
EXPECTED RESULTS
Feel free to close this. I know it's a pretty bizarre edge case, but thought it might be worth documenting here, and fixing it is possibly a breaking change in case somebody is already relying on the current
.stripNewlines
vs proposedstrip_newlines
object key naming.The text was updated successfully, but these errors were encountered: