From b5a6c3657d99c9648a62bfff2b315118fc5bb453 Mon Sep 17 00:00:00 2001 From: Sebastian Frank Date: Wed, 4 Nov 2026 14:50:37 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20types(hooks):=20base64-Varianten=20?= =?UTF-8?q?und=20padding=20(#62)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- index.d.ts | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) 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 }