(function(e){"use strict";functionr(e){vart,o;if(null===e||void0===e)return!1;if(n.isArray(e)){for(t=0;e.length>t;t+=1)if(r(e[t]))return!0;return!1}if("string"==typeofe||"number"==typeofe||"boolean"==typeofe)return!0;for(oine)if(e.hasOwnProperty(o)&&r(e[o]))return!0;return!1}varn=function(){functione(e){return"[object Array]"===Object.prototype.toString.apply(e)}functionr(e,r,n){vart,o=n;for(tine)e.hasOwnProperty(t)&&(o=r(o,e[t],t,e));returno}functionn(e,r,n){vart,o=n;for(t=0;e.length>t;t+=1)o=r(o,e[t],t,e);returno}functiont(t,o,i){returne(t)?n(t,o,i):r(t,o,i)}functiono(e){if("object"!=typeofe||null===e)returne;Object.freeze(e);varr,n;for(nine)e.hasOwnProperty(n)&&(r=e[n],"object"==typeofr&&i(r));returne}functioni(e){return"function"==typeofObject.freeze?o(e):e}return{isArray:e,reduce:t,deepFreeze:i}}(),t=function(){functione(e){returne>="a"&&"z">=e||e>="A"&&"Z">=e}functionr(e){returne>="0"&&"9">=e}functionn(e){returnr(e)||e>="a"&&"f">=e||e>="A"&&"F">=e}return{isAlpha:e,isDigit:r,isHexDigit:n}}(),o=function(){functione(e){varr,n,t="",o=u.encode(e);for(n=0;o.length>n;n+=1)r=o.charCodeAt(n),t+="%"+r.toString(16).toUpperCase();returnt}functionr(e,r){return"%"===e[r]&&t.isHexDigit(e[r+1])&&t.isHexDigit(e[r+2])}functionn(e,r){returnparseInt(e.substr(r,2),16)}functiono(e){if(!r(e,0))return!1;vart=n(e,1),o=u.numBytes(t);if(0===o)return!1;for(vari=1;o>i;i+=1)if(!r(e,3*i)||!u.isValidFollowingCharCode(n(e,3*i+1)))return!1;return!0}functioni(e,t){varo=e[t];if(!r(e,t))returno;vari=n(e,t+1),a=u.numBytes(i);if(0===a)returno;for(vars=1;a>s;s+=1)if(!r(e,t+3*s)||!u.isValidFollowingCharCode(n(e,t+3*s+1)))returno;returne.substr(t,3*a)}varu={encode:function(e){returnunescape(encodeURIComponent(e))},numBytes:function(e){return127>=e?1:e>=194&&223>=e?2:e>=224&&239>=e?3:e>=240&&244>=e?4:0},isValidFollowingCharCode:function(e){returne>=128&&191>=e}};return{encodeCharacter:e,isPctEncoded:o,pctCharAt:i}}(),i=function(){functione(e){returnt.isAlpha(e)||t.isDigit(e)||"_"===e||o.isPctEncoded(e)}functionr(e){returnt.isAlpha(e)||t.isDigit(e)||"-"===e||"."===e||"_"===e||"~"===e}functionn(e){return":"===e||"/"===e||"?"===e||"#"===e||"["===e||"]"===e||"@"===e||"!"===e||"$"===e||"&"===e||"("===e||")"===e||"*"===e||"+"===e||","===e||";"===e||"="===e||"'"===e}return{isVarchar:e,isUnreserved:r,isReserved:n}}(),u=function(){functione(e,r){varn,t="",u="";for(("number"==typeofe||"boolean"==typeofe)&&(e=""+e),n=0;e.length>n;n+=u.length)u=e.charAt(n),t+=i.isUnreserved(u)||r&&i.isReserved(u)?u:o.encodeCharacter(u);returnt}functionr(r){returne(r,!0)}return{encode:e,encodePassReserved:r}}(),a=function(){functione(e){r[e]={symbol:e,separator:"?"===e?"&":""===e||"+"===e||"#"===e?",":e,named:";"===e||"&"===e||"?"===e,ifEmpty:"&"===e||"?"===e?"=":"",first:"+"===e?"":e,encode:"+"===e||"#"===e?u.encodePassReserved:u.encode,toString:function(){returnthis.symbol}}}varr={};returne(""),e("+"),e("#"),e("."),e("/"),e(";"),e("?"),e("&"),{valueOf:function(e){if(r[e])returnr[e];if("=,!@|".indexOf(e)>=0)throwError('Illegal use of reserved operator "'+e+'"');returnr[""]}}}(),s=function(){functione(r){this.literal=e.encodeLiteral(r)}returne.encodeLiteral=function(e){varr,n="",t="";for(r=0;e.length>r;r+=t.length)t=o.pctCharAt(e,r),n+=t.length>1?t:i.isReserved(t)||i.isUnreserved(t)?t:o.encodeCharacter(t);returnn},e.prototype.expand=function(){returnthis.literal},e.prototype.toString=e.prototype.expand,e}(),f=function(){functione(e){functionr(){p={varname:u.substring(d,f),exploded:!1,maxLength:null},d=null}functionn(){if(h===f)throwError("after a ':' you have to specify the length. position = "+f);p.maxLength=parseInt(u.substring(h,f),10),h=null}varu,s,f,c=[],p=null,d=null,h=null,g="";for(u=e.substr(1,e.length-2),s=a.valueOf(u.charAt(0)),f=""===s.symbol?0:1,d=f;u.length>f;f+=g.length){if(g=o.pctCharAt(u,f),null!==d){if("."===g){if(d===f)throwError("a varname MUST NOT start with a dot -- see position "+f);continue}if(i.isVarchar(g))continue;r()}if(null!==h){if(f===h&&"0"===g)throwError("A :prefix must not start with digit 0 -- see position "+f);if(t.isDigit(g)){if(f-h>=4)throwError("A :prefix must max 4 digits -- see position "+f);continue}n()}if(":"!==g)if("*"!==g){if(","!==g)throwError("illegal character '"+g+"' at position "+f+' of "'+u+'"');c.push(p),p=null,d=f+1}else{if(null===p)throwError("explode exploded at position "+f);if(p.exploded)throwError("explode exploded twice at position "+f);if(p.maxLength)throwError("an explode (*) MUST NOT follow to a prefix, see position "+f);p.exploded=!0}else{if(null!==p.maxLength)throwError("only one :maxLength is allowed per varspec at position "+f);h=f+1}}returnnull!==d&&r(),null!==h&&n(),c.push(p),newl(e,s,c)}functionr(r){varn,t,o=[],i=null,u=0;for(n=0;r.length>n;n+=1)if(t=r.charAt(n),null===u){if(null===i)throwError("reached unreachable code");if("{"===t)throwError("brace was opened in position "+i+" and cannot be reopened in position "+n);if("}"===t){if(i+1===n)throwError("empty braces on position "+i);o.push(e(r.substring(i,n+1))),i=null,u=n+1}}else{if("}"===t)throwError("brace was closed in position "+n+" but never opened");"{"===t&&(n>u&&o.push(news(r.substring(u,n))),u=null,i=n)}if(null!==i)throwError("brace was opened on position "+i+", but never closed");returnr.length>u&&o.push(news(r.substr(u))),newc(r,o)}returnr}(),l=function(){functione(e){returnJSON?JSON.stringify(e):e}functiont(e,r,n){this.templateText=e,this.operator=r,this.varspecs=n}returnt.prototype.toString=function(){returnthis.templateText},t.prototype.expand=function(t){functiono(e,n,t){returnr(n)&&(e.length>0&&(e+=","),c||(e+=h.encode(t)+","),e+=h.encode(n)),e}functioni(e,n,t){returnr(n)&&(e.length>0&&(e+=h.separator),e+=c?s.encodeLiteral(f.varname):h.encode(t),e+="="+h.encode(n)),e}functionu(e,n,t){returnr(n)&&(e.length>0&&(e+=h.separator),c||(e+=h.encode(t)+"="),e+=h.encode(n)),e}vara,f,l,c,p="",d=!0,h=this.operator;for(a=0;this.varspecs.length>a;a+=1)if(f=this.varspecs[a],l=t[f.varname],r(l))if(d?(p+=h.first,d=!1):p+=h.separator,c=n.isArray(l),"string"==typeofl||"number"==typeofl||"boolean"==typeofl){if(l=""+l,h.named){if(p+=s.encodeLiteral(f.varname),""===l){p+=h.ifEmpty;continue}p+="="}null!==f.maxLength&&(l=l.substr(0,f.maxLength)),p+=h.encode(l)}else{if(f.maxLength)throwError("Prefix modifiers are not applicable to variables that have composite values. You tried to expand "+this+" with "+e(l));if(f.exploded)p+=n.reduce(l,h.named?i:u,"");else{if(h.named){if(p+=s.encodeLiteral(f.varname),!r(l)){p+=h.ifEmpty;continue}p+="="}p+=n.reduce(l,o,"")}}if(d){varg=!1;for(a=0;this.varspecs.length>a;a+=1)if(this.varspecs[a].exploded){g=!0;break}h.named&&!g&&(p+=h.symbol,p+=f.varname+h.ifEmpty)}returnp},t}(),c=function(){functione(e,r){this.templateText=e,this.expressions=r,n.deepFreeze(this)}returne.prototype.toString=function(){returnthis.templateText},e.prototype.expand=function(e){varr,n="";for(r=0;this.expressions.length>r;r+=1)n+=this.expressions[r].expand(e);returnn},e.parse=f,e}();e(c)})(function(e){"use strict";"undefined"!=typeofmodule?module.exports=e:"function"==typeofdefine?define([],function(){returne}):"undefined"!=typeofwindow?window.UriTemplate=e:global.UriTemplate=e});
\ No newline at end of file
(function(e){"use strict";functionn(e){vart;if(null===e||void0===e)return!1;if(r.isArray(e))returne.length>0;if("string"==typeofe||"number"==typeofe||"boolean"==typeofe)return!0;for(tine)if(e.hasOwnProperty(t)&&n(e[t]))return!0;return!1}vart=function(){functione(e){this.options=e}returne.prototype.toString=function(){returnJSON&&JSON.stringify?JSON.stringify(this.options):this.options},e}(),r=function(){functione(e){return"[object Array]"===Object.prototype.toString.apply(e)}functionn(e,n){vart,r="",i=!0;for(t=0;e.length>t;t+=1)i?i=!1:r+=n,r+=e[t];returnr}functiont(e,n){for(vart=[],r=0;e.length>r;r+=1)t.push(n(e[r]));returnt}functionr(e,n){for(vart=[],r=0;e.length>r;r+=1)n(e[r])&&t.push(e[r]);returnt}functioni(e){if("object"!=typeofe||null===e)returne;Object.freeze(e);varn,t;for(tine)e.hasOwnProperty(t)&&(n=e[t],"object"==typeofn&&o(n));returne}functiono(e){return"function"==typeofObject.freeze?i(e):e}return{isArray:e,join:n,map:t,filter:r,deepFreeze:o}}(),i=function(){functione(e){returne>="a"&&"z">=e||e>="A"&&"Z">=e}functionn(e){returne>="0"&&"9">=e}functiont(e){returnn(e)||e>="a"&&"f">=e||e>="A"&&"F">=e}return{isAlpha:e,isDigit:n,isHexDigit:t}}(),o=function(){functione(e){varn,t,r="",i=s.encode(e);for(t=0;i.length>t;t+=1)n=i.charCodeAt(t),r+="%"+n.toString(16).toUpperCase();returnr}functionn(e,n){return"%"===e[n]&&i.isHexDigit(e[n+1])&&i.isHexDigit(e[n+2])}functiont(e,n){returnparseInt(e.substr(n,2),16)}functionr(e){if(!n(e,0))return!1;varr=t(e,1),i=s.numBytes(r);if(0===i)return!1;for(varo=1;i>o;o+=1)if(!n(e,3*o)||!s.isValidFollowingCharCode(t(e,3*o+1)))return!1;return!0}functiono(e,r){vari=e[r];if(!n(e,r))returni;varo=t(e,r+1),a=s.numBytes(o);if(0===a)returni;for(varu=1;a>u;u+=1)if(!n(e,r+3*u)||!s.isValidFollowingCharCode(t(e,r+3*u+1)))returni;returne.substr(r,3*a)}vars={encode:function(e){returnunescape(encodeURIComponent(e))},numBytes:function(e){return127>=e?1:e>=194&&223>=e?2:e>=224&&239>=e?3:e>=240&&244>=e?4:0},isValidFollowingCharCode:function(e){returne>=128&&191>=e}};return{encodeCharacter:e,isPctEncoded:r,pctCharAt:o}}(),s=function(){functione(e){returni.isAlpha(e)||i.isDigit(e)||"_"===e||o.isPctEncoded(e)}functionn(e){returni.isAlpha(e)||i.isDigit(e)||"-"===e||"."===e||"_"===e||"~"===e}functiont(e){return":"===e||"/"===e||"?"===e||"#"===e||"["===e||"]"===e||"@"===e||"!"===e||"$"===e||"&"===e||"("===e||")"===e||"*"===e||"+"===e||","===e||";"===e||"="===e||"'"===e}return{isVarchar:e,isUnreserved:n,isReserved:t}}(),a=function(){functione(e,n){vart,r="",i="";for(("number"==typeofe||"boolean"==typeofe)&&(e=""+e),t=0;e.length>t;t+=i.length)i=e.charAt(t),r+=s.isUnreserved(i)||n&&s.isReserved(i)?i:o.encodeCharacter(i);returnr}functionn(n){returne(n,!0)}functiont(e,n){vart=o.pctCharAt(e,n);returnt.length>1?t:s.isReserved(t)||s.isUnreserved(t)?t:o.encodeCharacter(t)}functionr(e){varn,t="",r="";for(n=0;e.length>n;n+=r.length)r=o.pctCharAt(e,n),t+=r.length>1?r:s.isReserved(r)||s.isUnreserved(r)?r:o.encodeCharacter(r);returnt}return{encode:e,encodePassReserved:n,encodeLiteral:r,encodeLiteralCharacter:t}}(),u=function(){functione(e){n[e]={symbol:e,separator:"?"===e?"&":""===e||"+"===e||"#"===e?",":e,named:";"===e||"&"===e||"?"===e,ifEmpty:"&"===e||"?"===e?"=":"",first:"+"===e?"":e,encode:"+"===e||"#"===e?a.encodePassReserved:a.encode,toString:function(){returnthis.symbol}}}varn={};returne(""),e("+"),e("#"),e("."),e("/"),e(";"),e("?"),e("&"),{valueOf:function(e){returnn[e]?n[e]:"=,!@|".indexOf(e)>=0?null:n[""]}}}(),f=function(){functione(e){this.literal=a.encodeLiteral(e)}returne.prototype.expand=function(){returnthis.literal},e.prototype.toString=e.prototype.expand,e}(),p=function(){functione(e){functionn(){varn=e.substring(h,f);if(0===n.length)thrownewt({expressionText:e,message:"a varname must be specified",position:f});c={varname:n,exploded:!1,maxLength:null},h=null}functionr(){if(d===f)thrownewt({expressionText:e,message:"after a ':' you have to specify the length",position:f});c.maxLength=parseInt(e.substring(d,f),10),d=null}vara,f,p=[],c=null,h=null,d=null,m="";for(a=function(n){varr=u.valueOf(n);if(null===r)thrownewt({expressionText:e,message:"illegal use of reserved operator",position:f,operator:n});returnr}(e.charAt(0)),f=a.symbol.length,h=f;e.length>f;f+=m.length){if(m=o.pctCharAt(e,f),null!==h){if("."===m){if(h===f)thrownewt({expressionText:e,message:"a varname MUST NOT start with a dot",position:f});continue}if(s.isVarchar(m))continue;n()}if(null!==d){if(f===d&&"0"===m)thrownewt({expressionText:e,message:"A :prefix must not start with digit 0",position:f});if(i.isDigit(m)){if(f-d>=4)thrownewt({expressionText:e,message:"A :prefix must have max 4 digits",position:f});continue}r()}if(":"!==m)if("*"!==m){if(","!==m)thrownewt({expressionText:e,message:"illegal character",character:m,position:f});p.push(c),c=null,h=f+1}else{if(null===c)thrownewt({expressionText:e,message:"exploded without varspec",position:f});if(c.exploded)thrownewt({expressionText:e,message:"exploded twice",position:f});if(c.maxLength)thrownewt({expressionText:e,message:"an explode (*) MUST NOT follow to a prefix",position:f});c.exploded=!0}else{if(null!==c.maxLength)thrownewt({expressionText:e,message:"only one :maxLength is allowed per varspec",position:f});if(c.exploded)thrownewt({expressionText:e,message:"an exploeded varspec MUST NOT be varspeced",position:f});d=f+1}}returnnull!==h&&n(),null!==d&&r(),p.push(c),newl(e,a,p)}functionn(n){varr,i,o=[],s=null,a=0;for(r=0;n.length>r;r+=1)if(i=n.charAt(r),null===a){if(null===s)throwError("reached unreachable code");if("{"===i)thrownewt({templateText:n,message:"brace already opened",position:r});if("}"===i){if(s+1===r)thrownewt({templateText:n,message:"empty braces",position:s});try{o.push(e(n.substring(s+1,r)))}catch(u){if(u.prototype===t.prototype)thrownewt({templateText:n,message:u.options.message,position:s+u.options.position,details:u.options});throwu}s=null,a=r+1}}else{if("}"===i)thrownewt({templateText:n,message:"unopened brace closed",position:r});"{"===i&&(r>a&&o.push(newf(n.substring(a,r))),a=null,s=r)}if(null!==s)thrownewt({templateText:n,message:"unclosed brace",position:s});returnn.length>a&&o.push(newf(n.substr(a))),newc(n,o)}returnn}(),l=function(){functione(e){returnJSON?JSON.stringify(e):e}functiont(e){if(!n(e))return!0;if(""===e)return!0;if(r.isArray(e))return0===e.length;for(vartine)if(e.hasOwnProperty(t))return!1;return!0}functioni(e){varn,t=[];for(nine)e.hasOwnProperty(n)&&t.push({name:n,value:e[n]});returnt}functiono(e,n,t){this.templateText=e,this.operator=n,this.varspecs=t}functions(e,n,t){varr="";if(t=""+t,n.named){if(r+=a.encodeLiteral(e.varname),""===t)returnr+=n.ifEmpty;r+="="}returnnull!==e.maxLength&&(t=t.substr(0,e.maxLength)),r+=n.encode(t)}functionu(e){returnn(e.value)}functionf(e,o,s){varf=[],p="";if(o.named){if(p+=a.encodeLiteral(e.varname),t(s))returnp+=o.ifEmpty;p+="="}returnr.isArray(s)?(f=s,f=r.filter(f,n),f=r.map(f,o.encode),p+=r.join(f,",")):(f=i(s),f=r.filter(f,u),f=r.map(f,function(e){returno.encode(e.name)+","+o.encode(e.value)}),p+=r.join(f,",")),p}functionp(e,o,s){varf=r.isArray(s),p=[];returnf?(p=s,p=r.filter(p,n),p=r.map(p,function(n){varr=a.encodeLiteral(e.varname);returnr+=t(n)?o.ifEmpty:"="+o.encode(n)})):(p=i(s),p=r.filter(p,u),p=r.map(p,function(e){varn=a.encodeLiteral(e.name);returnn+=t(e.value)?o.ifEmpty:"="+o.encode(e.value)})),r.join(p,o.separator)}functionl(e,t){varo=[],s="";returnr.isArray(t)?(o=t,o=r.filter(o,n),o=r.map(o,e.encode),s+=r.join(o,e.separator)):(o=i(t),o=r.filter(o,function(e){returnn(e.value)}),o=r.map(o,function(n){returne.encode(n.name)+"="+e.encode(n.value)}),s+=r.join(o,e.separator)),s}returno.prototype.toString=function(){returnthis.templateText},o.prototype.expand=function(i){varo,a,u,c,h=[],d=!1,m=this.operator;for(o=0;this.varspecs.length>o;o+=1)if(a=this.varspecs[o],u=i[a.varname],null!==u&&void0!==u)if(a.exploded&&(d=!0),c=r.isArray(u),"string"==typeofu||"number"==typeofu||"boolean"==typeofu)h.push(s(a,m,u));else{if(a.maxLength&&n(u))throwError("Prefix modifiers are not applicable to variables that have composite values. You tried to expand "+this+" with "+e(u));a.exploded?n(u)&&(m.named?h.push(p(a,m,u)):h.push(l(m,u))):(m.named||!t(u))&&h.push(f(a,m,u))}return0===h.length?"":m.first+r.join(h,m.separator)},o}(),c=function(){functione(e,n){this.templateText=e,this.expressions=n,r.deepFreeze(this)}returne.prototype.toString=function(){returnthis.templateText},e.prototype.expand=function(e){varn,t="";for(n=0;this.expressions.length>n;n+=1)t+=this.expressions[n].expand(e);returnt},e.parse=p,e.UriTemplateError=t,e}();e(c)})(function(e){"use strict";"undefined"!=typeofmodule?module.exports=e:"function"==typeofdefine?define([],function(){returne}):"undefined"!=typeofwindow?window.UriTemplate=e:global.UriTemplate=e});
'special "undefined" value, such as undef or null are not "defined"':function(test){
test.ok(!isDefined(null));
test.ok(!isDefined(undefined));
test.done();
},
'A variable value that is a string of length zero is not considered undefined':function(test){
test.ok(isDefined(''));
test.done();
},
'A variable defined as a list value is considered undefined if the list contains zero members':{
/*
'empty array is undefined': function (test) {
test.ok(!isDefined([]));
test.done();
},
*/
'array containing only null is defined':function(test){
test.ok(isDefined([null]));
test.done();
},
'array containing only undefined is defined':function(test){
test.ok(isDefined([undefined]));
test.done();
},
'array containing only empty array is defined':function(test){
test.ok(isDefined([
[]
]));
test.done();
},
'array containing only empty object is defined':function(test){
test.ok(isDefined([
{}
]));
test.done();
},
'array containing empty string is defined':function(test){
test.ok(isDefined(['']));
test.done();
}
},
// propably the longest id I ever wrote. The text is from the RFC
'A variable defined as an associative array of (name, value) pairs is considered undefined if the array contains zero members or if all member names in the array are associated with undefined values':{
'the empty object is not "defined"':function(test){
test.ok(!isDefined({}));
test.done();
},
'null is a pretty member name':function(test){
test.ok(isDefined({null:1}));
test.done();
},
'not defined if all values are not "defined':function(test){