ChemPal Documentation - v1.7.0
    Preparing search index...

    Function urlencode

    • Encodes a string to be used in a URL.

      Parameters

      • str: string

        The string to encode

      Returns string

      The encoded string

      const encoded = urlencode("Hello, world! - 95% ethanol");
      // Returns a value with only safe characters:
      // "Hello%2C+world%21+-+95%25+ethanol"
      export function urlencode(str: string): string {
      return encodeURIComponent(str)
      .replace(/!/g, '%21')
      .replace(/'/g, '%27')
      .replace(/\(/g, '%28')
      .replace(/\)/g, '%29')
      .replace(/\*/g, '%2A')
      .replace(/%20/g, '+');
      }