wolfendale / scala-nunjucks

5 stars 1 forks source link

Add filter for 'first' #6

Closed amaalali closed 4 years ago

wolfendale commented 4 years ago

I did some testing in this codepen (really useful if you want to see what nunjucks will actually do in different cases)

The following all returned undefined:

{{ { key: 'value' } | first }}
{{ 1337 | first }}
{{ true | first }}
{{ false | first }}
{{ r/foo/ | first }}
{{ '' | first }}
{{ [] | first }}
{{ +'asdf' | first }}
{{ 1 / 0 | first }}

Returns NaN

And these threw: TypeError: Cannot read property '0' of undefined

{{ undefined | first }}
{{ null | first }}

I'd stick to matching that behaviour for now (at the moment we're just throwing runtime exceptions for errors, haven't come up with a strategy for how we want to handle that.