(str: string): Result.Result<string, EncodingError>Decodes a base64 (RFC4648) string into a UTF-8 string safely.
When to use
Use to decode a standard padded Base64 string 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 base64.
Example (Decoding Base64 strings)
import { Encoding, Result } from "effect"
const result = Encoding.decodeBase64String("aGVsbG8=")
if (Result.isSuccess(result)) {
console.log(result.success) // "hello"
}export const const decodeBase64String: (
str: string
) => Result.Result<string, EncodingError>
Decodes a base64 (RFC4648) string into a UTF-8 string safely.
When to use
Use to decode a standard padded Base64 string 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 base64.
Example (Decoding Base64 strings)
import { Encoding, Result } from "effect"
const result = Encoding.decodeBase64String("aGVsbG8=")
if (Result.isSuccess(result)) {
console.log(result.success) // "hello"
}
decodeBase64String = (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 decodeBase64: (
str: string
) => Result.Result<Uint8Array, EncodingError>
Decodes a base64 (RFC4648) string into bytes safely.
When to use
Use to decode a standard padded Base64 string 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 base64.
Example (Decoding Base64 bytes)
import { Encoding, Result } from "effect"
const result = Encoding.decodeBase64("SGVsbG8=")
if (Result.isSuccess(result)) {
console.log(Array.from(result.success)) // [72, 101, 108, 108, 111]
}
decodeBase64(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>_))