(str: string): Result.Result<string, EncodingError>Decodes a URL-safe base64 string into a UTF-8 string safely.
When to use
Use to decode padded or unpadded Base64Url text into UTF-8 text without throwing on invalid input.
Details
Returns Result.succeed with the decoded text when decoding succeeds, or
Result.fail with an EncodingError when the input is not valid URL-safe
base64.
Example (Decoding URL-safe Base64 strings)
import { Encoding, Result } from "effect"
const result = Encoding.decodeBase64UrlString("aGVsbG8_")
if (Result.isSuccess(result)) {
console.log(result.success) // "hello?"
}export const const decodeBase64UrlString: (
str: string
) => Result.Result<string, EncodingError>
Decodes a URL-safe base64 string into a UTF-8 string safely.
When to use
Use to decode padded or unpadded Base64Url text into UTF-8 text without
throwing on invalid input.
Details
Returns Result.succeed with the decoded text when decoding succeeds, or
Result.fail with an EncodingError when the input is not valid URL-safe
base64.
Example (Decoding URL-safe Base64 strings)
import { Encoding, Result } from "effect"
const result = Encoding.decodeBase64UrlString("aGVsbG8_")
if (Result.isSuccess(result)) {
console.log(result.success) // "hello?"
}
decodeBase64UrlString = (str: stringstr: string) => import ResultResult.const map: {
<A, A2>(f: (ok: A) => A2): <E>(
self: Result<A, E>
) => Result<A2, E>
<A, E, A2>(
self: Result<A, E>,
f: (ok: A) => A2
): Result<A2, E>
}
map(const decodeBase64Url: (
str: string
) => Result.Result<Uint8Array, EncodingError>
Decodes a URL-safe base64 string into bytes safely.
When to use
Use to decode padded or unpadded Base64Url text into bytes without throwing
on invalid input.
Details
Returns Result.succeed with a Uint8Array when decoding succeeds, or
Result.fail with an EncodingError when the input is not valid URL-safe
base64. Both padded and unpadded URL-safe base64 forms are accepted when
otherwise valid.
Example (Decoding URL-safe Base64 bytes)
import { Encoding, Result } from "effect"
const result = Encoding.decodeBase64Url("SGVsbG8_")
if (Result.isSuccess(result)) {
console.log(Array.from(result.success)) // [72, 101, 108, 108, 111, 63]
}
decodeBase64Url(str: stringstr), (_: Uint8Array<ArrayBufferLike>_) => const decoder: TextDecoderdecoder.TextDecoder.decode(input?: AllowSharedBufferSource, options?: TextDecodeOptions): stringThe TextDecoder.decode() method returns a string containing text decoded from the buffer passed as a parameter.
decode(_: Uint8Array<ArrayBufferLike>_))