Skip to content

Instantly share code, notes, and snippets.

@windwp
Last active June 11, 2016 08:45
Show Gist options
  • Save windwp/f8c3a91fbde7930bdd4e2f655ddaad81 to your computer and use it in GitHub Desktop.
Save windwp/f8c3a91fbde7930bdd4e2f655ddaad81 to your computer and use it in GitHub Desktop.
javascript snippet
capitalize(value) {
return value.toLowerCase().replace( /\b\w/g, function (m) {
return m.toUpperCase();
});
}
private convertObjToUrlQuery(obj: any): string {
if (!obj) return '';
var parts = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
var query = encodeURIComponent(key) + '=' + (((typeof obj[key]) === 'string') ? encodeURIComponent(obj[key]) : encodeURIComponent(JSON.stringify(obj[key])));
parts.push(query);
}
}
return "?" + parts.join('&');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment