Upload via GUI (7543 Dateien)

This commit is contained in:
2026-10-22 07:02:28 +00:00
parent 42fb8dfe9b
commit b2314f6fe6
50 changed files with 4466 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
import type { BufferSourceLike } from "../bytes/index.js";
import { type BufferEncoding } from "../converters/index.js";
import type { Utf16Options } from "../encoding/utf16.js";
/** Legacy text encodings accepted by the deprecated facade. */
export type TextEncoding = "ascii" | "utf8" | "utf16" | "utf16be" | "utf16le" | "usc2";
/**
* Legacy converter facade that mirrors the historical API surface.
* @deprecated Use the camelCase `convert` object or specific encoding modules instead.
*/
export declare class Convert {
/** Default UTF-8 encoding used by the legacy facade. */
static DEFAULT_UTF8_ENCODING: TextEncoding;
/** Checks whether the input is hexadecimal text. */
static isHex(data: unknown): data is string;
/** Checks whether the input is Base64 text. */
static isBase64(data: unknown): data is string;
/** Checks whether the input is Base64Url text. */
static isBase64Url(data: unknown): data is string;
/** Converts buffer data to text. */
static ToString(buffer: BufferSourceLike, enc?: BufferEncoding): string;
/** Converts text to bytes. */
static FromString(str: string, enc?: BufferEncoding): ArrayBufferLike;
/** Encodes bytes as Base64 text. */
static ToBase64(buffer: BufferSourceLike): string;
/** Decodes Base64 text into bytes. */
static FromBase64(base64: string): ArrayBufferLike;
/** Decodes Base64Url text into bytes. */
static FromBase64Url(base64url: string): ArrayBufferLike;
/** Encodes bytes as Base64Url text. */
static ToBase64Url(data: BufferSourceLike): string;
/** Converts UTF-8 or UTF-16 text to bytes. */
static FromUtf8String(text: string, encoding?: TextEncoding): ArrayBufferLike;
/** Converts bytes to UTF-8 or UTF-16 text. */
static ToUtf8String(buffer: BufferSourceLike, encoding?: TextEncoding): string;
/** Decodes binary text into bytes. */
static FromBinary(text: string): ArrayBufferLike;
/** Encodes bytes as binary text. */
static ToBinary(buffer: BufferSourceLike): string;
/** Encodes bytes as hexadecimal text. */
static ToHex(buffer: BufferSourceLike): string;
/** Decodes hexadecimal text into bytes. */
static FromHex(hexString: string): ArrayBufferLike;
/** Converts UTF-16 bytes into text. */
static ToUtf16String(buffer: BufferSourceLike, littleEndian?: boolean): string;
/** Converts UTF-16 text into bytes. */
static FromUtf16String(text: string, littleEndian?: boolean): ArrayBufferLike;
protected static Base64Padding(base64: string): string;
/** Normalizes whitespace in Base64-style text. */
static formatString(data: string): string;
}
/** Legacy text encoding aliases re-exported for compatibility. */
export type { BufferEncoding, Utf16Options };
+16
View File
@@ -0,0 +1,16 @@
import type { BufferSourceLike } from "../bytes/index.js";
/**
* Assigns own properties from source objects into the target object.
* @deprecated Prefer object spread or Object.assign.
*/
export declare function assign<T extends object>(target: T, ...sources: (Partial<T> | undefined | null)[]): T;
/**
* Concatenates buffer sources into a single ArrayBuffer.
* @deprecated Use `concat` from `@peculiar/utils/bytes` instead.
*/
export declare function combine(...buf: BufferSourceLike[]): ArrayBufferLike;
/**
* Compares two buffer sources for equality.
* @deprecated Use `equal` from `@peculiar/utils/bytes` instead.
*/
export declare function isEqual(bytes1: BufferSourceLike, bytes2: BufferSourceLike): boolean;
+5
View File
@@ -0,0 +1,5 @@
/** Barrel export for the deprecated compatibility layer. */
export { BufferSourceConverter } from "./buffer-source-converter.js";
export { Convert } from "./convert.js";
export type { BufferEncoding, TextEncoding } from "./convert.js";
export { assign, combine, isEqual } from "./functions.js";
+3
View File
@@ -0,0 +1,3 @@
/** Barrel export for PEM helpers, codecs, and related types. */
export type { PemBlock, PemCodec, PemDecodeOptions, PemEncodeBlock, PemEncodeOptions, PemFormat } from "./types.js";
export { decode, decodeFirst, encode, encodeMany, find, findAll, format, parse, pem, pemConverter } from "./pem.js";
+34
View File
@@ -0,0 +1,34 @@
import type { BufferSourceLike } from "../bytes/index.js";
import type { ParsedBytes, Converter } from "../converters/types.js";
import type { PemBlock, PemDecodeOptions, PemEncodeBlock, PemEncodeOptions, PemFormat } from "./types.js";
/** Encodes buffer data into a PEM block. */
export declare function encode(label: string, data: BufferSourceLike, options?: PemEncodeOptions): string;
/** Encodes multiple PEM blocks into one PEM bundle. */
export declare function encodeMany(blocks: readonly PemEncodeBlock[], options?: PemEncodeOptions): string;
/** Decodes PEM text into the contained blocks. */
export declare function decode(text: string, options?: PemDecodeOptions): PemBlock[];
/** Finds the first PEM block with the requested label. */
export declare function find(text: string, label: string): PemBlock | undefined;
/** Finds all PEM blocks with the requested label. */
export declare function findAll(text: string, label: string): PemBlock[];
/** Decodes the first matching PEM block. */
export declare function decodeFirst(text: string, label?: string): Uint8Array;
/** Parses the first matching PEM block and preserves its formatting metadata. */
export declare function parse(text: string, options?: PemDecodeOptions): ParsedBytes<PemFormat>;
/** Formats bytes with preserved PEM metadata. */
export declare function format(data: BufferSourceLike, value: PemFormat): string;
/** PEM codec helpers. */
export declare const pem: {
readonly decode: typeof decode;
readonly decodeFirst: typeof decodeFirst;
readonly encode: typeof encode;
readonly encodeMany: typeof encodeMany;
readonly find: typeof find;
readonly findAll: typeof findAll;
readonly format: typeof format;
readonly parse: typeof parse;
};
/** Converter wrapper for PEM text. */
export declare const pemConverter: Converter<PemEncodeOptions & {
label: string;
}, PemDecodeOptions, PemFormat>;
+48
View File
@@ -0,0 +1,48 @@
import type { BufferSourceLike } from "../bytes/index.js";
import type { ParsedBytes } from "../converters/types.js";
/** Represents a decoded PEM block with label, data, and optional headers. */
export interface PemBlock {
readonly label: string;
readonly data: Uint8Array;
readonly headers?: Readonly<Record<string, string>>;
}
/** Options that control PEM encoding. */
export interface PemEncodeOptions {
lineLength?: number;
newline?: "\n" | "\r\n";
headers?: Readonly<Record<string, string>>;
}
/** Options that control PEM decoding. */
export interface PemDecodeOptions {
label?: string;
strict?: boolean;
}
/** Format metadata that can be reused to re-encode PEM text. */
export interface PemFormat extends PemEncodeOptions {
readonly label: string;
}
/** Input block used by multi-block PEM encoding helpers. */
export interface PemEncodeBlock {
readonly label: string;
readonly data: BufferSourceLike;
readonly headers?: Readonly<Record<string, string>>;
}
/** Encodes and decodes PEM blocks. */
export interface PemCodec {
/** Encodes a buffer source into a PEM block. */
encode(label: string, data: BufferSourceLike, options?: PemEncodeOptions): string;
/** Encodes multiple PEM blocks into a single string. */
encodeMany(blocks: readonly PemEncodeBlock[], options?: PemEncodeOptions): string;
/** Decodes PEM text into blocks. */
decode(text: string, options?: PemDecodeOptions): PemBlock[];
/** Decodes the first matching PEM block. */
decodeFirst(text: string, label?: string): Uint8Array;
/** Finds the first PEM block with the requested label. */
find(text: string, label: string): PemBlock | undefined;
/** Finds all PEM blocks with the requested label. */
findAll(text: string, label: string): PemBlock[];
/** Parses the first matching PEM block and preserves the detected formatting. */
parse(text: string, options?: PemDecodeOptions): ParsedBytes<PemFormat>;
/** Formats bytes with previously detected PEM metadata. */
format(data: BufferSourceLike, format: PemFormat): string;
}