diff --git a/index.d.ts b/index.d.ts index 1869a65..b762de7 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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 }