HARPA.AI
LIBRARYAPIGUIDESAI COMMANDSBLOG

๐ŸŒย ย URL-Encoding / Decoding (Percent-encoding)

Fully encodes or decodes a URL using percent encoding.

Created by Morteza
Updated on Jan 13, 03:47
Installed 1 time
RUNS JS CODE

How to Use

IMPORT COMMAND

Content

- type: ask
  param: url
  message: 'Please provide URL:'
  options: null
  default: ''
  vision:
    enabled: false
    mode: area
    hint: ''
    send: true
  label: INPUT URL
  optionsInvalid: false
- type: js
  args: url
  code: |-
    function encodeDecodeURL(url) {
      function fullyEncode(str) {
        return str.split('').map(char => 
          '%' + char.charCodeAt(0).toString(16).toUpperCase()
        ).join('');
      }

      function partiallyEncode(str) {
        const protocol = str.match(/^(https?:\/\/)/)?.[1] || '';
        const rest = str.slice(protocol.length);
        return protocol + rest.split('').map(char => 
          char === '/' || char === ':' ? char : 
          '%' + char.charCodeAt(0).toString(16).toUpperCase()
        ).join('');
      }

      function universalDecode(str) {
        try {
          return decodeURIComponent(str.replace(/%([0-9A-F]{2})/gi, 
            (_, hex) => String.fromCharCode(parseInt(hex, 16))));
        } catch {
          return str;
        }
      }

      const fully = fullyEncode(url);
      const partially = partiallyEncode(url);
      const minimally = encodeURI(url);

      return {
        encoded: {
          header: "=== ENCODED VERSIONS ===",
          fully: fully,
          partially: partially,
          minimally: minimally
        },
        decoded: {
          header: "=== DECODED VERSIONS ===",
          fully: universalDecode(fully),
          partially: universalDecode(partially),
          minimally: universalDecode(minimally)
        }
      };
    }

    return encodeDecodeURL(args.url);
  param: resultURL
  timeout: 15000
  onFailure: ''
  silent: true
  label: ENCODE / DECODE URL
- type: say
  message: |-
    **Encoded / Decoded version:**
    - Fully encoded URL:
    ```
    {{resultURL.encoded.fully}}
    ```
    - Partially encoded URL (retains protocol and slashes):
    ```
    {{resultURL.encoded.partially}}
    ```
    - Minimum encoded URL (special characters only):
    ```
    {{resultURL.encoded.minimally}}
    ```
    - Fully decoded URL:
    ```
    {{resultURL.decoded.fully}}
    ```
  label: DISPLAY RESULT
- type: jump
  to: INPUT URL
Notice: Please read before using

This automation command is created by a community member. HARPA AI team does not audit community commands.

Please review the command carefully and only install if you trust the creator.

Contact us
HomeUse CasesGuidesPrivacy PolicyTerms of Service
CAN WE STORE COOKIES?
Our website uses cookies for the purposes of accessibility and security. They also allow us to gather statistics in order to improve the website for you. More info: Privacy Policy