Skip to content

Commit 0c44224

Browse files
authored
Added type definations for class 'rule' to get ts support. (#160)
1 parent 032fb49 commit 0c44224

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

index.d.ts

+32
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ export type Item = {
3535
text: string;
3636
};
3737

38+
export type RuleAccumulator = (item: Item) => boolean | void;
39+
export type RuleHandler<T = any> = (value: T) => void;
40+
41+
export interface TableResult {
42+
matrix: string[][];
43+
items: Item[];
44+
}
45+
3846
export class TableParser {
3947
private rows: { [key: string]: Item[] };
4048
constructor();
@@ -47,3 +55,27 @@ export class TableParser {
4755
getCleanMatrix(options?: { collisionSeparator: string }): string[][];
4856
renderMatrix(): string;
4957
}
58+
59+
export class Rule {
60+
static on(regexp: RegExp): Rule;
61+
static after(regexp: RegExp): Rule;
62+
static makeItemProcessor(rules: Rule[]): (item: DataEntry) => void;
63+
static addAccumulator(methodName: string, methodBuilder: Function): void;
64+
65+
constructor(regexp: RegExp);
66+
67+
// Accumulator methods
68+
extractRegexpValues(): Rule;
69+
parseNextItemValue(): Rule;
70+
accumulateAfterHeading(): Rule;
71+
accumulateFromSameX(): Rule;
72+
parseColumns(...args: any[]): Rule;
73+
parseTable(columnCount: number): Rule & {
74+
then(handler: (result: TableResult) => void): Rule;
75+
};
76+
77+
then<T>(handler: RuleHandler<T>): Rule;
78+
79+
private test(item: Item): RuleAccumulator | undefined;
80+
private whenDone(callback: () => void): void;
81+
}

0 commit comments

Comments
 (0)