✨ types(hooks): base64-Varianten und padding (#62)

BaseVariant, Base64Options, Base64DecodeOptions; encode/decode typisieren
variant (base64|base64url|base32) und padding. Overloads erhalten den
Rückgabetyp abhängig von returnBytes.

Refs cms/tibi-server#62
This commit is contained in:
apairon committed 2026-11-04 14:50:37 +00:00
1 parent ce0ac300f5
commit b5a6c3657d
1 file changed
+41 -4
Vendored
+41 -4
View File
@@ -1906,14 +1906,51 @@ declare global {
: string
}
/** RFC 4648 encoding variant shared by the base64 helpers. */
export type BaseVariant = "base64" | "base64url" | "base32"
export interface Base64Options {
/**
* Alphabet: `base64` (default, `+/`), `base64url` (`-_`) or `base32`
* (RFC 4648 §6, uppercase).
*/
variant?: BaseVariant
/**
* RFC padding. Default: `true` for `base64`, `false` for `base64url`
* and `base32` (JWT parts and TOTP secrets are unpadded).
*/
padding?: boolean
}
export interface Base64DecodeOptions extends Base64Options {
/** Return raw bytes instead of a string (default: false). */
returnBytes?: boolean
}
interface Base64Package {
encode(data: string | Int8Array): string
/**
* Encode a string/bytes value. Without options this is padded standard
* base64 — the historical, unchanged behaviour.
*/
encode(data: string | Int8Array, options?: Base64Options): string
/**
* Decode. Without an explicit `padding`, both padded and unpadded input
* are accepted; `base32` additionally accepts lowercase and grouped
* input ("MZXW 6YTB OI"). Alphabets stay strict.
*/
decode(data: string): string
decode(data: string, options: { returnBytes: true }): Int8Array
decode(data: string, options: { returnBytes: false }): string
decode(
data: string,
options: { returnBytes?: boolean }
options: Base64DecodeOptions & { returnBytes: true }
): Int8Array
decode(
data: string,
options: Base64DecodeOptions & { returnBytes?: false }
): string
decode(
data: string,
options: Base64DecodeOptions & { returnBytes: boolean }
): string | Int8Array
}