aboutsummaryrefslogtreecommitdiff
path: root/node_modules/cheerio/lib/cheerio.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-02-09 17:58:07 +0100
committerMinteck <contact@minteck.org>2022-02-09 17:58:07 +0100
commit22a25ded9f7d9c9a96cce8d1bc12475ca0434201 (patch)
tree0e33d0650fe58f41c00bbc4b8047956905766823 /node_modules/cheerio/lib/cheerio.js
parent8f54d903fb3470823a5e4d6ff4655de009836245 (diff)
downloadyoutoo-22a25ded9f7d9c9a96cce8d1bc12475ca0434201.tar.gz
youtoo-22a25ded9f7d9c9a96cce8d1bc12475ca0434201.tar.bz2
youtoo-22a25ded9f7d9c9a96cce8d1bc12475ca0434201.zip
Major update
Diffstat (limited to 'node_modules/cheerio/lib/cheerio.js')
-rw-r--r--node_modules/cheerio/lib/cheerio.js115
1 files changed, 115 insertions, 0 deletions
diff --git a/node_modules/cheerio/lib/cheerio.js b/node_modules/cheerio/lib/cheerio.js
new file mode 100644
index 0000000..d14143e
--- /dev/null
+++ b/node_modules/cheerio/lib/cheerio.js
@@ -0,0 +1,115 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.Cheerio = void 0;
+var tslib_1 = require("tslib");
+var parse_1 = tslib_1.__importDefault(require("./parse"));
+var options_1 = tslib_1.__importDefault(require("./options"));
+var utils_1 = require("./utils");
+var Attributes = tslib_1.__importStar(require("./api/attributes"));
+var Traversing = tslib_1.__importStar(require("./api/traversing"));
+var Manipulation = tslib_1.__importStar(require("./api/manipulation"));
+var Css = tslib_1.__importStar(require("./api/css"));
+var Forms = tslib_1.__importStar(require("./api/forms"));
+var Cheerio = /** @class */ (function () {
+ /**
+ * Instance of cheerio. Methods are specified in the modules. Usage of this
+ * constructor is not recommended. Please use $.load instead.
+ *
+ * @private
+ * @param selector - The new selection.
+ * @param context - Context of the selection.
+ * @param root - Sets the root node.
+ * @param options - Options for the instance.
+ */
+ function Cheerio(selector, context, root, options) {
+ var _this = this;
+ if (options === void 0) { options = options_1.default; }
+ this.length = 0;
+ this.options = options;
+ // $(), $(null), $(undefined), $(false)
+ if (!selector)
+ return this;
+ if (root) {
+ if (typeof root === 'string')
+ root = parse_1.default(root, this.options, false);
+ this._root = new this.constructor(root, null, null, this.options);
+ // Add a cyclic reference, so that calling methods on `_root` never fails.
+ this._root._root = this._root;
+ }
+ // $($)
+ if (utils_1.isCheerio(selector))
+ return selector;
+ var elements = typeof selector === 'string' && utils_1.isHtml(selector)
+ ? // $(<html>)
+ parse_1.default(selector, this.options, false).children
+ : isNode(selector)
+ ? // $(dom)
+ [selector]
+ : Array.isArray(selector)
+ ? // $([dom])
+ selector
+ : null;
+ if (elements) {
+ elements.forEach(function (elem, idx) {
+ _this[idx] = elem;
+ });
+ this.length = elements.length;
+ return this;
+ }
+ // We know that our selector is a string now.
+ var search = selector;
+ var searchContext = !context
+ ? // If we don't have a context, maybe we have a root, from loading
+ this._root
+ : typeof context === 'string'
+ ? utils_1.isHtml(context)
+ ? // $('li', '<ul>...</ul>')
+ this._make(parse_1.default(context, this.options, false))
+ : // $('li', 'ul')
+ ((search = context + " " + search), this._root)
+ : utils_1.isCheerio(context)
+ ? // $('li', $)
+ context
+ : // $('li', node), $('li', [nodes])
+ this._make(context);
+ // If we still don't have a context, return
+ if (!searchContext)
+ return this;
+ /*
+ * #id, .class, tag
+ */
+ // @ts-expect-error No good way to type this — we will always return `Cheerio<Element>` here.
+ return searchContext.find(search);
+ }
+ /**
+ * Make a cheerio object.
+ *
+ * @private
+ * @param dom - The contents of the new object.
+ * @param context - The context of the new object.
+ * @returns The new cheerio object.
+ */
+ Cheerio.prototype._make = function (dom, context) {
+ var cheerio = new this.constructor(dom, context, this._root, this.options);
+ cheerio.prevObject = this;
+ return cheerio;
+ };
+ return Cheerio;
+}());
+exports.Cheerio = Cheerio;
+/** 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);
+function isNode(obj) {
+ return (!!obj.name ||
+ obj.type === 'root' ||
+ obj.type === 'text' ||
+ obj.type === 'comment');
+}