happy-codec
    Preparing search index...

    Function encodeBase64

    • Converts DataSource (string or BufferSource) to a Base64 encoded string.

      Uses native Uint8Array.prototype.toBase64 if available, otherwise pure JS fallback.

      Parameters

      Returns string

      Base64 encoded string.

      If the input is not a string, ArrayBuffer, or ArrayBufferView.

      1.0.0

      // String input
      const encoded = encodeBase64('Hello, World!');
      console.log(encoded); // 'SGVsbG8sIFdvcmxkIQ=='

      // BufferSource input
      const buffer = new Uint8Array([72, 101, 108, 108, 111]);
      const base64 = encodeBase64(buffer);
      console.log(base64); // 'SGVsbG8='

      // Base64url with no padding
      const url = encodeBase64(buffer, { alphabet: 'base64url', omitPadding: true });
      console.log(url); // 'SGVsbG8'