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.
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:
Returns
NaN
And these threw:
TypeError: Cannot read property '0' of undefined
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.