Skip to content

Instantly share code, notes, and snippets.

@devinrhode2
Created March 22, 2014 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devinrhode2/9708720 to your computer and use it in GitHub Desktop.
Save devinrhode2/9708720 to your computer and use it in GitHub Desktop.
fe fi fo fum fam for the shenanigans
<script src="lodash.custom.min.js"></script>
<script type="text/javascript">
/*
Example:
_({key: value}).join('=', ';') === 'key=value;'
*/
(function(){
var oldJoin = _.prototype.join;
_.prototype.join = function (colon, comma) {
if ( comma ) {
var result = '';
_(this).forOwn(function(key, value) {
result += key + colon + value + comma;
});
//remove last comma
return result.substring(0, result.length - comma.length);
} else if (_.isFunction(oldJoin)) {
return oldJoin.apply(
this,
Array.prototype.slice.call(arguments, 0)
);
} else {
throw new Error('Please pass in a second argument');
}
};
/*
Example:
'http://domain.com/page?' + _.querystring({apples: '1.5', oranges: '2'})
'http://domain.com/page?' + 'apples=1.5&oranges=2'
*/
_.querystring = function(hash) {
return _(hash).join('=', '&');
};
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment