Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

js-url-1.7.6

  • Loading branch information...
commit 7ffe8d8c162257a5642e6fbd4cbcfdd84a37c0dc 1 parent ac50bac
@agourlay agourlay authored
View
80 ajax/libs/js-url/1.7.6/js-url.js
@@ -0,0 +1,80 @@
+/******************************************
+ * Websanova.com
+ *
+ * Resources for web entrepreneurs
+ *
+ * @author Websanova
+ * @copyright Copyright (c) 2012 Websanova.
+ * @license This websanova JavaScript url is dual licensed under the MIT and GPL licenses.
+ * @link http://www.websanova.com
+ * @github http://github.com/websanova/js-url
+ * @version 1.7.6
+ *
+ ******************************************/
+
+window.url = (function() {
+ function isNumeric(arg) {
+ return !isNaN(parseFloat(arg)) && isFinite(arg);
+ }
+
+ return function url(arg, url) {
+ var _ls = url || window.location.toString();
+
+ if(_ls.substring(0,2) === '//') _ls = 'http:' + _ls;
+ else if(_ls.split('://').length === 1) _ls = 'http://' + _ls;
+
+ url = _ls.split('/');
+ var _l = {auth:''}, host = url[2].split('@');
+
+ if(host.length === 1) host = host[0].split(':');
+ else{ _l.auth = host[0]; host = host[1].split(':'); }
+
+ _l.protocol=url[0], _l.hostname=host[0], _l.port=(host[1]||'80'), _l.pathname='/' + url.slice(3, url.length).join('/').split('?')[0].split('#')[0];
+ var _p = _l.pathname;
+ if(_p.split('.').length === 1 && _p[_p.length-1] !== '/') _p += '/';
+ var _h = _l.hostname, _hs = _h.split('.'), _ps = _p.split('/');
+
+ if(!arg) return _ls;
+ else if(arg === 'hostname') return _h;
+ else if(arg === 'domain') return _hs.slice(-2).join('.');
+ else if(arg === 'tld') return _hs.slice(-1).join('.');
+ else if(arg === 'sub') return _hs.slice(0, _hs.length - 2).join('.');
+ else if(arg === 'port') return _l.port || '80';
+ else if(arg === 'protocol') return _l.protocol.split(':')[0];
+ else if(arg === 'auth') return _l.auth;
+ else if(arg === 'user') return _l.auth.split(':')[0];
+ else if(arg === 'pass') return _l.auth.split(':')[1] || '';
+ else if(arg === 'path') return _p;
+ else if(arg[0] === '.')
+ {
+ arg = arg.substring(1);
+ if(isNumeric(arg)) {arg = parseInt(arg); return _hs[arg < 0 ? _hs.length + arg : arg-1] || ''; }
+ }
+ else if(isNumeric(arg)){ arg = parseInt(arg); return _ps[arg < 0 ? _ps.length - 1 + arg : arg] || ''; }
+ else if(arg === 'file') return _ps.slice(-1)[0];
+ else if(arg === 'filename') return _ps.slice(-1)[0].split('.')[0];
+ else if(arg === 'fileext') return _ps.slice(-1)[0].split('.')[1] || '';
+ else if(arg[0] === '?' || arg[0] === '#')
+ {
+ var params = _ls, param = null;
+
+ if(arg[0] === '?') params = (params.split('?')[1] || '').split('#')[0];
+ else if(arg[0] === '#') params = (params.split('#')[1] || '');
+
+ if(!arg[1]) return params;
+
+ arg = arg.substring(1);
+ params = params.split('&');
+
+ for(var i=0,ii=params.length; i<ii; i++)
+ {
+ param = params[i].split('=');
+ if(param[0] === arg) return param[1];
+ }
+
+ return null;
+ }
+
+ return '';
+ }
+})();
View
1  ajax/libs/js-url/1.7.6/js-url.min.js
@@ -0,0 +1 @@
+/* url() v1.7.6 - http://github.com/websanova/js-url */window.url=(function(){function b(c){return !isNaN(parseFloat(c))&&isFinite(c)}return function a(p,d){var c=d||window.location.toString();if(c.substring(0,2)==="//"){c="http:"+c}else{if(c.split("://").length===1){c="http://"+c}}d=c.split("/");var g={auth:""},o=d[2].split("@");if(o.length===1){o=o[0].split(":")}else{g.auth=o[0];o=o[1].split(":")}g.protocol=d[0],g.hostname=o[0],g.port=(o[1]||"80"),g.pathname="/"+d.slice(3,d.length).join("/").split("?")[0].split("#")[0];var e=g.pathname;if(e.split(".").length===1&&e[e.length-1]!=="/"){e+="/"}var k=g.hostname,l=k.split("."),m=e.split("/");if(!p){return c}else{if(p==="hostname"){return k}else{if(p==="domain"){return l.slice(-2).join(".")}else{if(p==="tld"){return l.slice(-1).join(".")}else{if(p==="sub"){return l.slice(0,l.length-2).join(".")}else{if(p==="port"){return g.port||"80"}else{if(p==="protocol"){return g.protocol.split(":")[0]}else{if(p==="auth"){return g.auth}else{if(p==="user"){return g.auth.split(":")[0]}else{if(p==="pass"){return g.auth.split(":")[1]||""}else{if(p==="path"){return e}else{if(p[0]==="."){p=p.substring(1);if(b(p)){p=parseInt(p);return l[p<0?l.length+p:p-1]||""}}else{if(b(p)){p=parseInt(p);return m[p<0?m.length-1+p:p]||""}else{if(p==="file"){return m.slice(-1)[0]}else{if(p==="filename"){return m.slice(-1)[0].split(".")[0]}else{if(p==="fileext"){return m.slice(-1)[0].split(".")[1]||""}else{if(p[0]==="?"||p[0]==="#"){var h=c,f=null;if(p[0]==="?"){h=(h.split("?")[1]||"").split("#")[0]}else{if(p[0]==="#"){h=(h.split("#")[1]||"")}}if(!p[1]){return h}p=p.substring(1);h=h.split("&");for(var j=0,n=h.length;j<n;j++){f=h[j].split("=");if(f[0]===p){return f[1]}}return null}}}}}}}}}}}}}}}}}return""}})();
View
2  ajax/libs/js-url/package.json
@@ -1,7 +1,7 @@
{
"name": "js-url",
"filename": "js-url.min.js",
- "version": "1.7.5",
+ "version": "1.7.6",
"description": "A simple, lightweight url parser for JavaScript",
"homepage": "https://github.com/websanova/js-url",
"keywords": [
Please sign in to comment.
Something went wrong with that request. Please try again.