tim
tim copied to clipboard
Respond to null values
Currently, tim throws an exception that {{property}} not closed when it encounters a null value. This is because the typeof null === "object" and it is assuming this is an object.
Either nulls should be ignored, or the error message should be more clear.
Hitting this with an API that I can't change....
Bit of a deal breaker for using tim
for me. :(
Can you suggest a work around?
Not tested, but it should be possible to add another else if
at line 226:
else if (substituted === null){
template = '';
}
This will return an empty string, instead of throwing an error. Pull requests welcome ;)
Not tested in tinytim (I guess this bug still applies?), and not minified (not sure what method you used for minifying).
Great. Thanks @symroe.
I'm thinking that tinytim's block at line 47 should be changed to:
if (lookup === undef || lookup === null){
return '';
}
So that it no longer throws an error if the property was not found. Throwing an error can be useful, for example, to catch problems in one's data-manipulation logic that may not be easily seen, but it is probably more hassle than it's worth.