Replies: 1 comment 1 reply
-
Actually that's because liquid filter names are not always valid identifier (I mean Here's the 1:1 conversion from filter function name to template name: liquidjs/src/util/underscore.ts Lines 128 to 133 in 1af8553 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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.Beta Was this translation helpful? Give feedback.
All reactions