Skip to content

Encoding

This module provides encoding & decoding functionality for:

- base64 (RFC4648) - base64 (URL) - hex

21 exports Added in v2.0.0 Source

Decoding

decodeBase64

Added in v2.0.0 Source

Decodes a base64 (RFC4648) encoded string into a Uint8Array.

Signature

declare function decodeBase64(str: string): Either<Uint8Array<ArrayBufferLike>, DecodeException>;

Decodes a base64 (RFC4648) encoded string into a UTF-8 string.

Signature

declare function decodeBase64String(str: string): Either<string, DecodeException>;

Decodes a base64 (URL) encoded string into a Uint8Array.

Signature

declare function decodeBase64Url(str: string): Either<Uint8Array<ArrayBufferLike>, DecodeException>;

Decodes a base64 (URL) encoded string into a UTF-8 string.

Signature

declare function decodeBase64UrlString(str: string): Either<string, DecodeException>;

decodeHex

Added in v2.0.0 Source

Decodes a hex encoded string into a Uint8Array.

Signature

declare function decodeHex(str: string): Either<Uint8Array<ArrayBufferLike>, DecodeException>;

Decodes a hex encoded string into a UTF-8 string.

Signature

declare function decodeHexString(str: string): Either<string, DecodeException>;

Decodes a URI component string into a UTF-8 string.

Signature

declare function decodeUriComponent(str: string): Either<string, DecodeException>;

Encoding

encodeBase64

Added in v2.0.0 Source

Encodes the given value into a base64 (RFC4648) string.

Signature

declare const encodeBase64: (input: Uint8Array | string) => string;

Encodes the given value into a base64 (URL) string.

Signature

declare const encodeBase64Url: (input: Uint8Array | string) => string;

encodeHex

Added in v2.0.0 Source

Encodes the given value into a hex string.

Signature

declare const encodeHex: (input: Uint8Array | string) => string;

Encodes a UTF-8 string into a URI component string.

Signature

declare function encodeUriComponent(str: string): Either<string, EncodeException>;

Errors

Creates a checked exception which occurs when decoding fails.

Signature

declare const DecodeException: (input: string, message?: string) => DecodeException;

Creates a checked exception which occurs when encoding fails.

Signature

declare const EncodeException: (input: string, message?: string) => EncodeException;

Models

DecodeException interface

Added in v2.0.0 Source

Represents a checked exception which occurs when decoding fails.

Signature

interface DecodeException {
  readonly _tag: "DecodeException";
  readonly [DecodeExceptionTypeId]: typeof DecodeExceptionTypeId;
  readonly input: string;
  readonly message?: string;
}

EncodeException interface

Added in v3.12.0 Source

Represents a checked exception which occurs when encoding fails.

Signature

interface EncodeException {
  readonly _tag: "EncodeException";
  readonly [EncodeExceptionTypeId]: typeof EncodeExceptionTypeId;
  readonly input: string;
  readonly message?: string;
}

Refinements

Returns true if the specified value is an DecodeException, false otherwise.

Signature

declare const isDecodeException: (u: unknown) => u is DecodeException;

Returns true if the specified value is an EncodeException, false otherwise.

Signature

declare const isEncodeException: (u: unknown) => u is EncodeException;

Symbols

Signature

declare const DecodeExceptionTypeId: unique symbol;

Signature

type DecodeExceptionTypeId = typeof DecodeExceptionTypeId;

Signature

declare const EncodeExceptionTypeId: unique symbol;

EncodeExceptionTypeId type

Added in v3.12.0 Source

Signature

type EncodeExceptionTypeId = typeof EncodeExceptionTypeId;