API reference › @evolu/common › Type › Uint8ArrayFromBase64Url
const Uint8ArrayFromBase64Url: transform(
"Uint8ArrayFromBase64Url",
Base64Url,
Uint8Array,
{
from: (value) => ok(base64UrlToUint8Array(value)),
to: uint8ArrayToBase64Url,
},
);
Defined in: packages/common/src/Type.ts:8763
Transforms Base64Url text into bytes.
Use it to decode binary fields of JSON and other text payloads, for example inside an object. Decoding cannot fail, because Base64Url accepts only the canonical encoding of some bytes. Encoding returns that canonical text, so equal bytes encode to equal strings.
Example
import {
assertEqual,
assertErr,
assertOk,
Uint8ArrayFromBase64Url,
} from "@evolu/common";
const bytes = Uint8ArrayFromBase64Url.fromUnknown("AAEC_w");
assertOk(bytes, new Uint8Array([0, 1, 2, 255]));
assertEqual(Uint8ArrayFromBase64Url.to(bytes.value), "AAEC_w");
assertErr(Uint8ArrayFromBase64Url.fromUnknown("AAEC/w"), {
type: "Base64Url",
value: "AAEC/w",
});