feat(modules/misc/urldecode): add urldecode command
This commit is contained in:
		
							parent
							
								
									9f584e69a8
								
							
						
					
					
						commit
						9cbafac379
					
				
					 1 changed files with 29 additions and 0 deletions
				
			
		
							
								
								
									
										29
									
								
								src/modules/misc/urldecode.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/modules/misc/urldecode.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,29 @@
 | 
			
		|||
const Command = require("#lib/command.js");
 | 
			
		||||
 | 
			
		||||
const urldecode = new Command("urldecode");
 | 
			
		||||
urldecode.category = "misc";
 | 
			
		||||
urldecode.helpText = "Get url information";
 | 
			
		||||
urldecode.usage = "<url>";
 | 
			
		||||
urldecode.callback = async function (msg, _, [urlString]) {
 | 
			
		||||
    const url = new URL(urlString);
 | 
			
		||||
 | 
			
		||||
    const info = [
 | 
			
		||||
        ["scheme", url.protocol],
 | 
			
		||||
        ["username", url.username],
 | 
			
		||||
        ["password", url.password],
 | 
			
		||||
        ["host", url.host],
 | 
			
		||||
        ["path", url.pathname],
 | 
			
		||||
        ["hash", url.hash],
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    return `\`\`\`py
 | 
			
		||||
${info.filter(kv => kv[1].length > 0).map(([k, v]) => `${k} = ${v}`).join("\n")}
 | 
			
		||||
 | 
			
		||||
${JSON.stringify(
 | 
			
		||||
    url.searchParams,
 | 
			
		||||
    (_, v) => v instanceof URLSearchParams ? Object.fromEntries(v.entries()) : v,
 | 
			
		||||
    "\t"
 | 
			
		||||
)}
 | 
			
		||||
\`\`\``;
 | 
			
		||||
};
 | 
			
		||||
hf.registerCommand(urldecode);
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue