Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
/*
 URI.js v1.4.2 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js
*/
if(typeof exports==="undefined")exports={};if(typeof require!=="function")require=function(){return exports};
URI=function(){function k(){this.errors=[]}function o(a){return a===undefined?"undefined":a===null?"null":Object.prototype.toString.call(a).split(" ").pop().split("]").shift().toLowerCase()}function v(a){for(var b="",c=0,d,g,w;c<a.length;){d=parseInt(a.substr(c+1,2),16);if(d<128){b+=String.fromCharCode(d);c+=3}else if(d>191&&d<224){g=parseInt(a.substr(c+4,2),16);b+=String.fromCharCode((d&31)<<6|g&63);c+=6}else{g=parseInt(a.substr(c+4,2),16);w=parseInt(a.substr(c+7,2),16);b+=String.fromCharCode((d&
15)<<12|(g&63)<<6|w&63);c+=9}}return b}function x(a){for(var b="",c=0,d;c<a.length;){d=parseInt(a.substr(c+1,2),16);if(d<128){d=String.fromCharCode(d);b+=d.match(G)?d:a.substr(c,3);c+=3}else if(d>191&&d<224){b+=a.substr(c,6);c+=6}else{b+=a.substr(c,9);c+=9}}return b}function m(a){a=a.charCodeAt(0);return a<16?"%0"+a.toString(16).toUpperCase():a<128?"%"+a.toString(16).toUpperCase():a<2048?"%"+(a>>6|192).toString(16).toUpperCase()+"%"+(a&63|128).toString(16).toUpperCase():"%"+(a>>12|224).toString(16).toUpperCase()+
"%"+(a>>6&63|128).toString(16).toUpperCase()+"%"+(a&63|128).toString(16).toUpperCase()}function f(a){return"(?:"+a+")"}function j(a){for(var b=a,c=1,d=arguments[c];d;){b=b.slice(0,-1)+d.slice(1);d=arguments[++c]}return b}var l=j("[0-9]","[A-Fa-f]"),h=f("%"+l+l),n=j("[\\:\\/\\?\\#\\[\\]\\@]","[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]"),i=j("[A-Za-z]","[0-9]","[\\-\\.\\_\\~]"),p=f("[A-Za-z]"+j("[A-Za-z]","[0-9]","[\\+\\-\\.]")+"*"),q=f(f(h+"|"+j(i,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]","[\\:]"))+"*"),r=f(f("25[0-5]")+
"|"+f("2[0-4][0-9]")+"|"+f("1[0-9][0-9]")+"|"+f("[1-9][0-9]")+"|[0-9]");r=f(r+"\\."+r+"\\."+r+"\\."+r);var u=f(j(i,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]","[\\:]")+"+");l=f("v"+l+"+\\."+j(i,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]","[\\:]")+"+");l=f("\\["+f(u+"|"+l)+"\\]");u=f(f(h+"|"+j(i,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]"))+"*");r=f(l+"|"+r+"|"+u);l=f("[0-9]*");var s=f(h+"|"+j(i,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]","[\\:\\@]")),t=f(s+"*");u=f(s+"+");var H=f(f(h+"|"+j(i,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",
"[\\@]"))+"+");t=f(f("\\/"+t)+"*");var y=f("\\/"+f(u+t)+"?"),z=f(""),A=f(f(s+"|[\\/\\?]")+"*");s=f(f(s+"|[\\/\\?]")+"*");var I=RegExp("("+("^("+p+")\\:"+f(f("\\/\\/("+f("("+q+")@")+"?("+r+")"+f("\\:("+l+")")+"?)")+"?("+t+"|"+y+"|"+f(u+t)+"|"+z+")")+f("\\?("+A+")")+"?"+f("\\#("+s+")")+"?$")+")|("+("^(){0}"+f(f("\\/\\/("+f("("+q+")@")+"?("+r+")"+f("\\:("+l+")")+"?)")+"?("+t+"|"+y+"|"+f(H+t)+"|"+z+")")+f("\\?("+A+")")+"?"+f("\\#("+s+")")+"?$")+")"),J=RegExp(j("[^]","[A-Za-z]","[0-9]","[\\+\\-\\.]"),
"g"),K=RegExp(j("[^\\%\\:]",i,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]"),"g"),L=RegExp(j("[^\\%]",i,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]"),"g"),M=RegExp(j("[^\\%\\/\\:\\@]",i,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]"),"g"),N=RegExp(j("[^\\%\\/\\@]",i,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]"),"g"),B=RegExp(j("[^\\%]",i,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]","[\\:\\@\\/\\?]"),"g"),O=RegExp(j("[^]",i,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]"),"g"),G=RegExp(i,"g");j("[^\\%]",i,n);var C=RegExp(h+"+","g"),P=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?([^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n)*))?/i,
D=/^\.\.?\//,E=/^\/\.(\/|$)/,F=/^\/\.\.(\/|$)/,Q=/^\/?(?:.|\n)*?(?=\/|$)/,R="".match(/(){0}/)[1]===undefined,e=exports;k.prototype={scheme:undefined,userinfo:undefined,host:undefined,port:undefined,path:undefined,query:undefined,fragment:undefined,reference:undefined,errors:undefined};e.a={};e.parse=function(a,b){var c,d=new k;a=a?a.toString():"";b=b||{};if(b.reference==="suffix")a=(b.scheme?b.scheme+":":"")+"//"+a;if(c=a.match(I))c=c[1]?c.slice(1,10):c.slice(10,19);if(!c){b.tolerant||d.errors.push("URI is not strictly valid.");
c=a.match(P)}if(c){if(R){d.scheme=c[1];d.userinfo=c[3];d.host=c[4];d.port=parseInt(c[5],10);d.path=c[6]||"";d.query=c[7];d.fragment=c[8];if(isNaN(d.port))d.port=c[5]}else{d.scheme=c[1]||undefined;d.userinfo=a.indexOf("@")!==-1?c[3]:undefined;d.host=a.indexOf("//")!==-1?c[4]:undefined;d.port=parseInt(c[5],10);d.path=c[6]||"";d.query=a.indexOf("?")!==-1?c[7]:undefined;d.fragment=a.indexOf("#")!==-1?c[8]:undefined;if(isNaN(d.port))d.port=a.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?c[4]:undefined}d.reference=
d.scheme===undefined&&d.userinfo===undefined&&d.host===undefined&&d.port===undefined&&d.path===undefined&&d.query===undefined?"same-document":d.scheme===undefined?"relative":d.fragment===undefined?"absolute":"uri";b.reference&&b.reference!=="suffix"&&b.reference!==d.reference&&d.errors.push("URI is not a "+b.reference+" reference.");(c=e.a[(b.scheme||d.scheme||"").toLowerCase()])&&c.parse&&c.parse(d,b)}else d.errors.push("URI can not be parsed.");return d};e.e=function(a){var b=[];if(a.userinfo!==
undefined){b.push(a.userinfo.toString().replace(K,m));b.push("@")}a.host!==undefined&&b.push(a.host.toString().toLowerCase().replace(L,m));if(typeof a.port==="number"){b.push(":");b.push(a.port.toString(10))}return b.length?b.join(""):undefined};e.b=function(a){for(var b=[],c;a.length;)if(a.match(D))a=a.replace(D,"");else if(a.match(E))a=a.replace(E,"/");else if(a.match(F)){a=a.replace(F,"/");b.pop()}else if(a==="."||a==="..")a="";else{c=a.match(Q)[0];a=a.slice(c.length);b.push(c)}return b.join("")};
e.serialize=function(a,b){var c=[],d,g;b=b||{};(d=e.a[(b.scheme||a.scheme||"").toLowerCase()])&&d.serialize&&d.serialize(a,b);if(b.reference!=="suffix"&&a.scheme){c.push(a.scheme.toString().toLowerCase().replace(J,""));c.push(":")}d=e.e(a);if(d!==undefined){b.reference!=="suffix"&&c.push("//");c.push(d);a.path&&a.path.charAt(0)!=="/"&&c.push("/")}if(a.path!==undefined){g=e.b(a.path.toString().replace(/%2E/ig,"."));g=a.scheme?g.replace(M,m):g.replace(N,m);if(d===undefined)g=g.replace(/^\/\//,"/%2F");
c.push(g)}if(a.query!==undefined){c.push("?");c.push(a.query.toString().replace(B,m))}if(a.fragment!==undefined){c.push("#");c.push(a.fragment.toString().replace(B,m))}return c.join("").replace(C,x).replace(/%[0-9A-Fa-f]{2}/g,function(w){return w.toUpperCase()})};e.d=function(a,b,c,d){var g=new k;if(!d){a=e.parse(e.serialize(a,c),c);b=e.parse(e.serialize(b,c),c)}c=c||{};if(!c.tolerant&&b.scheme){g.scheme=b.scheme;g.userinfo=b.userinfo;g.host=b.host;g.port=b.port;g.path=e.b(b.path);g.query=b.query}else{if(b.userinfo!==
undefined||b.host!==undefined||b.port!==undefined){g.userinfo=b.userinfo;g.host=b.host;g.port=b.port;g.path=e.b(b.path);g.query=b.query}else{if(b.path){if(b.path.charAt(0)==="/")g.path=e.b(b.path);else{g.path=(a.userinfo!==undefined||a.host!==undefined||a.port!==undefined)&&!a.path?"/"+b.path:a.path?a.path.slice(0,a.path.lastIndexOf("/")+1)+b.path:b.path;g.path=e.b(g.path)}g.query=b.query}else{g.path=a.path;g.query=b.query!==undefined?b.query:a.query}g.userinfo=a.userinfo;g.host=a.host;g.port=a.port}g.scheme=
a.scheme}g.fragment=b.fragment;return g};e.i=function(a,b,c){return e.serialize(e.d(e.parse(a,c),e.parse(b,c),c,true),c)};e.normalize=function(a,b){if(typeof a==="string")a=e.serialize(e.parse(a,b),b);else if(o(a)==="object")a=e.parse(e.serialize(a,b),b);return a};e.f=function(a,b,c){if(typeof a==="string")a=e.serialize(e.parse(a,c),c);else if(o(a)==="object")a=e.serialize(a,c);if(typeof b==="string")b=e.serialize(e.parse(b,c),c);else if(o(b)==="object")b=e.serialize(b,c);return a===b};e.g=function(a){return a&&
a.toString().replace(O,m)};e.j=function(a){return a&&a.toString().replace(C,v)};exports.h=m;exports.k=v;exports.Components=k;exports.c=e;exports.pctEncChar=m;exports.pctDecChars=v;exports.Components=k;exports.URI={SCHEMES:e.a,parse:e.parse,removeDotSegments:e.b,serialize:e.serialize,resolveComponents:e.d,resolve:e.i,normalize:e.normalize,equal:e.f,escapeComponent:e.g,unescapeComponent:e.j};require("./schemes");return e}();require("../uri").c.a.http={serialize:function(k){if(k.port===80||k.port==="")k.port=undefined;if(!k.path)k.path="/";return k}};(function(){var k=require("../uri"),o=k.c,v=k.h,x=/^urn\:((?:[0-9A-Za-z][0-9A-Za-z\-]{1,31}))$/,m=RegExp("^((?:[0-9A-Za-z][0-9A-Za-z\\-]{1,31}))\\:((?:(?:(?:\\%[0-9A-Fa-f]{2})|[0-9A-Za-z\\(\\)\\+\\,\\-\\.\\:\\=\\@\\;\\$\\_\\!\\*\\'\\/\\?\\#])+))$"),f=/^([^\:]+)\:(.*)/,j=/[\x00-\x20\\\"\&\<\>\[\]\^\`\{\|\}\~\x7F-\xFF]/g,l=/^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/;o.a.urn={parse:function(h,n){var i=h.path.match(m),p,q;if(!i){n.tolerant||h.errors.push("URN is not strictly valid.");i=
h.path.match(f)}if(i){p="urn:"+i[1].toLowerCase();(q=o.a[p])||(q=o.a[p]={});if(!q.serialize)q.serialize=o.a.urn.serialize;h.scheme=p;h.path=i[2];q.parse&&q.parse(h,n)}else h.errors.push("URN can not be parsed.");return h},serialize:function(h,n){var i=h.scheme||n.scheme,p;if(i&&i!=="urn"){(p=i.match(x))||(p=["urn:"+i,i]);h.scheme="urn";h.path=p[1]+":"+(h.path?h.path.replace(j,v):"")}return h}};o.a["urn:uuid"]={parse:function(h,n){if(!n.tolerant&&(!h.path||!h.path.match(l)))h.errors.push("UUID is not valid.")},
serialize:function(h,n){if(!n.tolerant&&(!h.path||!h.path.match(l)))h.scheme=undefined;else h.path=(h.path||"").toLowerCase();return o.a.urn.serialize(h,n)}}})();
New to GrepCode? Check out our FAQ X