Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Ability to make it even more nano without any issues #6

Closed
TedMN opened this issue Nov 20, 2013 · 1 comment
Closed

Ability to make it even more nano without any issues #6

TedMN opened this issue Nov 20, 2013 · 1 comment

Comments

@TedMN
Copy link

TedMN commented Nov 20, 2013

Just looked at nano.js and you could easily make it several characters. It is interesting that you spend time making should you do not output null or undefined, but don't check that undefined[keys[]] or null[keys[]] is not protected, you could put it in the while(i < l && ...) adds code though.

function nano(template, data) {
return template.replace(/{([\w.]*)}/g, function(str, key) {
var keys = key.split("."), v = data[keys.shift()], i = 0, l = keys.length;
while(i < l) v = v[keys[i++]];
//simple while, hoisted variables up to avoid extra 'var', increment on use
return (typeof v == "undefined" || v == null) ? '' : v;
//change double negative save two chars.
});
}

Just sharing what I happen to see, really not any issue and I can close out either way.

@TedMN
Copy link
Author

TedMN commented Dec 30, 2019

Not critical and 6 years old

@TedMN TedMN closed this as completed Dec 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant