@udraft/cursor
Version:
uDraft Cursor enables you to declarative write code generators!
74 lines (73 loc) • 2.53 kB
TypeScript
import { CursorSelection, CursorTransformer } from "../types/cursor";
export declare class UCursor<Type extends Record<string, any>> {
_children: {
key: keyof Type;
each: boolean;
cursor: UCursor<Type[keyof Type] | Type[keyof Type][number]>;
}[];
_identationSize: number | null;
_identationChar: string | null;
_block: [string, string] | null;
_prefix: string;
_suffix: string;
_move: number;
_selector: RegExp | null;
_parent: UCursor<{
[key: string]: Type;
}> | null;
_transformers: {
key: keyof Type;
each: boolean;
transformer: CursorTransformer<Type, any> | CursorTransformer<Type[keyof Type], number>;
}[];
_template: string;
_clearSelections: boolean;
_eachJoin: string;
constructor();
$children(): {
key: keyof Type;
each: boolean;
cursor: UCursor<Type[keyof Type] | Type[keyof Type][number]>;
}[];
$parent(): UCursor<{
[key: string]: Type;
}> | null;
$blocks(root?: boolean): number;
$identationChar(): string | null;
$identationSize(): number | null;
$identation(): {
root: string;
children: string;
};
$seletion(input: string): CursorSelection[];
move(amount: number): this;
block(start: string, end: string): this;
template(template: string): this;
clean(clearSelections?: boolean): this;
prefix(prefix: string): this;
suffix(suffix: string): this;
join(str: string): this;
select(selector: RegExp): this;
noIdent(): this;
ident({ size: identation, char }: {
size?: number;
char?: string;
}): this;
parent(parent: UCursor<{
[key: string]: Type;
}>): this;
empty(write: () => string): this;
linebreak(amount?: number): this;
expand(expanded: (cursor: UCursor<Type>) => void): this;
in<Key extends keyof Type>(key: Key, nested: (cursor: UCursor<Required<Type>[Key]>) => void): this;
each<Key extends keyof Type>(key: Key, nested: (cursor: UCursor<Required<Type>[Key][number]>) => void): this;
writeFrom<Key extends keyof Type>(key: Key, transformer: CursorTransformer<Type, Key>): this;
writeFromEach<Key extends keyof Type>(key: Key, transformer: CursorTransformer<Type[Key], number>): this;
write(transformer: CursorTransformer<{
root: Type;
}, "root">): this;
render(data: Type, input?: string, meta?: {
noFix: boolean;
}): string;
_clean(output: string): string;
}