@metreeca/core - v0.9.22
    Preparing search index...

    Function encodeBase64

    • Encodes a string to base64.

      Converts the input to UTF-8 bytes and encodes them in the standard alphabet of RFC 4648 § 4, retaining the trailing = padding, or in the URL-safe variant of RFC 4648 § 5, substituting + / / with - / _ and stripping the trailing = padding.

      Warning

      Text carrying isolated UTF-16 surrogates doesn't survive the round trip: UTF-8 conversion replaces each one with U+FFFD REPLACEMENT CHARACTER, so decoding the result returns a string that differs from plain. Test the input with strings!isWellFormed or sanitise it with strings!toWellFormed where the distinction matters.

      Parameters

      • plain: string

        The string to encode

      • url: boolean = false

        Whether to encode using the URL-safe alphabet of RFC 4648 § 5 rather than the standard alphabet of RFC 4648 § 4; defaults to false

      Returns string

      The base64 representation of plain in the selected alphabet, with every isolated surrogate encoded as U+FFFD