Skip to content

Instantly share code, notes, and snippets.

@BonsaiDen
Created July 12, 2011 20:45
Show Gist options
  • Save BonsaiDen/1078944 to your computer and use it in GitHub Desktop.
Save BonsaiDen/1078944 to your computer and use it in GitHub Desktop.
952 bytes
function lf(a){for(var b,c,d,e,f=[],g=[],h={},i=/([^\\]|^)(\{([^\{\}]+[^\\\}]|[^\{\\\}]|)\})/g,j,k,l=0,m=function(a,b){a=g[a<0?l+a:a];if(d=a[2])for(e=0;e<d.length;e++)b=b&&b[d[e]];f[a[0]]=b;return n},n={at:m,map:function(a){c=a.length;if(+c===c)for(b=0;b<c;)m(b,a[b++]);else for(b in a)n[b]&&n[b](a[b]);return n},each:function(a){for(b=0;b<l;)d=g[b++],f[d[0]]=a(b,d[1],d[2]);return n},toString:function(){return f.join("")}};;){f.push.call(f,a.substring(i.lastIndex,(j=i.exec(a))?j.index+!!j[1]:a=k).replace(/\\(\{|\})/g,"$1"),j?j[2]:k);if(!j)return n;if(/\.|\[/.test(e=j=j[3]))for(j=(c=/\.?([^\.\[]+)|\[(\d+|('|")(|.*?[^\\])\3)\]/g).exec(e)[1],b=[];d=c.exec(e);b.push(d[4]!=k?d[4]:d[2]!=k?+d[2]:d[1]));n[j]||(n[j]=function(a){return function(c){for(b=0;b<a.length;)m(a[b++],c);return n}}(h[j]=[]),n[j+"s"]=function(a){return function(f){for(b=0,d=a.length,c=f.length,e=c<d?c:d;b<e;)m(a[b],f[b++]);return n}}(h[j])),g.push([l*2+1,j,b]),h[j].push(l++)}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment