cheerio.js 3.5 KB

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