UNPKG

9.27 kBTypeScriptView Raw
1// Type definitions for Cheerio v0.22.0
2// Project: https://github.com/cheeriojs/cheerio
3// Definitions by: Bret Little <https://github.com/blittle>, VILIC VANE <http://vilic.info>, Wayne Maurer <https://github.com/wmaurer>, Umar Nizamani <https://github.com/umarniz>, LiJinyao <https://github.com/LiJinyao>, Chennakrishna <https://github.com/chennakrishna8>, AzSiAz <https://github.com/AzSiAz>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6interface Cheerio {
7 // Document References
8 // Cheerio https://github.com/cheeriojs/cheerio
9 // JQuery http://api.jquery.com
10
11 [index: number]: CheerioElement;
12 length: number;
13
14 // Attributes
15
16 attr(): {[attr: string]: string};
17 attr(name: string): string;
18 attr(name: string, value: any): Cheerio;
19
20 data(): any;
21 data(name: string): any;
22 data(name: string, value: any): any;
23
24 val(): string;
25 val(value: string): Cheerio;
26
27 removeAttr(name: string): Cheerio;
28
29 has(selector: string): Cheerio;
30 has(element: CheerioElement): Cheerio;
31
32 hasClass(className: string): boolean;
33 addClass(classNames: string): Cheerio;
34
35 removeClass(): Cheerio;
36 removeClass(className: string): Cheerio;
37 removeClass(func: (index: number, className: string) => string): Cheerio;
38
39 toggleClass(className: string): Cheerio;
40 toggleClass(className: string, toggleSwitch: boolean): Cheerio;
41 toggleClass(toggleSwitch?: boolean): Cheerio;
42 toggleClass(func: (index: number, className: string, toggleSwitch: boolean) => string, toggleSwitch?: boolean): Cheerio;
43
44 is(selector: string): boolean;
45 is(element: CheerioElement): boolean;
46 is(element: CheerioElement[]): boolean;
47 is(selection: Cheerio): boolean;
48 is(func: (index: number, element: CheerioElement) => boolean): boolean;
49
50 // Form
51 serialize(): string;
52 serializeArray(): {name: string, value: string}[];
53
54 // Traversing
55
56 find(selector: string): Cheerio;
57 find(element: Cheerio): Cheerio;
58
59 parent(selector?: string): Cheerio;
60 parents(selector?: string): Cheerio;
61 parentsUntil(selector?: string, filter?: string): Cheerio;
62 parentsUntil(element: CheerioElement, filter?: string): Cheerio;
63 parentsUntil(element: Cheerio, filter?: string): Cheerio;
64
65 prop(name: string): any;
66 prop(name: string, value: any): Cheerio;
67
68 closest(): Cheerio;
69 closest(selector: string): Cheerio;
70
71 next(selector?: string): Cheerio;
72 nextAll(): Cheerio;
73 nextAll(selector: string): Cheerio;
74
75 nextUntil(selector?: string, filter?: string): Cheerio;
76 nextUntil(element: CheerioElement, filter?: string): Cheerio;
77 nextUntil(element: Cheerio, filter?: string): Cheerio;
78
79 prev(selector?: string): Cheerio;
80 prevAll(): Cheerio;
81 prevAll(selector: string): Cheerio;
82
83 prevUntil(selector?: string, filter?: string): Cheerio;
84 prevUntil(element: CheerioElement, filter?: string): Cheerio;
85 prevUntil(element: Cheerio, filter?: string): Cheerio;
86
87 slice(start: number, end?: number): Cheerio;
88
89 siblings(selector?: string): Cheerio;
90
91 children(selector?: string): Cheerio;
92
93 contents(): Cheerio;
94
95 each(func: (index: number, element: CheerioElement) => any): Cheerio;
96 map(func: (index: number, element: CheerioElement) => any): Cheerio;
97
98 filter(selector: string): Cheerio;
99 filter(selection: Cheerio): Cheerio;
100 filter(element: CheerioElement): Cheerio;
101 filter(elements: CheerioElement[]): Cheerio;
102 filter(func: (index: number, element: CheerioElement) => boolean): Cheerio;
103
104 not(selector: string): Cheerio;
105 not(selection: Cheerio): Cheerio;
106 not(element: CheerioElement): Cheerio;
107 not(func: (index: number, element: CheerioElement) => boolean): Cheerio;
108
109 first(): Cheerio;
110 last(): Cheerio;
111
112 eq(index: number): Cheerio;
113
114 get(): any[];
115 get(index: number): any;
116
117 index(): number;
118 index(selector: string): number;
119 index(selection: Cheerio): number;
120
121 end(): Cheerio;
122
123 add(selectorOrHtml: string): Cheerio;
124 add(selector: string, context: Document): Cheerio;
125 add(element: CheerioElement): Cheerio;
126 add(elements: CheerioElement[]): Cheerio;
127 add(selection: Cheerio): Cheerio;
128
129 addBack():Cheerio;
130 addBack(filter: string):Cheerio;
131
132 // Manipulation
133 appendTo(target: Cheerio) : Cheerio
134 prependTo(target: Cheerio) : Cheerio
135
136 append(content: string, ...contents: any[]): Cheerio;
137 append(content: Document, ...contents: any[]): Cheerio;
138 append(content: Document[], ...contents: any[]): Cheerio;
139 append(content: Cheerio, ...contents: any[]): Cheerio;
140
141 prepend(content: string, ...contents: any[]): Cheerio;
142 prepend(content: Document, ...contents: any[]): Cheerio;
143 prepend(content: Document[], ...contents: any[]): Cheerio;
144 prepend(content: Cheerio, ...contents: any[]): Cheerio;
145
146 after(content: string, ...contents: any[]): Cheerio;
147 after(content: Document, ...contents: any[]): Cheerio;
148 after(content: Document[], ...contents: any[]): Cheerio;
149 after(content: Cheerio, ...contents: any[]): Cheerio;
150
151 insertAfter(content: string): Cheerio;
152 insertAfter(content: Document): Cheerio;
153 insertAfter(content: Cheerio): Cheerio;
154
155 before(content: string, ...contents: any[]): Cheerio;
156 before(content: Document, ...contents: any[]): Cheerio;
157 before(content: Document[], ...contents: any[]): Cheerio;
158 before(content: Cheerio, ...contents: any[]): Cheerio;
159
160 insertBefore(content: string): Cheerio;
161 insertBefore(content: Document): Cheerio;
162 insertBefore(content: Cheerio): Cheerio;
163
164 remove(selector?: string): Cheerio;
165
166 replaceWith(content: string): Cheerio;
167 replaceWith(content: CheerioElement): Cheerio;
168 replaceWith(content: CheerioElement[]): Cheerio;
169 replaceWith(content: Cheerio): Cheerio;
170 replaceWith(content: () => Cheerio): Cheerio;
171
172 empty(): Cheerio;
173
174 html(): string | null;
175 html(html: string): Cheerio;
176
177 text(): string;
178 text(text: string): Cheerio;
179
180 wrap(content: string): Cheerio;
181 wrap(content: Document): Cheerio;
182 wrap(content: Cheerio): Cheerio;
183
184 css(propertyName: string): string;
185 css(propertyNames: string[]): string[];
186 css(propertyName: string, value: string): Cheerio;
187 css(propertyName: string, value: number): Cheerio;
188 css(propertyName: string, func: (index: number, value: string) => string): Cheerio;
189 css(propertyName: string, func: (index: number, value: string) => number): Cheerio;
190 css(properties: Object): Cheerio;
191
192 // Rendering
193
194 // Miscellaneous
195
196 clone(): Cheerio;
197
198 // Not Documented
199
200 toArray(): CheerioElement[];
201}
202
203interface CheerioOptionsInterface {
204 // Document References
205 // Cheerio https://github.com/cheeriojs/cheerio
206 // HTMLParser2 https://github.com/fb55/htmlparser2/wiki/Parser-options
207 // DomHandler https://github.com/fb55/DomHandler
208
209 xmlMode?: boolean;
210 decodeEntities?: boolean;
211 lowerCaseTags?: boolean;
212 lowerCaseAttributeNames?: boolean;
213 recognizeCDATA?: boolean;
214 recognizeSelfClosing?: boolean;
215 normalizeWhitespace?: boolean;
216 ignoreWhitespace?: boolean;
217}
218
219interface CheerioSelector {
220 (selector: string): Cheerio;
221 (selector: string, context: string): Cheerio;
222 (selector: string, context: CheerioElement): Cheerio;
223 (selector: string, context: CheerioElement[]): Cheerio;
224 (selector: string, context: Cheerio): Cheerio;
225 (selector: string, context: string, root: string): Cheerio;
226 (selector: string, context: CheerioElement, root: string): Cheerio;
227 (selector: string, context: CheerioElement[], root: string): Cheerio;
228 (selector: string, context: Cheerio, root: string): Cheerio;
229 (selector: any): Cheerio;
230}
231
232interface CheerioStatic extends CheerioSelector {
233 // Document References
234 // Cheerio https://github.com/cheeriojs/cheerio
235 // JQuery http://api.jquery.com
236 xml(): string;
237 root(): Cheerio;
238 contains(container: CheerioElement, contained: CheerioElement): boolean;
239 parseHTML(data: string, context?: Document, keepScripts?: boolean): Document[];
240
241 html(options?: CheerioOptionsInterface): string;
242 html(selector: string, options?: CheerioOptionsInterface): string;
243 html(element: Cheerio, options?: CheerioOptionsInterface): string;
244 html(element: CheerioElement, options?: CheerioOptionsInterface): string;
245}
246
247interface CheerioElement {
248 // Document References
249 // Node Console
250 tagName: string;
251 type: string;
252 name: string;
253 attribs: {[attr: string]: string};
254 children: CheerioElement[];
255 childNodes: CheerioElement[];
256 lastChild: CheerioElement;
257 firstChild: CheerioElement;
258 next: CheerioElement;
259 nextSibling: CheerioElement;
260 prev: CheerioElement;
261 previousSibling: CheerioElement;
262 parent: CheerioElement;
263 parentNode: CheerioElement;
264 nodeValue: string;
265 data?: string;
266}
267
268interface CheerioAPI extends CheerioSelector, CheerioStatic {
269 load(html: string, options?: CheerioOptionsInterface): CheerioStatic;
270 load(element: CheerioElement, options?: CheerioOptionsInterface): CheerioStatic;
271}
272
273interface Document { }
274
275declare var cheerio:CheerioAPI;
276
277declare module "cheerio" {
278 export = cheerio;
279}