uri-template-lite
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -5,4 +5,4 @@ | ||
/* | ||
* @version 0.1.6 | ||
* @date 2014-05-20 | ||
* @version 0.1.7 | ||
* @date 2014-05-21 | ||
* @stability 2 - Unstable | ||
@@ -114,31 +114,26 @@ * @author Lauri Rooden <lauri@rooden.ee> | ||
, add = (separator == ";" || separator == "&") | ||
, reGroup = "(.+?)" | ||
fnStr += 'sep="'+separator+'";' | ||
//fnStr += 'sep="'+separator+'";' | ||
var reGroup = key.split(",").map(function(name) { | ||
var len, exp | ||
name = name.replace(/(?:(\*)|:(\d+))$/, function(_, _exp, _len) { | ||
len = _len | ||
exp = _exp | ||
return "" | ||
}) | ||
var re = "(.*?)" | ||
, exp = name != (name = name.split("*")[0]) | ||
, len = !exp && (len = name.split(":"), name=len[0], len[1]) | ||
var reGroup = "(.*?)" | ||
pos++ | ||
//console.log("KEY", arguments) | ||
if (len) { | ||
reGroup = "((?:%..|.){1,"+len+"})" | ||
re = "((?:%..|.){1,"+len+"})" | ||
lengths[name] = {pos:pos, len: len} | ||
} | ||
else if (len = lengths[name]) { | ||
reGroup = "(\\"+len.pos+".*?)" | ||
re = "(\\"+len.pos+".*?)" | ||
} | ||
fnStr += "t=(parts["+pos+"]||'').split('"+ separator +"');" | ||
fnStr += "out[\""+name+"\"]=t.length>1?t.map(decodeURIComponent):decodeURIComponent(t[0]);" | ||
fnStr += "t=($["+pos+"]||'').split('"+ separator +"').map(decodeURIComponent);" | ||
fnStr += "o[\""+name+"\"]=t.length>1?t:t[0];" | ||
return add ? | ||
separator == "&" ? | ||
escapeRegExp(name + "=") + reGroup | ||
: escapeRegExp(name) + "(?:="+reGroup+")?" | ||
: reGroup | ||
escapeRegExp(name + "=") + re | ||
: escapeRegExp(name) + "(?:="+re+")?" | ||
: re | ||
}).join(escapeRegExp(separator)) | ||
@@ -150,3 +145,3 @@ return (op!="+"?escapeRegExp(op):"")+reGroup | ||
this.re = new RegExp(reStr) | ||
this.fn = new Function("parts", "var t,sep,eq,out={};"+fnStr+";return out") | ||
this.fn = new Function("$", "var t,o={};"+fnStr+"return o") | ||
}, | ||
@@ -153,0 +148,0 @@ match: function(uri) { |
@@ -5,4 +5,4 @@ | ||
/* | ||
* @version 0.1.6 | ||
* @date 2014-05-20 | ||
* @version 0.1.7 | ||
* @date 2014-05-21 | ||
* @stability 2 - Unstable | ||
@@ -114,31 +114,26 @@ * @author Lauri Rooden <lauri@rooden.ee> | ||
, add = (separator == ";" || separator == "&") | ||
, reGroup = "(.+?)" | ||
fnStr += 'sep="'+separator+'";' | ||
//fnStr += 'sep="'+separator+'";' | ||
var reGroup = key.split(",").map(function(name) { | ||
var len, exp | ||
name = name.replace(/(?:(\*)|:(\d+))$/, function(_, _exp, _len) { | ||
len = _len | ||
exp = _exp | ||
return "" | ||
}) | ||
var re = "(.*?)" | ||
, exp = name != (name = name.split("*")[0]) | ||
, len = !exp && (len = name.split(":"), name=len[0], len[1]) | ||
var reGroup = "(.*?)" | ||
pos++ | ||
//console.log("KEY", arguments) | ||
if (len) { | ||
reGroup = "((?:%..|.){1,"+len+"})" | ||
re = "((?:%..|.){1,"+len+"})" | ||
lengths[name] = {pos:pos, len: len} | ||
} | ||
else if (len = lengths[name]) { | ||
reGroup = "(\\"+len.pos+".*?)" | ||
re = "(\\"+len.pos+".*?)" | ||
} | ||
fnStr += "t=(parts["+pos+"]||'').split('"+ separator +"');" | ||
fnStr += "out[\""+name+"\"]=t.length>1?t.map(decodeURIComponent):decodeURIComponent(t[0]);" | ||
fnStr += "t=($["+pos+"]||'').split('"+ separator +"').map(decodeURIComponent);" | ||
fnStr += "o[\""+name+"\"]=t.length>1?t:t[0];" | ||
return add ? | ||
separator == "&" ? | ||
escapeRegExp(name + "=") + reGroup | ||
: escapeRegExp(name) + "(?:="+reGroup+")?" | ||
: reGroup | ||
escapeRegExp(name + "=") + re | ||
: escapeRegExp(name) + "(?:="+re+")?" | ||
: re | ||
}).join(escapeRegExp(separator)) | ||
@@ -150,3 +145,3 @@ return (op!="+"?escapeRegExp(op):"")+reGroup | ||
this.re = new RegExp(reStr) | ||
this.fn = new Function("parts", "var t,sep,eq,out={};"+fnStr+";return out") | ||
this.fn = new Function("$", "var t,o={};"+fnStr+"return o") | ||
}, | ||
@@ -153,0 +148,0 @@ match: function(uri) { |
@@ -1,3 +0,2 @@ | ||
!function(k){function e(a){return a.replace(n,"\\$&")}function f(a){this.init(this.template=a)}var p={"":",","+":",","#":",","?":"&"},n=/[.*+?^=!:${}()|\[\]\/\\]/g,q=new RegExp(/\{([+#.\/;?&]?)((?:[\w%.]+(\*|:\d)?,?)+)\}/g.source+"|.[^{]*?","g");f.prototype={init:function(a){var l=0,b="",f={};a="^"+a.replace(q,function(a,h,m){if(!m)return e(a);var c=p[h]||h,k=";"==c||"&"==c;a="(.+?)";b+='sep="'+c+'";';a=m.split(",").map(function(a){var d;a=a.replace(/(?:(\*)|:(\d+))$/,function(a,b,c){d=c;return""}); | ||
var g="(.*?)";l++;if(d)g="((?:%..|.){1,"+d+"})",f[a]={pos:l,len:d};else if(d=f[a])g="(\\"+d.pos+".*?)";b+="t=(parts["+l+"]||'').split('"+c+"');";b+='out["'+a+'"]=t.length>1?t.map(decodeURIComponent):decodeURIComponent(t[0]);';return k?"&"==c?e(a+"=")+g:e(a)+"(?:="+g+")?":g}).join(e(c));return("+"!=h?e(h):"")+a})+"$";this.re=new RegExp(a);this.fn=new Function("parts","var t,sep,eq,out={};"+b+";return out")},match:function(a){return(a=this.re.exec(a))&&this.fn(a)}};k.Template=f}(this.URI||(this.URI= | ||
{})); | ||
!function(k){function c(a){return a.replace(n,"\\$&")}function d(a){this.init(this.template=a)}var p={"":",","+":",","#":",","?":"&"},n=/[.*+?^=!:${}()|\[\]\/\\]/g,q=new RegExp(/\{([+#.\/;?&]?)((?:[\w%.]+(\*|:\d)?,?)+)\}/g.source+"|.[^{]*?","g");d.prototype={init:function(a){var l=0,e="",d={};a="^"+a.replace(q,function(a,h,m){if(!m)return c(a);var f=p[h]||h,k=";"==f||"&"==f;a=m.split(",").map(function(a){var g="(.*?)",b=a==(a=a.split("*")[0])&&(b=a.split(":"),a=b[0],b[1]);l++;if(b)g="((?:%..|.){1,"+ | ||
b+"})",d[a]={pos:l,len:b};else if(b=d[a])g="(\\"+b.pos+".*?)";e+="t=($["+l+"]||'').split('"+f+"').map(decodeURIComponent);";e+='o["'+a+'"]=t.length>1?t:t[0];';return k?"&"==f?c(a+"=")+g:c(a)+"(?:="+g+")?":g}).join(c(f));return("+"!=h?c(h):"")+a})+"$";this.re=new RegExp(a);this.fn=new Function("$","var t,o={};"+e+"return o")},match:function(a){return(a=this.re.exec(a))&&this.fn(a)}};k.Template=d}(this.URI||(this.URI={})); |
@@ -1,4 +0,4 @@ | ||
!function(p){function u(a){return encodeURIComponent(a).replace(v,escape)}function l(a){return a.replace(w,"\\$&")}function x(a,g,e){return a+(g||"&"==e?"=":"")+g}function m(a,g,e){a=a.map(g).filter(function(a){return"string"==typeof a});return a.length&&a.join(e)}function q(a,g){return a.replace(r,function(a,f,y){var b=s[f]||f,h=f&&","==b?encodeURI:u,d=(";"==b||"&"==b)&&x;return(a=m(y.split(","),function(a){var n=a!=(a=a.split("*")[0]),k=!n&&(k=a.split(":"),a=k[0],k[1]),c=g[a];if(null!=c){if("object"== | ||
typeof c){if(Array.isArray(c)?c=m(c,h,n?d?b+a+"=":b:","):(k=n?"=":",",c=m(Object.keys(c),function(a){return h(a)+k+h(c[a])},n&&(d||"/"==b)?b:","),n&&(d=null)),!c)return}else c=h(k?c.slice(0,k):c);return d?d(a,c,b):c}},b))?"+"!=f?f+a:a:""!==a||"#"!=f&&"."!=f?"":f})}function t(a){this.init(this.template=a);this.expand=q.bind(this,a)}var v=/[\]\[:\/?#@!$&()*+,;=']/g,s={"":",","+":",","#":",","?":"&"},w=/[.*+?^=!:${}()|\[\]\/\\]/g,r=/\{([+#.\/;?&]?)((?:[\w%.]+(\*|:\d)?,?)+)\}/g,z=new RegExp(r.source+ | ||
"|.[^{]*?","g");p.expand=q;t.prototype={init:function(a){var g=0,e="",f={};a="^"+a.replace(z,function(a,b,h){if(!h)return l(a);var d=s[b]||b,m=";"==d||"&"==d;a="(.+?)";e+='sep="'+d+'";';a=h.split(",").map(function(a){var b;a=a.replace(/(?:(\*)|:(\d+))$/,function(a,c,d){b=d;return""});var c="(.*?)";g++;if(b)c="((?:%..|.){1,"+b+"})",f[a]={pos:g,len:b};else if(b=f[a])c="(\\"+b.pos+".*?)";e+="t=(parts["+g+"]||'').split('"+d+"');";e+='out["'+a+'"]=t.length>1?t.map(decodeURIComponent):decodeURIComponent(t[0]);'; | ||
return m?"&"==d?l(a+"=")+c:l(a)+"(?:="+c+")?":c}).join(l(d));return("+"!=b?l(b):"")+a})+"$";this.re=new RegExp(a);this.fn=new Function("parts","var t,sep,eq,out={};"+e+";return out")},match:function(a){return(a=this.re.exec(a))&&this.fn(a)}};p.Template=t}(this.URI||(this.URI={})); | ||
!function(p){function u(a){return encodeURIComponent(a).replace(v,escape)}function h(a){return a.replace(w,"\\$&")}function x(a,f,g){return a+(f||"&"==g?"=":"")+f}function m(a,f,g){a=a.map(f).filter(function(a){return"string"==typeof a});return a.length&&a.join(g)}function q(a,f){return a.replace(r,function(a,d,h){var c=s[d]||d,k=d&&","==c?encodeURI:u,e=(";"==c||"&"==c)&&x;return(a=m(h.split(","),function(a){var n=a!=(a=a.split("*")[0]),l=!n&&(l=a.split(":"),a=l[0],l[1]),b=f[a];if(null!=b){if("object"== | ||
typeof b){if(Array.isArray(b)?b=m(b,k,n?e?c+a+"=":c:","):(l=n?"=":",",b=m(Object.keys(b),function(a){return k(a)+l+k(b[a])},n&&(e||"/"==c)?c:","),n&&(e=null)),!b)return}else b=k(l?b.slice(0,l):b);return e?e(a,b,c):b}},c))?"+"!=d?d+a:a:""!==a||"#"!=d&&"."!=d?"":d})}function t(a){this.init(this.template=a);this.expand=q.bind(this,a)}var v=/[\]\[:\/?#@!$&()*+,;=']/g,s={"":",","+":",","#":",","?":"&"},w=/[.*+?^=!:${}()|\[\]\/\\]/g,r=/\{([+#.\/;?&]?)((?:[\w%.]+(\*|:\d)?,?)+)\}/g,y=new RegExp(r.source+ | ||
"|.[^{]*?","g");p.expand=q;t.prototype={init:function(a){var f=0,g="",d={};a="^"+a.replace(y,function(a,c,k){if(!k)return h(a);var e=s[c]||c,m=";"==e||"&"==e;a=k.split(",").map(function(a){var c="(.*?)",b=a==(a=a.split("*")[0])&&(b=a.split(":"),a=b[0],b[1]);f++;if(b)c="((?:%..|.){1,"+b+"})",d[a]={pos:f,len:b};else if(b=d[a])c="(\\"+b.pos+".*?)";g+="t=($["+f+"]||'').split('"+e+"').map(decodeURIComponent);";g+='o["'+a+'"]=t.length>1?t:t[0];';return m?"&"==e?h(a+"=")+c:h(a)+"(?:="+c+")?":c}).join(h(e)); | ||
return("+"!=c?h(c):"")+a})+"$";this.re=new RegExp(a);this.fn=new Function("$","var t,o={};"+g+"return o")},match:function(a){return(a=this.re.exec(a))&&this.fn(a)}};p.Template=t}(this.URI||(this.URI={})); |
33
index.js
@@ -5,4 +5,4 @@ | ||
/* | ||
* @version 0.1.6 | ||
* @date 2014-05-20 | ||
* @version 0.1.7 | ||
* @date 2014-05-21 | ||
* @stability 2 - Unstable | ||
@@ -114,31 +114,26 @@ * @author Lauri Rooden <lauri@rooden.ee> | ||
, add = (separator == ";" || separator == "&") | ||
, reGroup = "(.+?)" | ||
fnStr += 'sep="'+separator+'";' | ||
//fnStr += 'sep="'+separator+'";' | ||
var reGroup = key.split(",").map(function(name) { | ||
var len, exp | ||
name = name.replace(/(?:(\*)|:(\d+))$/, function(_, _exp, _len) { | ||
len = _len | ||
exp = _exp | ||
return "" | ||
}) | ||
var re = "(.*?)" | ||
, exp = name != (name = name.split("*")[0]) | ||
, len = !exp && (len = name.split(":"), name=len[0], len[1]) | ||
var reGroup = "(.*?)" | ||
pos++ | ||
//console.log("KEY", arguments) | ||
if (len) { | ||
reGroup = "((?:%..|.){1,"+len+"})" | ||
re = "((?:%..|.){1,"+len+"})" | ||
lengths[name] = {pos:pos, len: len} | ||
} | ||
else if (len = lengths[name]) { | ||
reGroup = "(\\"+len.pos+".*?)" | ||
re = "(\\"+len.pos+".*?)" | ||
} | ||
fnStr += "t=(parts["+pos+"]||'').split('"+ separator +"');" | ||
fnStr += "out[\""+name+"\"]=t.length>1?t.map(decodeURIComponent):decodeURIComponent(t[0]);" | ||
fnStr += "t=($["+pos+"]||'').split('"+ separator +"').map(decodeURIComponent);" | ||
fnStr += "o[\""+name+"\"]=t.length>1?t:t[0];" | ||
return add ? | ||
separator == "&" ? | ||
escapeRegExp(name + "=") + reGroup | ||
: escapeRegExp(name) + "(?:="+reGroup+")?" | ||
: reGroup | ||
escapeRegExp(name + "=") + re | ||
: escapeRegExp(name) + "(?:="+re+")?" | ||
: re | ||
}).join(escapeRegExp(separator)) | ||
@@ -150,3 +145,3 @@ return (op!="+"?escapeRegExp(op):"")+reGroup | ||
this.re = new RegExp(reStr) | ||
this.fn = new Function("parts", "var t,sep,eq,out={};"+fnStr+";return out") | ||
this.fn = new Function("$", "var t,o={};"+fnStr+"return o") | ||
}, | ||
@@ -153,0 +148,0 @@ match: function(uri) { |
{ | ||
"name": "uri-template-lite", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"stability": 2, | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -9,4 +9,4 @@ [1]: https://secure.travis-ci.org/litejs/uri-template-lite.png | ||
@version 0.1.6 | ||
@date 2014-05-20 | ||
@version 0.1.7 | ||
@date 2014-05-21 | ||
@stability 2 - Unstable | ||
@@ -13,0 +13,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75166
1511