velt/encoding
API referenceConverts between bytes and text: Base64 (RFC 4648, standard and URL-safe alphabets), lowercase hex, and UTF-8. The functions work on u8[], Velt's byte array; Uint8Array.fromBytes(b) and xs.toBytes() convert to and from typed arrays. For a walkthrough, read the guide.
Exports
+/ alphabet) with = padding.base64EncodeStringBase64 of the UTF-8 bytes of s.base64UrlDecodeDecodes URL-safe Base64; padding is optional.base64UrlEncodeURL-safe Base64 (-_ alphabet, RFC 4648 §5) without padding.atobThe bytes the Base64 data encodes, as a string with one code unit per byte, as Node's atob (WHATWG forgiving-base64): ASCII whitespace anywhere is ignored, and so is the padding (but at most two =, only at the end, and only where they complete a group of four).btoaThe Base64 (standard alphabet, = padded) of data, whose code units are bytes, as Node's btoa.hexDecodeDecodes hex digits (either case).hexEncodeLowercase hex, two digits per byte.isAsciiWhether every character of s is ASCII (so its bytes are its UTF-16 code units).utf8ByteAtByte i of s's UTF-8 (as utf8Length counts them), read in place; a RangeError past it.utf8LengthThe number of bytes s keeps its text in: UTF-8, a lone surrogate as its three-byte form (Buffer.byteLength(s) for well-formed text).utf8SubstringThe text of bytes start to end of s's UTF-8 (as utf8ByteAt numbers them), shared with s where slice would share it.firstInvalidOffset of the first byte of data that starts an invalid UTF-8 sequence, or -1.utf8DecodeDecodes UTF-8.utf8DecodeLossyDecodes UTF-8, replacing each maximal invalid subsequence with U+FFFD (WHATWG / Unicode "substitution of maximal subparts", as TextDecoder and Rust's from_utf8_lossy do).utf8EncodeThe UTF-8 bytes of s (a copy).utf8ValidWhether data is valid UTF-8.validToStringBytes known to be valid UTF-8 (encoder output, repaired lossy input) as a string.EncodingErrorThrown for malformed Base64, hex or UTF-8 input.Re-exported from velt/encoding/base64
function base64Decode(s: string): u8[]Decodes standard Base64; padding is optional. Throws EncodingError on a character outside the
alphabet or a length or padding that cannot come from whole bytes.
Re-exported from velt/encoding/base64
function base64DecodeString(s: string): stringDecodes Base64 to bytes and those as UTF-8. Throws EncodingError on bad Base64 or UTF-8.
Re-exported from velt/encoding/base64
function base64Encode(data: u8[]): stringStandard Base64 (+/ alphabet) with = padding.
Re-exported from velt/encoding/base64
function base64EncodeString(s: string): stringBase64 of the UTF-8 bytes of s.
Re-exported from velt/encoding/base64
function base64UrlDecode(s: string): u8[]Decodes URL-safe Base64; padding is optional. Throws EncodingError.
Re-exported from velt/encoding/base64
function base64UrlEncode(data: u8[]): stringURL-safe Base64 (-_ alphabet, RFC 4648 §5) without padding.
Re-exported from velt/encoding/binary_string
function atob(data: string): stringThe bytes the Base64 data encodes, as a string with one code unit per byte, as Node's
atob (WHATWG forgiving-base64): ASCII whitespace anywhere is ignored, and so is the
padding (but at most two =, only at the end, and only where they complete a group of four).
Throws a DOMException named InvalidCharacterError on any other character and on a length
that cannot come from whole bytes.
Re-exported from velt/encoding/binary_string
function btoa(data: string): stringThe Base64 (standard alphabet, = padded) of data, whose code units are bytes, as Node's
btoa. Throws a DOMException named InvalidCharacterError if a code unit is above 0xFF.
Re-exported from velt/encoding/hex
function hexDecode(s: string): u8[]Decodes hex digits (either case). Throws EncodingError on odd length or a non-hex character.
Re-exported from velt/encoding/hex
function hexEncode(data: u8[]): stringLowercase hex, two digits per byte.
Re-exported from velt/encoding/string_bytes
function isAscii(s: string): boolWhether every character of s is ASCII (so its bytes are its UTF-16 code units). O(1).
Re-exported from velt/encoding/string_bytes
function utf8ByteAt(s: string, i: usize): u8Byte i of s's UTF-8 (as utf8Length counts them), read in place; a RangeError past it.
Re-exported from velt/encoding/string_bytes
function utf8Length(s: string): usizeThe number of bytes s keeps its text in: UTF-8, a lone surrogate as its three-byte form
(Buffer.byteLength(s) for well-formed text). O(1).
Re-exported from velt/encoding/string_bytes
function utf8Substring(s: string, start: usize, end: usize): stringThe text of bytes start to end of s's UTF-8 (as utf8ByteAt numbers them), shared with
s where slice would share it. A RangeError unless start <= end <= utf8Length(s) and both
are at the start of a character (or the end).
Re-exported from velt/encoding/utf8
function firstInvalid(data: u8[]): i64Offset of the first byte of data that starts an invalid UTF-8 sequence, or -1.
Re-exported from velt/encoding/utf8
function utf8Decode(data: u8[]): stringDecodes UTF-8. Throws EncodingError if data is not valid UTF-8 (overlong forms,
surrogates and code points above U+10FFFF are invalid).
Re-exported from velt/encoding/utf8
function utf8DecodeLossy(data: u8[]): stringDecodes UTF-8, replacing each maximal invalid subsequence with U+FFFD (WHATWG / Unicode
"substitution of maximal subparts", as TextDecoder and Rust's from_utf8_lossy do).
Re-exported from velt/encoding/utf8
function utf8Encode(s: string): u8[]The UTF-8 bytes of s (a copy).
Re-exported from velt/encoding/utf8
function utf8Valid(data: u8[]): boolWhether data is valid UTF-8.
Re-exported from velt/encoding/utf8
function validToString(bytes: u8[]): stringBytes known to be valid UTF-8 (encoder output, repaired lossy input) as a string.
Re-exported from velt/encoding/errors
class EncodingError extends ErrorThrown for malformed Base64, hex or UTF-8 input.
constructor(message: string)No doc comment yet