Skip to content

Instantly share code, notes, and snippets.

@kopiro
Created April 28, 2015 10:55
Show Gist options
  • Save kopiro/1beb201a2c84486686a6 to your computer and use it in GitHub Desktop.
Save kopiro/1beb201a2c84486686a6 to your computer and use it in GitHub Desktop.
PrettyJSURL
var PrettyURL = {
parse: function(hash) {
hash = hash.replace('#', '');
if (_.isEmpty(hash) || hash[0] != '/') return null;
var obj = {};
_.each(hash.substr(1).split('/'), function(value) {
value = value.split(':', 2);
if (_.isEmpty(value[0])) return;
obj[value[0]] = value[1];
});
return obj;
},
stringify: function(obj) {
var hash = [];
_.each(obj, function(value, key) {
if (!_.isEmpty(value) && value != 0) {
hash.push( key + ':' + value );
}
});
return '/' + hash.join('/');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment