Skip to content

Instantly share code, notes, and snippets.

@rufus2021
Created August 20, 2015 14:01
Show Gist options
  • Save rufus2021/fe097433cb099b15ada4 to your computer and use it in GitHub Desktop.
Save rufus2021/fe097433cb099b15ada4 to your computer and use it in GitHub Desktop.
// encode a particular part of a url
exports.encodeUrl = function encodeUrl(url, delimiter, keyword) {
var split = url.split(delimiter);
var container = [];
split.map(function (item) {
var replaced = keyword + '=';
if (item.indexOf(keyword) === 0) {
item = encodeURIComponent(item.split('=')[1]);
return container.push(replaced + item);
}
container.push(item);
});
return container.join('&');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment