UNPKG

@alessiofrittoli/crypto-encoder

Version:
39 lines (36 loc) 1.49 kB
import { CoerceToUint8ArrayInput } from '@alessiofrittoli/crypto-buffer'; /** * Represents the encoding types that can be used. * * This type includes all standard `BufferEncoding` types as well as a custom 'base32' encoding. */ type Encoding = BufferEncoding | 'base32'; /** * The Encoder class provides static methods for encoding and decoding data * using various encoding schemes such as base32, base64, and others. */ declare class Encoder { /** * A list of supported encodings. */ static SUPPORTED_ENCODINGS: Encoding[]; /** * Encodes the given data using the specified encoding. * * @param data - The data to encode. This can be a string, Buffer, or Uint8Array. * @param encoding - The encoding to use for the output. If not specified, defaults to 'utf8'. * @param inputEncoding - The encoding of the input data. * @returns The encoded data as a string. */ static encode(data: CoerceToUint8ArrayInput, encoding?: Encoding, inputEncoding?: Encoding): string; /** * Decodes the given data using the specified encoding. * * @param data - The data to decode. * @param encoding - The encoding of the input data. * @returns The decoded data as a Uint8Array. */ static decode(data: CoerceToUint8ArrayInput, encoding?: Encoding): Uint8Array<ArrayBufferLike> | Buffer<ArrayBuffer>; static toString: (input: CoerceToUint8ArrayInput) => string; } export { Encoder, type Encoding };