-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.d.ts
61 lines (48 loc) · 1.84 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
type Dict = Record<string, any>;
type Promisable<T> = Promise<T> | T;
export type Rules<T extends Dict = Dict> = {
[K in keyof T]: boolean | T[K];
};
export interface Context<T extends Dict = Rules> {
readonly options: Pick<Config, 'host'> & Record<string, any>;
load<K extends keyof T>(title: K): T[K] | void;
report<K extends keyof T>(title: K, message: string): void;
assert<K extends keyof T>(title: K, check: boolean, message: string): void;
assert<K extends keyof T>(title: K, check: (options: Exclude<T[K],boolean>) => boolean, message: string): void;
// TODO?: async checks
// assert<K extends keyof T>(title: K, check: (options: Exclude<T[K],boolean>) => Promise<boolean>, message: string): Promise<void>;
// assert<K extends keyof T>(title: K, check: boolean | ((options: Exclude<T[K],boolean>) => Promisable<boolean>), message: string): Promisable<void>;
}
export type Plugin<R extends Rules = Rules> = (context: Context<R>, document: HTMLElement) => Promisable<void>;
export interface Argv {
cwd?: string;
host?: string;
input?: string[];
}
export interface Config {
host?: string;
inputs?: string[];
presets?: Config[];
plugins?: Plugin[];
rules?: Rules;
}
export interface Message {
message: string;
line?: number;
col?: number;
}
export type Messages = {
[rule: string]: Message;
}
export type Report = {
[input: string]: Messages;
}
export function lint(html: string, config?: Omit<Config, 'inputs'>): Promise<Messages|void>;
export function url(href: string, config?: Omit<Config, 'inputs'>): Promise<Report>;
export function fs(path: string, config?: Omit<Config, 'inputs'>): Promise<Report>;
export function run(config?: Config, options?: Argv): Promise<Report>;
export function config(options?: Argv): Promise<Config>;
export declare class Assertion extends Error {
rule: string;
constructor(message: string, rule: string);
}