Created
April 28, 2015 10:55
-
-
Save kopiro/1beb201a2c84486686a6 to your computer and use it in GitHub Desktop.
PrettyJSURL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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