tim icon indicating copy to clipboard operation
tim copied to clipboard

Respond to null values

Open premasagar opened this issue 13 years ago • 4 comments

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.

premasagar avatar Mar 09 '11 22:03 premasagar

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?

symroe avatar Oct 09 '12 16:10 symroe

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 ;)

premasagar avatar Oct 09 '12 16:10 premasagar

Not tested in tinytim (I guess this bug still applies?), and not minified (not sure what method you used for minifying).

symroe avatar Oct 10 '12 17:10 symroe

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.

premasagar avatar Oct 11 '12 10:10 premasagar