cheerio.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import * as Attributes from './api/attributes.js';
  2. import * as Traversing from './api/traversing.js';
  3. import * as Manipulation from './api/manipulation.js';
  4. import * as Css from './api/css.js';
  5. import * as Forms from './api/forms.js';
  6. export class Cheerio {
  7. /**
  8. * Instance of cheerio. Methods are specified in the modules. Usage of this
  9. * constructor is not recommended. Please use `$.load` instead.
  10. *
  11. * @private
  12. * @param elements - The new selection.
  13. * @param root - Sets the root node.
  14. * @param options - Options for the instance.
  15. */
  16. constructor(elements, root, options) {
  17. this.length = 0;
  18. this.options = options;
  19. this._root = root;
  20. if (elements) {
  21. for (let idx = 0; idx < elements.length; idx++) {
  22. this[idx] = elements[idx];
  23. }
  24. this.length = elements.length;
  25. }
  26. }
  27. }
  28. /** Set a signature of the object. */
  29. Cheerio.prototype.cheerio = '[cheerio object]';
  30. /*
  31. * Make cheerio an array-like object
  32. */
  33. Cheerio.prototype.splice = Array.prototype.splice;
  34. // Support for (const element of $(...)) iteration:
  35. Cheerio.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  36. // Plug in the API
  37. Object.assign(Cheerio.prototype, Attributes, Traversing, Manipulation, Css, Forms);
  38. //# sourceMappingURL=cheerio.js.map