cheerio.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.Cheerio = void 0;
  27. const Attributes = __importStar(require("./api/attributes.js"));
  28. const Traversing = __importStar(require("./api/traversing.js"));
  29. const Manipulation = __importStar(require("./api/manipulation.js"));
  30. const Css = __importStar(require("./api/css.js"));
  31. const Forms = __importStar(require("./api/forms.js"));
  32. const Extract = __importStar(require("./api/extract.js"));
  33. /**
  34. * The cheerio class is the central class of the library. It wraps a set of
  35. * elements and provides an API for traversing, modifying, and interacting with
  36. * the set.
  37. *
  38. * Loading a document will return the Cheerio class bound to the root element of
  39. * the document. The class will be instantiated when querying the document (when
  40. * calling `$('selector')`).
  41. *
  42. * @example This is the HTML markup we will be using in all of the API examples:
  43. *
  44. * ```html
  45. * <ul id="fruits">
  46. * <li class="apple">Apple</li>
  47. * <li class="orange">Orange</li>
  48. * <li class="pear">Pear</li>
  49. * </ul>
  50. * ```
  51. */
  52. class Cheerio {
  53. /**
  54. * Instance of cheerio. Methods are specified in the modules. Usage of this
  55. * constructor is not recommended. Please use `$.load` instead.
  56. *
  57. * @private
  58. * @param elements - The new selection.
  59. * @param root - Sets the root node.
  60. * @param options - Options for the instance.
  61. */
  62. constructor(elements, root, options) {
  63. this.length = 0;
  64. this.options = options;
  65. this._root = root;
  66. if (elements) {
  67. for (let idx = 0; idx < elements.length; idx++) {
  68. this[idx] = elements[idx];
  69. }
  70. this.length = elements.length;
  71. }
  72. }
  73. }
  74. exports.Cheerio = Cheerio;
  75. /** Set a signature of the object. */
  76. Cheerio.prototype.cheerio = '[cheerio object]';
  77. /*
  78. * Make cheerio an array-like object
  79. */
  80. Cheerio.prototype.splice = Array.prototype.splice;
  81. // Support for (const element of $(...)) iteration:
  82. Cheerio.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  83. // Plug in the API
  84. Object.assign(Cheerio.prototype, Attributes, Traversing, Manipulation, Css, Forms, Extract);
  85. //# sourceMappingURL=cheerio.js.map