uri-js
Advanced tools
Comparing version 1.4.2 to 2.0.0
/* | ||
URI.js v1.4.2 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js | ||
URI.js v2.0.0 (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)}}})(); | ||
var URI=function(){function f(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];if(1<a.length){a[0]=a[0].slice(0,-1);for(var b=a.length-1,d=1;d<b;++d)a[d]=a[d].slice(1,-1);a[b]=a[b].slice(1);return a.join("")}return a[0]}function k(a){a=a.charCodeAt(0);var b;16>a?b="%0"+a.toString(16).toUpperCase():128>a?b="%"+a.toString(16).toUpperCase():b=2048>a?"%"+(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();return b}function p(a){for(var b="",d=0,e=a.length,c,f,g;d<e;)c=parseInt(a.substr(d+1,2),16),128>c?(b+=String.fromCharCode(c),d+=3):194<=c&&224>c?(6<=e-d?(f=parseInt(a.substr(d+4,2),16),b+=String.fromCharCode((c&31)<<6|f&63)):b+=a.substr(d,6),d+=6):224<=c?(9<=e-d?(f=parseInt(a.substr(d+4,2),16),g=parseInt(a.substr(d+7,2),16),b+=String.fromCharCode((c&15)<<12|(f&63)<<6|g&63)):b+=a.substr(d,9),d+=9):(b+=a.substr(d,3),d+=3);return b} | ||
function q(a){return void 0===a?"undefined":null===a?"null":Object.prototype.toString.call(a).split(" ").pop().split("]").shift().toLowerCase()}function m(a){return a.toUpperCase()}function t(a,b){function d(a){var c=p(a);return c.match(b.m)?c:a}a.scheme&&(a.scheme=String(a.scheme).replace(b.a,d).toLowerCase().replace(b.j,""));void 0!==a.userinfo&&(a.userinfo=String(a.userinfo).replace(b.a,d).replace(b.l,k).replace(/%[0-9A-Fa-f]{2}/g,m));void 0!==a.host&&(a.host=String(a.host).replace(b.a,d).toLowerCase().replace(b.f, | ||
k).replace(/%[0-9A-Fa-f]{2}/g,m));void 0!==a.path&&(a.path=String(a.path).replace(b.a,d).replace(a.scheme?b.g:b.h,k).replace(/%[0-9A-Fa-f]{2}/g,m));void 0!==a.query&&(a.query=String(a.query).replace(b.a,d).replace(b.i,k).replace(/%[0-9A-Fa-f]{2}/g,m));void 0!==a.fragment&&(a.fragment=String(a.fragment).replace(b.a,d).replace(b.c,k).replace(/%[0-9A-Fa-f]{2}/g,m))}function h(a,b){void 0===b&&(b={});var d=n,e,c={};"suffix"===b.reference&&(a=(b.scheme?b.scheme+":":"")+"//"+a);(e=a.match(z))?(A?(c.scheme= | ||
e[1],c.userinfo=e[3],c.host=e[4],c.port=parseInt(e[5],10),c.path=e[6]||"",c.query=e[7],c.fragment=e[8],isNaN(c.port)&&(c.port=e[5])):(c.scheme=e[1]||void 0,c.userinfo=-1!==a.indexOf("@")?e[3]:void 0,c.host=-1!==a.indexOf("//")?e[4]:void 0,c.port=parseInt(e[5],10),c.path=e[6]||"",c.query=-1!==a.indexOf("?")?e[7]:void 0,c.fragment=-1!==a.indexOf("#")?e[8]:void 0,isNaN(c.port)&&(c.port=a.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?e[4]:void 0)),c.reference=void 0===c.scheme&&void 0===c.userinfo&&void 0=== | ||
c.host&&void 0===c.port&&void 0===c.path&&void 0===c.query?"same-document":void 0===c.scheme?"relative":void 0===c.fragment?"absolute":"uri",b.reference&&"suffix"!==b.reference&&b.reference!==c.reference&&(c.error=c.error||"URI is not a "+b.reference+" reference."),e=r[(b.scheme||c.scheme||"").toLowerCase()],t(c,d),e&&e.parse&&e.parse(c,b)):c.error=c.error||"URI can not be parsed.";return c}function u(a){var b=[];void 0!==a.userinfo&&(b.push(a.userinfo),b.push("@"));void 0!==a.host&&b.push(a.host); | ||
"number"===typeof a.port&&(b.push(":"),b.push(a.port.toString(10)));return b.length?b.join(""):void 0}function l(a){for(var b=[],d;a.length;)a.match(v)?a=a.replace(v,""):a.match(w)?a=a.replace(w,"/"):a.match(x)?(a=a.replace(x,"/"),b.pop()):"."===a||".."===a?a="":(d=a.match(B)[0],a=a.slice(d.length),b.push(d));return b.join("")}function g(a,b){void 0===b&&(b={});var d=n,e=[],c,f;(c=r[(b.scheme||a.scheme||"").toLowerCase()])&&c.serialize&&c.serialize(a,b);t(a,d);"suffix"!==b.reference&&a.scheme&&(e.push(a.scheme), | ||
e.push(":"));d=u(a);void 0!==d&&("suffix"!==b.reference&&e.push("//"),e.push(d),a.path&&"/"!==a.path.charAt(0)&&e.push("/"));void 0!==a.path&&(f=a.path,b.absolutePath||c&&c.absolutePath||(f=l(f)),void 0===d&&(f=f.replace(/^\/\//,"/%2F")),e.push(f));void 0!==a.query&&(e.push("?"),e.push(a.query));void 0!==a.fragment&&(e.push("#"),e.push(a.fragment));return e.join("")}function y(a,b,d,e){void 0===d&&(d={});var c={};e||(a=h(g(a,d),d),b=h(g(b,d),d));d=d||{};!d.tolerant&&b.scheme?(c.scheme=b.scheme,c.userinfo= | ||
b.userinfo,c.host=b.host,c.port=b.port,c.path=l(b.path),c.query=b.query):(void 0!==b.userinfo||void 0!==b.host||void 0!==b.port?(c.userinfo=b.userinfo,c.host=b.host,c.port=b.port,c.path=l(b.path),c.query=b.query):(b.path?("/"===b.path.charAt(0)?c.path=l(b.path):(void 0===a.userinfo&&void 0===a.host&&void 0===a.port||a.path?a.path?c.path=a.path.slice(0,a.path.lastIndexOf("/")+1)+b.path:c.path=b.path:c.path="/"+b.path,c.path=l(c.path)),c.query=b.query):(c.path=a.path,c.query=void 0!==b.query?b.query: | ||
a.query),c.userinfo=a.userinfo,c.host=a.host,c.port=a.port),c.scheme=a.scheme);c.fragment=b.fragment;return c}var n=function(a){var b=f("[0-9]","[A-Fa-f]"),d=f("[A-Za-z]","[0-9]","[\\-\\.\\_\\~]",a?"[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]":"[]");return{s:!1,j:new RegExp(f("[^]","[A-Za-z]","[0-9]","[\\+\\-\\.]"),"g"),l:new RegExp(f("[^\\%\\:]",d,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]"),"g"),f:new RegExp(f("[^\\%]",d,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]"),"g"),g:new RegExp(f("[^\\%\\/\\:\\@]", | ||
d,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]"),"g"),h:new RegExp(f("[^\\%\\/\\@]",d,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]"),"g"),i:new RegExp(f("[^\\%]",d,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]","[\\:\\@\\/\\?]",a?"[\\uE000-\\uF8FF]":"[]"),"g"),c:new RegExp(f("[^\\%]",d,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]","[\\:\\@\\/\\?]"),"g"),b:new RegExp(f("[^]",d,"[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]"),"g"),m:new RegExp(d,"g"),o:new RegExp(f("[^\\%]",d,f("[\\:\\/\\?\\#\\[\\]\\@]","[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]")), | ||
"g"),a:new RegExp("(?:"+("(?:"+("%[EFef]"+b+"%"+b+b+"%"+b+b)+")|"+("(?:"+("%[89A-Fa-f]"+b+"%"+b+b)+")")+"|"+("(?:"+("%"+b+b)+")"))+")","g")}}(!1),z=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?([^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n)*))?/i,v=/^\.\.?\//,w=/^\/\.(\/|$)/,x=/^\/\.\.(\/|$)/,B=/^\/?(?:.|\n)*?(?=\/|$)/,A=void 0==="".match(/(){0}/)[1],r={};return{IRI_SUPPORT:!1,VALIDATE_SUPPORT:!1,pctEncChar:k,pctDecChars:p,SCHEMES:r,parse:h,_recomposeAuthority:u,removeDotSegments:l,serialize:g, | ||
resolveComponents:y,resolve:function(a,b,d){return g(y(h(a,d),h(b,d),d,!0),d)},normalize:function(a,b){"string"===typeof a?a=g(h(a,b),b):"object"===q(a)&&(a=h(g(a,b),b));return a},equal:function(a,b,d){"string"===typeof a?a=g(h(a,d),d):"object"===q(a)&&(a=g(a,d));"string"===typeof b?b=g(h(b,d),d):"object"===q(b)&&(b=g(b,d));return a===b},escapeComponent:function(a){return a&&a.toString().replace(n.b,k)},unescapeComponent:function(a){return a&&a.toString().replace(n.a,p)}}}();URI.SCHEMES.http=URI.SCHEMES.https={domainHost:!0,parse:function(f){f.host||(f.error=f.error||"HTTP URIs must have a host.");return f},serialize:function(f){if(f.port===("https"!==String(f.scheme).toLowerCase()?80:443)||""===f.port)f.port=void 0;f.path||(f.path="/");return f}}; |
@@ -1,5 +0,1 @@ | ||
//CommonJS module proxy; see src/uri.js for implementation | ||
var URI = require("./src/uri"); | ||
for (var key in URI) { | ||
exports[key] = URI[key]; | ||
} | ||
module.exports = require("./build/uri"); |
{ | ||
"name" : "uri-js", | ||
"version" : "1.4.2", | ||
"description" : "An RFC 3986 compliant, scheme extendable URI parsing/validating/resolving library for JavaScript.", | ||
"homepage" : "http://github.com/garycourt/uri-js", | ||
"author" : "Gary Court <gary.court@gmail.com>", | ||
"main" : "./src/uri.js" | ||
} | ||
"name": "uri-js", | ||
"version": "2.0.0", | ||
"description": "An RFC 3986/3987 compliant, scheme extendable URI/IRI parsing/validating/resolving library for JavaScript.", | ||
"main": "build/uri.js", | ||
"directories": { | ||
"test": "tests" | ||
}, | ||
"scripts": { | ||
"setup": "grunt setup", | ||
"build": "grunt", | ||
"test": "node_modules/.bin/mocha -u mocha-qunit-ui build/uri.js tests/tests.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/garycourt/uri-js" | ||
}, | ||
"keywords": [ | ||
"URI", | ||
"IRI", | ||
"IDN", | ||
"URN", | ||
"RFC3986", | ||
"RFC3987", | ||
"RFC5891", | ||
"RFC2616", | ||
"RFC2818", | ||
"RFC2141", | ||
"RFC4122" | ||
], | ||
"author": "Gary Court <gary.court@gmail.com>", | ||
"license": "BSD", | ||
"bugs": { | ||
"url": "https://github.com/garycourt/uri-js/issues" | ||
}, | ||
"homepage": "https://github.com/garycourt/uri-js", | ||
"devDependencies": { | ||
"api-closure-compiler": "^1.0.5", | ||
"grunt": "^0.4.5", | ||
"grunt-closure-compiler-build": "^1.0.1", | ||
"grunt-contrib-copy": "^0.8.0", | ||
"grunt-typescript": "^0.6.2", | ||
"mocha": "^2.2.5", | ||
"mocha-qunit-ui": "^0.1.2" | ||
} | ||
} |
# URI.js | ||
URI.js is an [RFC 3986](http://www.ietf.org/rfc/rfc3986.txt) compliant, scheme extendable URI parsing/validating/resolving library for all JavaScript environments (browsers, Node.js, etc). | ||
It is also compliant with the IRI ([RFC 3987](http://www.ietf.org/rfc/rfc3987.txt)) and IDNA ([RFC 5890](http://www.ietf.org/rfc/rfc5890.txt)) specifications. | ||
## Loading | ||
URI.js weighs in at only 2.3kb (gzipped, 7kb deflated). Need IRI support? It's only an extra 1.3kb (3.6kb gzipped, 9.8kb deflated). | ||
To load in a browser, use the following tag: | ||
<script type="text/javascript" src="uri-js/dist/uri.min.js"></script> | ||
To load in a CommonJS (Node.js) environment, simply use: | ||
var URI = require("./uri-js"); | ||
## API | ||
@@ -22,3 +15,2 @@ | ||
//{ | ||
// errors : [], | ||
// scheme : "uri", | ||
@@ -43,3 +35,3 @@ // userinfo : "user:pass", | ||
URI.normalize("HTTP://ABC.com/%7Esmith/home.html") === "http://abc.com/~smith/home.html" | ||
URI.normalize("HTTP://ABC.com:80/%7Esmith/home.html") === "http://abc.com/~smith/home.html" | ||
@@ -50,2 +42,9 @@ ### Comparison | ||
### IRI Support | ||
//convert IRI to URI | ||
URI.serialize(URI.parse("http://exampl�.org/ros�")) === "http://xn--exampl-gva.org/ros%C3%A9" | ||
//convert URI to IRI | ||
URI.serialize(URI.parse("http://xn--exampl-gva.org/ros%C3%A9"), {iri:true}) === "http://exampl�.org/ros�" | ||
### Options | ||
@@ -55,14 +54,30 @@ | ||
* `scheme` | ||
* `scheme` (string) | ||
Indicates the scheme that the URI should be treated as, overriding the URI's normal scheme parsing behavior. | ||
* `reference` | ||
* `reference` (string) | ||
If set to `"suffix"`, it indicates that the URI is in the suffix format, and the validator will use the option's `scheme` property to determine the URI's scheme. | ||
* `tolerant` | ||
* `tolerant` (boolean, false) | ||
If set to `true`, the parser will not report invalid URIs. It will also relax URI resolving rules. | ||
* `absolutePath` (boolean, false) | ||
If set to `true`, the serializer will not resolve a relative `path` component. | ||
* `iri` (boolean, false) | ||
If set to `true`, the serializer will unescape non-ASCII characters as per [RFC 3987](http://www.ietf.org/rfc/rfc3987.txt). | ||
* `unicodeSupport` (boolean, false) | ||
If set to `true`, the parser will unescape non-ASCII characters in the parsed output as per [RFC 3987](http://www.ietf.org/rfc/rfc3987.txt). | ||
* `domainHost` (boolean, false) | ||
If set to `true`, the library will treat the `host` component as a domain name, and convert IDNs (International Domain Names) as per [RFC 5891](http://www.ietf.org/rfc/rfc5891.txt). | ||
## Scheme Extendable | ||
@@ -90,5 +105,30 @@ | ||
* http \[[RFC 2616](http://www.ietf.org/rfc/rfc2616.txt)\] | ||
* https \[[RFC 2818](http://www.ietf.org/rfc/rfc2818.txt)\] | ||
* urn \[[RFC 2141](http://www.ietf.org/rfc/rfc2141.txt)\] | ||
* urn:uuid \[[RFC 4122](http://www.ietf.org/rfc/rfc4122.txt)\] | ||
Note: The minified version of URI.js only comes with http/https support compiled in. | ||
## Usage | ||
To load in a browser, use the following tag: | ||
<script type="text/javascript" src="uri-js/dist/uri.min.js"></script> | ||
If you need IRI support, use the following tag instead: | ||
<script type="text/javascript" src="uri-js/dist/uri-iri.min.js"></script> | ||
To load in a CommonJS (Node.js/io.js) environment, first install with npm by running on the command line: | ||
npm install uri-js | ||
Then, in your code, load it using: | ||
var URI = require("uri-js"); | ||
## Breaking changes from 1.x | ||
The `errors` array on parsed components as now been changed to an `error` string. | ||
## License | ||
@@ -95,0 +135,0 @@ |
@@ -0,0 +0,0 @@ /* |
@@ -8,3 +8,3 @@ // | ||
test("Acquire URI", function () { | ||
URI = require("./uri").URI; | ||
//URI = require("./uri").URI; | ||
ok(URI); | ||
@@ -18,3 +18,3 @@ }); | ||
components = URI.parse("uri:"); | ||
strictEqual(components.errors.length, 0, "scheme errors"); | ||
strictEqual(components.error, undefined, "scheme errors"); | ||
strictEqual(components.scheme, "uri", "scheme"); | ||
@@ -31,3 +31,3 @@ //strictEqual(components.authority, undefined, "authority"); | ||
components = URI.parse("//@"); | ||
strictEqual(components.errors.length, 0, "userinfo errors"); | ||
strictEqual(components.error, undefined, "userinfo errors"); | ||
strictEqual(components.scheme, undefined, "scheme"); | ||
@@ -44,3 +44,3 @@ //strictEqual(components.authority, "@", "authority"); | ||
components = URI.parse("//"); | ||
strictEqual(components.errors.length, 0, "host errors"); | ||
strictEqual(components.error, undefined, "host errors"); | ||
strictEqual(components.scheme, undefined, "scheme"); | ||
@@ -57,3 +57,3 @@ //strictEqual(components.authority, "", "authority"); | ||
components = URI.parse("//:"); | ||
strictEqual(components.errors.length, 0, "port errors"); | ||
strictEqual(components.error, undefined, "port errors"); | ||
strictEqual(components.scheme, undefined, "scheme"); | ||
@@ -70,3 +70,3 @@ //strictEqual(components.authority, ":", "authority"); | ||
components = URI.parse(""); | ||
strictEqual(components.errors.length, 0, "path errors"); | ||
strictEqual(components.error, undefined, "path errors"); | ||
strictEqual(components.scheme, undefined, "scheme"); | ||
@@ -83,3 +83,3 @@ //strictEqual(components.authority, undefined, "authority"); | ||
components = URI.parse("?"); | ||
strictEqual(components.errors.length, 0, "query errors"); | ||
strictEqual(components.error, undefined, "query errors"); | ||
strictEqual(components.scheme, undefined, "scheme"); | ||
@@ -96,3 +96,3 @@ //strictEqual(components.authority, undefined, "authority"); | ||
components = URI.parse("#"); | ||
strictEqual(components.errors.length, 0, "fragment errors"); | ||
strictEqual(components.error, undefined, "fragment errors"); | ||
strictEqual(components.scheme, undefined, "scheme"); | ||
@@ -109,3 +109,3 @@ //strictEqual(components.authority, undefined, "authority"); | ||
components = URI.parse("uri://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body"); | ||
strictEqual(components.errors.length, 0, "all errors"); | ||
strictEqual(components.error, undefined, "all errors"); | ||
strictEqual(components.scheme, "uri", "scheme"); | ||
@@ -119,2 +119,24 @@ //strictEqual(components.authority, "user:pass@example.com:123", "authority"); | ||
strictEqual(components.fragment, "body", "fragment"); | ||
//IPv4address | ||
components = URI.parse("//10.10.10.10/test"); | ||
strictEqual(components.error, undefined, "IPv4address errors"); | ||
strictEqual(components.scheme, undefined, "scheme"); | ||
strictEqual(components.userinfo, undefined, "userinfo"); | ||
strictEqual(components.host, "10.10.10.10", "host"); | ||
strictEqual(components.port, undefined, "port"); | ||
strictEqual(components.path, "/test", "path"); | ||
strictEqual(components.query, undefined, "query"); | ||
strictEqual(components.fragment, undefined, "fragment"); | ||
//mixed IPv4address & reg-name, example from terion-name (https://github.com/garycourt/uri-js/issues/4) | ||
components = URI.parse("uri://10.10.10.10.example.com/en/process"); | ||
strictEqual(components.error, undefined, "mixed errors"); | ||
strictEqual(components.scheme, "uri", "scheme"); | ||
strictEqual(components.userinfo, undefined, "userinfo"); | ||
strictEqual(components.host, "10.10.10.10.example.com", "host"); | ||
strictEqual(components.port, undefined, "port"); | ||
strictEqual(components.path, "/en/process", "path"); | ||
strictEqual(components.query, undefined, "query"); | ||
strictEqual(components.fragment, undefined, "fragment"); | ||
}); | ||
@@ -155,2 +177,6 @@ | ||
strictEqual(URI.serialize(components), "uri://foo:bar@example.com:1/path?query#fragment", "All Components"); | ||
strictEqual(URI.serialize({path:"//path"}), "/%2Fpath", "Double slash path"); | ||
strictEqual(URI.serialize({path:"foo:bar"}), "foo%3Abar", "Colon path"); | ||
strictEqual(URI.serialize({path:"?query"}), "%3Fquery", "Query path"); | ||
}); | ||
@@ -217,5 +243,13 @@ | ||
test("URI Normalizing", function () { | ||
//test from RFC 3987 | ||
strictEqual(URI.normalize("uri://www.example.org/red%09ros\xE9#red"), "uri://www.example.org/red%09ros%C3%A9#red"); | ||
}); | ||
test("URI Equals", function () { | ||
//test from RFC 3986 | ||
strictEqual(URI.equal("example://a/b/c/%7Bfoo%7D", "eXAMPLE://a/./b/../b/%63/%7bfoo%7d"), true); | ||
//test from RFC 3987 | ||
strictEqual(URI.equal("http://example.org/~user", "http://example.org/%7euser"), true); | ||
}); | ||
@@ -225,3 +259,3 @@ | ||
var chr; | ||
for (var d = 0; d <= 128; ++d) { | ||
for (var d = 0; d <= 129; ++d) { | ||
chr = String.fromCharCode(d); | ||
@@ -235,2 +269,4 @@ if (!chr.match(/[\$\&\+\,\;\=]/)) { | ||
strictEqual(URI.escapeComponent("\u00c0"), encodeURIComponent("\u00c0")); | ||
strictEqual(URI.escapeComponent("\u07ff"), encodeURIComponent("\u07ff")); | ||
strictEqual(URI.escapeComponent("\u0800"), encodeURIComponent("\u0800")); | ||
strictEqual(URI.escapeComponent("\u30a2"), encodeURIComponent("\u30a2")); | ||
@@ -241,3 +277,3 @@ }); | ||
var chr; | ||
for (var d = 0; d <= 128; ++d) { | ||
for (var d = 0; d <= 129; ++d) { | ||
chr = String.fromCharCode(d); | ||
@@ -247,2 +283,4 @@ strictEqual(URI.unescapeComponent(encodeURIComponent(chr)), chr); | ||
strictEqual(URI.unescapeComponent(encodeURIComponent("\u00c0")), "\u00c0"); | ||
strictEqual(URI.unescapeComponent(encodeURIComponent("\u07ff")), "\u07ff"); | ||
strictEqual(URI.unescapeComponent(encodeURIComponent("\u0800")), "\u0800"); | ||
strictEqual(URI.unescapeComponent(encodeURIComponent("\u30a2")), "\u30a2"); | ||
@@ -252,87 +290,169 @@ }); | ||
// | ||
// HTTP | ||
// IRI | ||
// | ||
module("HTTP"); | ||
if (URI.IRI_SUPPORT) { | ||
test("HTTP Equals", function () { | ||
//test from RFC 2616 | ||
strictEqual(URI.equal("http://abc.com:80/~smith/home.html", "http://abc.com/~smith/home.html"), true); | ||
strictEqual(URI.equal("http://ABC.com/%7Esmith/home.html", "http://abc.com/~smith/home.html"), true); | ||
strictEqual(URI.equal("http://ABC.com:/%7esmith/home.html", "http://abc.com/~smith/home.html"), true); | ||
strictEqual(URI.equal("HTTP://ABC.COM", "http://abc.com/"), true); | ||
//test from RFC 3986 | ||
strictEqual(URI.equal("http://example.com:/", "http://example.com:80/"), true); | ||
}); | ||
var IRI_OPTION = { iri : true, unicodeSupport : true }; | ||
test("IRI Parsing", function () { | ||
var components = URI.parse("uri://us\xA0er:pa\uD7FFss@example.com:123/o\uF900ne/t\uFDCFwo.t\uFDF0hree?q1=a1\uF8FF\uE000&q2=a2#bo\uFFEFdy", IRI_OPTION); | ||
strictEqual(components.error, undefined, "all errors"); | ||
strictEqual(components.scheme, "uri", "scheme"); | ||
//strictEqual(components.authority, "us\xA0er:pa\uD7FFss@example.com:123", "authority"); | ||
strictEqual(components.userinfo, "us\xA0er:pa\uD7FFss", "userinfo"); | ||
strictEqual(components.host, "example.com", "host"); | ||
strictEqual(components.port, 123, "port"); | ||
strictEqual(components.path, "/o\uF900ne/t\uFDCFwo.t\uFDF0hree", "path"); | ||
strictEqual(components.query, "q1=a1\uF8FF\uE000&q2=a2", "query"); | ||
strictEqual(components.fragment, "bo\uFFEFdy", "fragment"); | ||
}); | ||
test("IRI Serialization", function () { | ||
var components = { | ||
scheme : "uri", | ||
userinfo : "us\xA0er:pa\uD7FFss", | ||
host : "example.com", | ||
port : 123, | ||
path : "/o\uF900ne/t\uFDCFwo.t\uFDF0hree", | ||
query : "q1=a1\uF8FF\uE000&q2=a2", | ||
fragment : "bo\uFFEFdy\uE001" | ||
}; | ||
strictEqual(URI.serialize(components, IRI_OPTION), "uri://us\xA0er:pa\uD7FFss@example.com:123/o\uF900ne/t\uFDCFwo.t\uFDF0hree?q1=a1\uF8FF\uE000&q2=a2#bo\uFFEFdy%EE%80%81"); | ||
}); | ||
test("IRI Normalizing", function () { | ||
strictEqual(URI.normalize("uri://www.example.org/red%09ros\xE9#red", IRI_OPTION), "uri://www.example.org/red%09ros\xE9#red"); | ||
}); | ||
test("IRI Equals", function () { | ||
//example from RFC 3987 | ||
strictEqual(URI.equal("example://a/b/c/%7Bfoo%7D/ros\xE9", "eXAMPLE://a/./b/../b/%63/%7bfoo%7d/ros%C3%A9", IRI_OPTION), true); | ||
}); | ||
test("Convert IRI to URI", function () { | ||
//example from RFC 3987 | ||
strictEqual(URI.serialize(URI.parse("uri://www.example.org/red%09ros\xE9#red", IRI_OPTION)), "uri://www.example.org/red%09ros%C3%A9#red"); | ||
//Internationalized Domain Name conversion via punycode example from RFC 3987 | ||
strictEqual(URI.serialize(URI.parse("uri://r\xE9sum\xE9.example.org", {iri:true, domainHost:true}), {domainHost:true}), "uri://xn--rsum-bpad.example.org"); | ||
}); | ||
test("Convert URI to IRI", function () { | ||
//examples from RFC 3987 | ||
strictEqual(URI.serialize(URI.parse("uri://www.example.org/D%C3%BCrst"), IRI_OPTION), "uri://www.example.org/D\xFCrst"); | ||
strictEqual(URI.serialize(URI.parse("uri://www.example.org/D%FCrst"), IRI_OPTION), "uri://www.example.org/D%FCrst"); | ||
strictEqual(URI.serialize(URI.parse("uri://xn--99zt52a.example.org/%e2%80%ae"), IRI_OPTION), "uri://xn--99zt52a.example.org/%E2%80%AE"); //or uri://\u7D0D\u8C46.example.org/%E2%80%AE | ||
//Internationalized Domain Name conversion via punycode example from RFC 3987 | ||
strictEqual(URI.serialize(URI.parse("uri://xn--rsum-bpad.example.org", {domainHost:true}), {iri:true, domainHost:true}), "uri://r\xE9sum\xE9.example.org"); | ||
}); | ||
} | ||
// | ||
// URN | ||
// HTTP | ||
// | ||
module("URN"); | ||
if (URI.SCHEMES["http"]) { | ||
test("URN Parsing", function () { | ||
//example from RFC 2141 | ||
var components = URI.parse("urn:foo:a123,456"); | ||
strictEqual(components.errors.length, 0, "errors"); | ||
strictEqual(components.scheme, "urn:foo", "scheme"); | ||
//strictEqual(components.authority, undefined, "authority"); | ||
strictEqual(components.userinfo, undefined, "userinfo"); | ||
strictEqual(components.host, undefined, "host"); | ||
strictEqual(components.port, undefined, "port"); | ||
strictEqual(components.path, "a123,456", "path"); | ||
strictEqual(components.query, undefined, "query"); | ||
strictEqual(components.fragment, undefined, "fragment"); | ||
}); | ||
//module("HTTP"); | ||
test("URN Serialization", function () { | ||
//example from RFC 2141 | ||
var components = { | ||
scheme : "urn:foo", | ||
path : "a123,456" | ||
}; | ||
strictEqual(URI.serialize(components), "urn:foo:a123,456"); | ||
}); | ||
test("HTTP Equals", function () { | ||
//test from RFC 2616 | ||
strictEqual(URI.equal("http://abc.com:80/~smith/home.html", "http://abc.com/~smith/home.html"), true); | ||
strictEqual(URI.equal("http://ABC.com/%7Esmith/home.html", "http://abc.com/~smith/home.html"), true); | ||
strictEqual(URI.equal("http://ABC.com:/%7esmith/home.html", "http://abc.com/~smith/home.html"), true); | ||
strictEqual(URI.equal("HTTP://ABC.COM", "http://abc.com/"), true); | ||
//test from RFC 3986 | ||
strictEqual(URI.equal("http://example.com:/", "http://example.com:80/"), true); | ||
}); | ||
test("URN Equals", function () { | ||
//test from RFC 2141 | ||
strictEqual(URI.equal("urn:foo:a123,456", "urn:foo:a123,456"), true); | ||
strictEqual(URI.equal("urn:foo:a123,456", "URN:foo:a123,456"), true); | ||
strictEqual(URI.equal("urn:foo:a123,456", "urn:FOO:a123,456"), true); | ||
strictEqual(URI.equal("urn:foo:a123,456", "urn:foo:A123,456"), false); | ||
strictEqual(URI.equal("urn:foo:a123%2C456", "URN:FOO:a123%2c456"), true); | ||
}); | ||
} | ||
if (URI.SCHEMES["https"]) { | ||
//module("HTTPS"); | ||
test("HTTPS Equals", function () { | ||
strictEqual(URI.equal("https://example.com", "https://example.com:443/"), true); | ||
strictEqual(URI.equal("https://example.com:/", "https://example.com:443/"), true); | ||
}); | ||
} | ||
// | ||
// URN UUID | ||
// URN | ||
// | ||
test("UUID Parsing", function () { | ||
//example from RFC 4122 | ||
var components = URI.parse("urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6"); | ||
strictEqual(components.errors.length, 0, "errors"); | ||
strictEqual(components.scheme, "urn:uuid", "scheme"); | ||
strictEqual(components.path, "f81d4fae-7dec-11d0-a765-00a0c91e6bf6", "path"); | ||
components = URI.parse("urn:uuid:notauuid-7dec-11d0-a765-00a0c91e6bf6"); | ||
notStrictEqual(components.errors.length, 0, "errors"); | ||
}); | ||
if (URI.SCHEMES["urn"]) { | ||
test("UUID Serialization", function () { | ||
//example from RFC 4122 | ||
var components = { | ||
scheme : "urn:uuid", | ||
path : "f81d4fae-7dec-11d0-a765-00a0c91e6bf6" | ||
}; | ||
strictEqual(URI.serialize(components), "urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6"); | ||
components = { | ||
scheme : "urn:uuid", | ||
path : "notauuid-7dec-11d0-a765-00a0c91e6bf6" | ||
}; | ||
strictEqual(URI.serialize(components), "notauuid-7dec-11d0-a765-00a0c91e6bf6"); | ||
}); | ||
//module("URN"); | ||
test("UUID Equals", function () { | ||
strictEqual(URI.equal("URN:UUID:F81D4FAE-7DEC-11D0-A765-00A0C91E6BF6", "urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6"), true); | ||
}); | ||
test("URN Parsing", function () { | ||
//example from RFC 2141 | ||
var components = URI.parse("urn:foo:a123,456"); | ||
strictEqual(components.error, undefined, "errors"); | ||
strictEqual(components.scheme, "urn:foo", "scheme"); | ||
//strictEqual(components.authority, undefined, "authority"); | ||
strictEqual(components.userinfo, undefined, "userinfo"); | ||
strictEqual(components.host, undefined, "host"); | ||
strictEqual(components.port, undefined, "port"); | ||
strictEqual(components.path, "a123,456", "path"); | ||
strictEqual(components.query, undefined, "query"); | ||
strictEqual(components.fragment, undefined, "fragment"); | ||
}); | ||
test("URN Serialization", function () { | ||
//example from RFC 2141 | ||
var components = { | ||
scheme : "urn:foo", | ||
path : "a123,456" | ||
}; | ||
strictEqual(URI.serialize(components), "urn:foo:a123,456"); | ||
}); | ||
test("URN Equals", function () { | ||
//test from RFC 2141 | ||
strictEqual(URI.equal("urn:foo:a123,456", "urn:foo:a123,456"), true); | ||
strictEqual(URI.equal("urn:foo:a123,456", "URN:foo:a123,456"), true); | ||
strictEqual(URI.equal("urn:foo:a123,456", "urn:FOO:a123,456"), true); | ||
strictEqual(URI.equal("urn:foo:a123,456", "urn:foo:A123,456"), false); | ||
strictEqual(URI.equal("urn:foo:a123%2C456", "URN:FOO:a123%2c456"), true); | ||
}); | ||
// | ||
// URN UUID | ||
// | ||
test("UUID Parsing", function () { | ||
//example from RFC 4122 | ||
var components = URI.parse("urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6"); | ||
strictEqual(components.error, undefined, "errors"); | ||
strictEqual(components.scheme, "urn:uuid", "scheme"); | ||
strictEqual(components.path, "f81d4fae-7dec-11d0-a765-00a0c91e6bf6", "path"); | ||
components = URI.parse("urn:uuid:notauuid-7dec-11d0-a765-00a0c91e6bf6"); | ||
notStrictEqual(components.error, undefined, "errors"); | ||
}); | ||
test("UUID Serialization", function () { | ||
//example from RFC 4122 | ||
var components = { | ||
scheme : "urn:uuid", | ||
path : "f81d4fae-7dec-11d0-a765-00a0c91e6bf6" | ||
}; | ||
strictEqual(URI.serialize(components), "urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6"); | ||
components = { | ||
scheme : "urn:uuid", | ||
path : "notauuid-7dec-11d0-a765-00a0c91e6bf6" | ||
}; | ||
strictEqual(URI.serialize(components), "notauuid-7dec-11d0-a765-00a0c91e6bf6"); | ||
}); | ||
test("UUID Equals", function () { | ||
strictEqual(URI.equal("URN:UUID:F81D4FAE-7DEC-11D0-A765-00A0C91E6BF6", "urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6"), true); | ||
}); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
27
3830
0
1
141
0
171710
7
1
1