UNPKG

@hugoalh/base64

Version:

A module for Base64 encode and decode.

119 lines 3.38 kB
/** * Variant type of the Base64. */ export type Base64Variant = "rfc1421" | "rfc2045" | "rfc2152" | "rfc3501" | "rfc4648-4" | "rfc4648-5" | "rfc9580" | "standard" | "url"; /** * Base64 basic options. */ export interface Base64BasicOptions { /** * Which Base64 variant to use. * @default {"standard"} */ variant?: Base64Variant; } /** * Base64 decode options. */ export interface Base64DecodeOptions extends Base64BasicOptions { } /** * Base64 encode options. */ export interface Base64EncodeOptions extends Base64BasicOptions { /** * Whether allow to have padding (`=`). * * When this property is not defined as type of boolean, padding will according to the specification of the defined {@linkcode variant}. * @default {null} */ padding?: boolean | null; } /** * Base64 decoder. */ export declare class Base64Decoder { #private; get [Symbol.toStringTag](): string; /** * Initialize. * @param {Base64DecodeOptions} [options={}] Base64 decode options. */ constructor(options?: Base64DecodeOptions); /** * Variant of the Base64 decoder. * @returns {Base64Variant} */ get variant(): Base64Variant; /** * Decode from Base64 to bytes. * @param {string | Uint8Array} item Item that need to decode. * @returns {Uint8Array} A decoded bytes. */ decodeToBytes(item: string | Uint8Array): Uint8Array; /** * Decode from Base64 to text. * @param {string | Uint8Array} item Item that need to decode. * @returns {string} A decoded text. */ decodeToText(item: string | Uint8Array): string; } /** * Base64 encoder. */ export declare class Base64Encoder { #private; get [Symbol.toStringTag](): string; /** * Initialize. * @param {Base64EncodeOptions} [options={}] Base64 encode options. */ constructor(options?: Base64EncodeOptions); /** * Whether padding in the Base64 encoder. * @returns {boolean} */ get padding(): boolean; /** * Variant of the Base64 encoder. * @returns {Base64Variant} */ get variant(): Base64Variant; /** * Encode to Base64 bytes. * @param {string | Uint8Array} item Item that need to encode. * @returns {Uint8Array} A Base64 encoded bytes. */ encodeToBytes(item: string | Uint8Array): Uint8Array; /** * Encode to Base64 text. * @param {string | Uint8Array} item Item that need to encode. * @returns {string} A Base64 encoded text. */ encodeToText(item: string | Uint8Array): string; } /** * Transform from Base64 encoded bytes stream to bytes stream. */ export declare class Base64DecoderStream extends TransformStream<Uint8Array, Uint8Array> { #private; get [Symbol.toStringTag](): string; /** * Initialize. * @param {Base64DecodeOptions} [options={}] Base64 decode options. */ constructor(options?: Base64DecodeOptions); } /** * Transform from bytes stream to Base64 encoded bytes stream. */ export declare class Base64EncoderStream extends TransformStream<Uint8Array, Uint8Array> { #private; get [Symbol.toStringTag](): string; /** * Initialize. * @param {Base64EncodeOptions} [options={}] Base64 encode options. */ constructor(options?: Base64EncodeOptions); } //# sourceMappingURL=mod.d.ts.map