forked from LeaVerou/parsel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
86 lines (74 loc) · 1.55 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Type definitions for parsel-js 1.0.2
// Project: https://github.com/LeaVerou/parsel
// Definitions by:
// - Matt Oxley <https://github.com/mattflux>
// - Naveen DA <https://github.com/NaveenDA>
// Definitions: https://github.com/LeaVerou/parsel/blob/master/index.d.ts
interface Tokens {
type:
| "class"
| "attribute"
| "id"
| "type"
| "pseudo-element"
| "pseudo-class"
| "comma"
| "combinator";
content: string;
name: string;
namespace?: string;
value?: string;
pos: [number, number];
operator?: string;
argument?: string;
subtree?: AST;
caseSensitive?: "i";
}
interface Complex {
type: "complex";
combinator: string;
right: AST;
left: AST;
}
interface Compound {
type: "compound";
list: Tokens[];
}
interface List {
type: "list";
list: AST[];
}
interface ParserOptions {
recursive?: boolean;
list?: boolean;
}
interface SpecificityOptions {
format?: string;
}
type AST = Complex | Compound | List | Tokens;
/**
* Get AST:
*/
export function parse(selector: string, options?: ParserOptions): AST;
/**
* Get list of tokens as a flat array:
*/
export function tokenize(selector: string): Tokens[];
/**
* Traverse all tokens of a (sub)tree:
*/
export function walk(node: AST, cb: (node: AST, parentNode: AST) => {}): void;
/**
* Calculate specificity (returns an array of 3 numbers):
*/
export function specificity(
selector: string | AST,
options?: SpecificityOptions
): number[];
/**
* To convert the specificity array to a number
*/
export function specificityToNumber(
specificity: number[],
base?: number
): number;