58 lines
2.0 KiB
JavaScript
58 lines
2.0 KiB
JavaScript
import * as Attributes from './api/attributes.js';
|
|
import * as Traversing from './api/traversing.js';
|
|
import * as Manipulation from './api/manipulation.js';
|
|
import * as Css from './api/css.js';
|
|
import * as Forms from './api/forms.js';
|
|
import * as Extract from './api/extract.js';
|
|
/**
|
|
* The cheerio class is the central class of the library. It wraps a set of
|
|
* elements and provides an API for traversing, modifying, and interacting with
|
|
* the set.
|
|
*
|
|
* Loading a document will return the Cheerio class bound to the root element of
|
|
* the document. The class will be instantiated when querying the document (when
|
|
* calling `$('selector')`).
|
|
*
|
|
* @example This is the HTML markup we will be using in all of the API examples:
|
|
*
|
|
* ```html
|
|
* <ul id="fruits">
|
|
* <li class="apple">Apple</li>
|
|
* <li class="orange">Orange</li>
|
|
* <li class="pear">Pear</li>
|
|
* </ul>
|
|
* ```
|
|
*/
|
|
export class Cheerio {
|
|
/**
|
|
* Instance of cheerio. Methods are specified in the modules. Usage of this
|
|
* constructor is not recommended. Please use `$.load` instead.
|
|
*
|
|
* @private
|
|
* @param elements - The new selection.
|
|
* @param root - Sets the root node.
|
|
* @param options - Options for the instance.
|
|
*/
|
|
constructor(elements, root, options) {
|
|
this.length = 0;
|
|
this.options = options;
|
|
this._root = root;
|
|
if (elements) {
|
|
for (let idx = 0; idx < elements.length; idx++) {
|
|
this[idx] = elements[idx];
|
|
}
|
|
this.length = elements.length;
|
|
}
|
|
}
|
|
}
|
|
/** Set a signature of the object. */
|
|
Cheerio.prototype.cheerio = '[cheerio object]';
|
|
/*
|
|
* Make cheerio an array-like object
|
|
*/
|
|
Cheerio.prototype.splice = Array.prototype.splice;
|
|
// Support for (const element of $(...)) iteration:
|
|
Cheerio.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
|
|
// Plug in the API
|
|
Object.assign(Cheerio.prototype, Attributes, Traversing, Manipulation, Css, Forms, Extract);
|
|
//# sourceMappingURL=cheerio.js.map
|