Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding first version

  • Loading branch information...
commit 0ef400e2e1a478b6fb6df0a86f9251afb189caab 1 parent a2e255d
@addyosmani authored
Showing with 28 additions and 0 deletions.
  1. +28 −0 parsley.js
View
28 parsley.js
@@ -0,0 +1,28 @@
+/*
+* parsley - a comprehensive URL parser
+* author: Addy Osmani
+* notes: inspired by work from Steven Levithan
+* Copyright (c) 2011 Addy Osmani
+* Dual MIT/BSD license
+*/
+function parsely( strUrl ){
+ var uri = {},
+ keys = ["source","protocol","authDomain","authLogin","user","password","host","port","relative","path","dir","file","query","anchor"],
+ i = keys.length,
+ n = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,
+ m = n.exec(strUrl),
+ ext = ['path','dir','anchor'],
+ c = ext.length
+ k = /(?:^|&)([^&=]*)=?([^&]*)/g, //for params &= etc.
+ l = /(?:[^\/\\]+|\\.)+/g; //for dirs/paths
+
+ while (i--) uri[keys[i]] = m[i] || "";
+ uri['queries'] = {};
+ uri['query'].replace(k, function ($0, $1, $2) {
+ if ($1) uri['queries'][$1] = $2;
+ });
+
+ while(c--) uri[ext[c] + 's'] = uri[ext[c]].match(l) || "";
+
+ return uri;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.