@tevm/voltaire / primitives/Base64
primitives/Base64
Type Aliases
Base64Like
Base64Like =Defined in: src/primitives/Base64/Base64Type.ts:19 Inputs that can be converted to BrandedBase64BrandedBase64|string|Uint8Array
Base64UrlLike
Base64UrlLike =Defined in: src/primitives/Base64/Base64Type.ts:37 Inputs that can be converted to BrandedBase64UrlBrandedBase64Url|string|Uint8Array
BrandedBase64
BrandedBase64 =Defined in: src/primitives/Base64/Base64Type.ts:12 Branded Base64 string type Standard Base64 encoding (RFC 4648):string&object
- Alphabet: A-Z, a-z, 0-9, +, /
- Padding: = (required, length must be multiple of 4)
Type Declaration
[brand]
readonly[brand]:"Base64"
BrandedBase64Url
BrandedBase64Url =Defined in: src/primitives/Base64/Base64Type.ts:30 Branded Base64Url string type URL-safe Base64 encoding (RFC 4648):string&object
- Alphabet: A-Z, a-z, 0-9, -, _
- Padding: typically omitted
Type Declaration
[brand]
readonly[brand]:"Base64Url"
Variables
Base64
Defined in: src/primitives/Base64/Base64.js:77 Base64 encoding/decoding namespace Standard and URL-safe base64 encoding with proper padding. Built on Web APIs for maximum performance and compatibility.constBase64:object
Type Declaration
calcDecodedSize()
calcDecodedSize: (Calculate decoded size in bytesencodedLength) =>number
Parameters
encodedLength
number
Length of base64 string
Returns
number
Maximum size of decoded output
calcEncodedSize()
calcEncodedSize: (Calculate encoded size in bytesdataLength) =>number
Parameters
dataLength
number
Length of data to encode
Returns
number
Size of base64 output
decode()
decode: (Decode standard base64 string to bytesencoded) =>Uint8Array<ArrayBufferLike>
Parameters
encoded
string
Base64 string to decode
Returns
Uint8Array<ArrayBufferLike>
Decoded bytes
See
https://voltaire.tevm.sh/primitives/base64 for Base64 documentationSince
0.0.0Throws
If input is invalid base64Example
decodeToString()
decodeToString: (Decode base64 string to UTF-8 stringencoded) =>string
Parameters
encoded
string
Base64 string
Returns
string
Decoded string
Example
decodeUrlSafe()
decodeUrlSafe: (Decode URL-safe base64 string to bytesencoded) =>Uint8Array<ArrayBufferLike>
Parameters
encoded
string
URL-safe base64 string
Returns
Uint8Array<ArrayBufferLike>
Decoded bytes
Throws
If input is invaliddecodeUrlSafeToString()
decodeUrlSafeToString: (Decode URL-safe base64 to UTF-8 stringencoded) =>string
Parameters
encoded
string
URL-safe base64 string
Returns
string
Decoded string
encode()
encode: (Encode bytes to standard base64 string Uses standard base64 alphabet (A-Z, a-z, 0-9, +, /) with padding (=)data) =>BrandedBase64
Parameters
data
Uint8Array<ArrayBufferLike>
Bytes to encode
Returns
BrandedBase64
Base64-encoded string
Example
encodeString()
encodeString: (Encode string to base64str) =>string
Parameters
str
string
String to encode (UTF-8)
Returns
string
Base64-encoded string
Example
encodeStringUrlSafe()
encodeStringUrlSafe: (Encode string to URL-safe base64str) =>BrandedBase64Url
Parameters
str
string
String to encode (UTF-8)
Returns
BrandedBase64Url
URL-safe base64 string
encodeUrlSafe()
encodeUrlSafe: (Encode bytes to URL-safe base64 string Uses URL-safe alphabet (A-Z, a-z, 0-9, -, _) without paddingdata) =>BrandedBase64Url
Parameters
data
Uint8Array<ArrayBufferLike>
Bytes to encode
Returns
BrandedBase64Url
URL-safe base64 string
Example
from()
from: (Convert input to BrandedBase64value) =>BrandedBase64
Parameters
value
Base64Like
Input to convert
Returns
BrandedBase64
Branded Base64 string
Throws
If input cannot be converted to valid Base64Example
fromUrlSafe()
fromUrlSafe: (Convert input to BrandedBase64Urlvalue) =>BrandedBase64Url
Parameters
value
Base64UrlLike
Input to convert
Returns
BrandedBase64Url
Branded Base64Url string
Throws
If input cannot be converted to valid Base64UrlExample
isValid()
isValid: (Check if string is valid base64str) =>boolean
Parameters
str
string
String to validate
Returns
boolean
True if valid base64
isValidUrlSafe()
isValidUrlSafe: (Check if string is valid URL-safe base64str) =>boolean
Parameters
str
string
String to validate
Returns
boolean
True if valid URL-safe base64
toBase64()
toBase64: (Convert BrandedBase64Url to BrandedBase64value) =>BrandedBase64
Parameters
value
BrandedBase64Url
Base64Url string
Returns
BrandedBase64
Base64 string
Example
toBase64Url()
toBase64Url: (Convert BrandedBase64 to BrandedBase64Urlvalue) =>BrandedBase64Url
Parameters
value
BrandedBase64
Base64 string
Returns
BrandedBase64Url
Base64Url string
Example
toBytes()
toBytes: (Convert BrandedBase64 to bytesvalue) =>Uint8Array<ArrayBufferLike>
Parameters
value
BrandedBase64
Base64 string
Returns
Uint8Array<ArrayBufferLike>
Decoded bytes
Example
toBytesUrlSafe()
toBytesUrlSafe: (Convert BrandedBase64Url to bytesvalue) =>Uint8Array<ArrayBufferLike>
Parameters
value
BrandedBase64Url
Base64Url string
Returns
Uint8Array<ArrayBufferLike>
Decoded bytes
Example
toString()
toString: (Convert BrandedBase64 to plain string (strip branding)value) =>string
Parameters
value
BrandedBase64
Base64 string
Returns
string
Plain string
Example
toStringUrlSafe()
toStringUrlSafe: (Convert BrandedBase64Url to plain string (strip branding)value) =>string
Parameters
value
BrandedBase64Url
Base64Url string
Returns
string
Plain string
Example
Example
Functions
calcDecodedSize()
calcDecodedSize(Defined in: src/primitives/Base64/calcDecodedSize.js:7 Calculate decoded size in bytesencodedLength):number
Parameters
encodedLength
number
Length of base64 string
Returns
number
Maximum size of decoded output
calcEncodedSize()
calcEncodedSize(Defined in: src/primitives/Base64/calcEncodedSize.js:7 Calculate encoded size in bytesdataLength):number
Parameters
dataLength
number
Length of data to encode
Returns
number
Size of base64 output
decode()
decode(Defined in: src/primitives/Base64/decode.js:19 Decode standard base64 string to bytesencoded):Uint8Array<ArrayBufferLike>
Parameters
encoded
string
Base64 string to decode
Returns
Uint8Array<ArrayBufferLike>
Decoded bytes
See
https://voltaire.tevm.sh/primitives/base64 for Base64 documentationSince
0.0.0Throws
If input is invalid base64Example
decodeToString()
decodeToString(Defined in: src/primitives/Base64/decodeToString.js:15 Decode base64 string to UTF-8 stringencoded):string
Parameters
encoded
string
Base64 string
Returns
string
Decoded string
Example
decodeUrlSafe()
decodeUrlSafe(Defined in: src/primitives/Base64/decodeUrlSafe.js:10 Decode URL-safe base64 string to bytesencoded):Uint8Array<ArrayBufferLike>
Parameters
encoded
string
URL-safe base64 string
Returns
Uint8Array<ArrayBufferLike>
Decoded bytes
Throws
If input is invaliddecodeUrlSafeToString()
decodeUrlSafeToString(Defined in: src/primitives/Base64/decodeUrlSafeToString.js:9 Decode URL-safe base64 to UTF-8 stringencoded):string
Parameters
encoded
string
URL-safe base64 string
Returns
string
Decoded string
encode()
encode(Defined in: src/primitives/Base64/encode.js:19 Encode bytes to standard base64 string Uses standard base64 alphabet (A-Z, a-z, 0-9, +, /) with padding (=)data):BrandedBase64
Parameters
data
Uint8Array<ArrayBufferLike>
Bytes to encode
Returns
BrandedBase64
Base64-encoded string
Example
encodeString()
encodeString(Defined in: src/primitives/Base64/encodeString.js:14 Encode string to base64str):string
Parameters
str
string
String to encode (UTF-8)
Returns
string
Base64-encoded string
Example
encodeStringUrlSafe()
encodeStringUrlSafe(Defined in: src/primitives/Base64/encodeStringUrlSafe.js:9 Encode string to URL-safe base64str):BrandedBase64Url
Parameters
str
string
String to encode (UTF-8)
Returns
BrandedBase64Url
URL-safe base64 string
encodeUrlSafe()
encodeUrlSafe(Defined in: src/primitives/Base64/encodeUrlSafe.js:19 Encode bytes to URL-safe base64 string Uses URL-safe alphabet (A-Z, a-z, 0-9, -, _) without paddingdata):BrandedBase64Url
Parameters
data
Uint8Array<ArrayBufferLike>
Bytes to encode
Returns
BrandedBase64Url
URL-safe base64 string
Example
from()
from(Defined in: src/primitives/Base64/from.js:21 Convert input to BrandedBase64value):BrandedBase64
Parameters
value
Base64Like
Input to convert
Returns
BrandedBase64
Branded Base64 string
Throws
If input cannot be converted to valid Base64Example
fromUrlSafe()
fromUrlSafe(Defined in: src/primitives/Base64/fromUrlSafe.js:21 Convert input to BrandedBase64Urlvalue):BrandedBase64Url
Parameters
value
Base64UrlLike
Input to convert
Returns
BrandedBase64Url
Branded Base64Url string
Throws
If input cannot be converted to valid Base64UrlExample
isValid()
isValid(Defined in: src/primitives/Base64/isValid.js:7 Check if string is valid base64str):boolean
Parameters
str
string
String to validate
Returns
boolean
True if valid base64
isValidUrlSafe()
isValidUrlSafe(Defined in: src/primitives/Base64/isValidUrlSafe.js:7 Check if string is valid URL-safe base64str):boolean
Parameters
str
string
String to validate
Returns
boolean
True if valid URL-safe base64
toBase64()
toBase64(Defined in: src/primitives/Base64/toBase64.js:17 Convert BrandedBase64Url to BrandedBase64value):BrandedBase64
Parameters
value
BrandedBase64Url
Base64Url string
Returns
BrandedBase64
Base64 string
Example
toBase64Url()
toBase64Url(Defined in: src/primitives/Base64/toBase64Url.js:17 Convert BrandedBase64 to BrandedBase64Urlvalue):BrandedBase64Url
Parameters
value
BrandedBase64
Base64 string
Returns
BrandedBase64Url
Base64Url string
Example
toBytes()
toBytes(Defined in: src/primitives/Base64/toBytes.js:16 Convert BrandedBase64 to bytesvalue):Uint8Array<ArrayBufferLike>
Parameters
value
BrandedBase64
Base64 string
Returns
Uint8Array<ArrayBufferLike>
Decoded bytes
Example
toBytesUrlSafe()
toBytesUrlSafe(Defined in: src/primitives/Base64/toBytesUrlSafe.js:16 Convert BrandedBase64Url to bytesvalue):Uint8Array<ArrayBufferLike>
Parameters
value
BrandedBase64Url
Base64Url string
Returns
Uint8Array<ArrayBufferLike>
Decoded bytes
Example
toString()
toString(Defined in: src/primitives/Base64/toString.js:15 Convert BrandedBase64 to plain string (strip branding)value):string
Parameters
value
BrandedBase64
Base64 string
Returns
string
Plain string
Example
toStringUrlSafe()
toStringUrlSafe(Defined in: src/primitives/Base64/toStringUrlSafe.js:14 Convert BrandedBase64Url to plain string (strip branding)value):string
Parameters
value
BrandedBase64Url
Base64Url string
Returns
string
Plain string

