Open In App

Node.js querystring.unescape() Method

Improve
Improve
Like Article
Like
Save
Share
Report

On the specified str, the querystring.unescape() method decodes URL percent-encoded characters. This method converts a percent-encoding string into a normal string. It means it decodes any percent-encoding string into a normal string by removing the % symbol. This method iterates through the string and removes the % encoding where needed on the specified str.

The queryString.unescape() function is used by querystring.parse() and is not well known for direct usage. It’s being imported mainly to enable program code to have a changeable decoding implementation by assigning queryString.unescape to a different function if necessary.

Syntax:

querystring.unescape(str);

Parameters: This function accepts only one parameter, which is described below.

  • Str: It is the URL percent-encoded characters that are going to be decoded into a normal string.

Return value: It returns a normal string after decoding the URL percent-encoded characters.

Note: Install querystring using the below command.

npm i querystring

Below are the following examples to explain the concepts of the query string.unescape function.

Example 1:  In this example, we are encoding a URL percent-encoded string.

Index.js

Javascript




//Importing querystring module
import querystring from "querystring" 
  
// String to be decoded
let str = "I%20love%20geeksforgeeks";
  
// Using the unescape function to decode
let decodedURL = querystring.unescape(str);
  
// Printing the decoded url
console.log(decodedURL)


Run index.js file using below command:

node index.js

Output:

Decoded string: I love geeksforgeeks

Example 2: In this example, we are decoding a  URL percent-encoded string using querystring.unescape( ) function and decodeURIComponent function and print the output of both the functions.

Javascript




//Importing querystring module
import querystring from "querystring" 
  
// String to be encoded
let str = "I%20love%20geeksforgeeks";
  
// Using the unescape function to the string
let decodeURL1 = querystring.unescape(str);
  
let decodeURL2 = decodeURIComponent(str);
// Printing the decoded url
console.log("Decoded string using unescape: " + decodeURL1)
console.log("Decoded string using decodeURIComponent: " + decodeURL2)
  
  
if(decodeURL2 === decodeURL1)
console.log("both strings are equal")


Output:

Decoded string using unescape: I love geeksforgeeks
Decoded string using decodeURIComponent: I love geeksforgeeks
both strings are equal


Last Updated : 08 Apr, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads