10 examples of 'javascript urlencode' in JavaScript

Every line of 'javascript urlencode' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
60function urlencode(str) {
61 str = (str + '').toString();
62
63 return encodeURIComponent(str)
64 .replace(/!/g, '%21')
65 .replace(/'/g, '%27')
66 .replace(/\(/g, '%28')
67 .replace(/\)/g, '%29')
68 .replace(/\*/g, '%2A')
69 .replace(/%20/g, '+');
70}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

184function urlEncode_(str) {
185 return encodeURIComponent(String(str));
186}
104function urlencode(o) {
105 var qs = [];
106 for (var k in o) qs.push(k + '=' + encodeURIComponent(o[k]));
107 return qs.join('&');
108}
191function base64urlEncode(s) {
192 return btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
193}
1export function urlEncode(data: any) {
2 return Object.keys(data)
3 .filter(key => data[key] !== undefined)
4 .map(key => `${key}=${encodeURIComponent(data[key])}`)
5 .join('&');
6}
127function urlEncode(unencoded) {
128 return encodeURIComponent(unencoded).replace(/'/g,'%27').replace(/"/g,'%22')
129}
74function base64urlEncode(str) {
75 return new Buffer(str).toString('base64');
76}
45function base64UrlEncode(data) {
46 var chop;
47 data = base64Encode(data);
48 chop = data.indexOf('=');
49 if (chop !== -1) {
50 data = data.slice(0, chop);
51 }
52 data = data.replace(/\+/g, '-');
53 data = data.replace(/\//g, '_');
54 return data;
55}
5export function encode(str: string): string {
6 return btoa(encodeURIComponent(str).replace(/%[0-9A-F]{2}/g, percentToByte));
7}
65export function urlEncode(obj, prefix) {
66 var str = []
67
68 for (var p in obj) {
69 if (obj.hasOwnProperty(p)) {
70 var k = prefix ? prefix + '[' + p + ']' : p
71 var v = obj[p]
72
73 str.push(
74 typeof v === 'object'
75 ? urlEncode(v, k)
76 : encodeURIComponent(k) + '=' + encodeURIComponent(v)
77 )
78 }
79 }
80 return str.join('&')
81}

Related snippets