cesr
Version:
[](https://www.npmjs.com/package/cesr) [](https://github.com/lenkan/cesr-js/blob/main/LICENSE)
59 lines (58 loc) • 1.58 kB
TypeScript
export interface CodeSizeInit {
hs: number;
fs?: number;
ss?: number;
os?: number;
ls?: number;
xs?: number;
}
export type CodeTableInit = Record<string, CodeSizeInit>;
export interface CodeSize {
hs: number;
fs: number;
ss: number;
os: number;
ls: number;
xs: number;
}
export type Domain = "text" | "binary";
export interface CodeTableOptions {
/**
* Strict lookup rules - throws if codes are not in the provided table
*/
strict?: boolean;
}
export interface FrameData {
code: string;
raw?: Uint8Array;
count?: number;
index?: number;
ondex?: number;
text?: string;
}
export interface ReadResult {
/**
* The frame, or null if there was not enough data in the input
*/
frame: Required<FrameData> | null;
/**
* The number of bytes consumed from the input
*/
n: number;
}
export declare class CodeTable {
#private;
constructor(table: Record<string, CodeSizeInit>, options?: CodeTableOptions);
/**
* Finds the size table of a code
* @param input The input to parse the code from
*/
lookup(input: string | Uint8Array): CodeSize;
encode(frame: FrameData, domain?: Domain): Uint8Array;
decode(input: string | Uint8Array): Required<FrameData>;
/**
* Tries to read a frame from the input. Returns an object with the frame and the number of bytes read.
* @param input The input. May be longer than one frame, in which case only the first frame is returned.
*/
read(input: Uint8Array): ReadResult;
}