diff options
author | Minteck <contact@minteck.org> | 2022-02-09 17:58:07 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-02-09 17:58:07 +0100 |
commit | 22a25ded9f7d9c9a96cce8d1bc12475ca0434201 (patch) | |
tree | 0e33d0650fe58f41c00bbc4b8047956905766823 /node_modules/cheerio/lib | |
parent | 8f54d903fb3470823a5e4d6ff4655de009836245 (diff) | |
download | youtoo-22a25ded9f7d9c9a96cce8d1bc12475ca0434201.tar.gz youtoo-22a25ded9f7d9c9a96cce8d1bc12475ca0434201.tar.bz2 youtoo-22a25ded9f7d9c9a96cce8d1bc12475ca0434201.zip |
Major update
Diffstat (limited to 'node_modules/cheerio/lib')
45 files changed, 5195 insertions, 0 deletions
diff --git a/node_modules/cheerio/lib/api/attributes.d.ts b/node_modules/cheerio/lib/api/attributes.d.ts new file mode 100644 index 0000000..208b0c7 --- /dev/null +++ b/node_modules/cheerio/lib/api/attributes.d.ts @@ -0,0 +1,317 @@ +/** + * Methods for getting and modifying attributes. + * + * @module cheerio/attributes + */ +import type { Node, Element } from 'domhandler'; +import type { Cheerio } from '../cheerio'; +/** + * Method for getting attributes. Gets the attribute value for only the first + * element in the matched set. + * + * @category Attributes + * @example + * + * ```js + * $('ul').attr('id'); + * //=> fruits + * ``` + * + * @param name - Name of the attribute. + * @returns The attribute's value. + * @see {@link https://api.jquery.com/attr/} + */ +export declare function attr<T extends Node>(this: Cheerio<T>, name: string): string | undefined; +/** + * Method for getting all attributes and their values of the first element in + * the matched set. + * + * @category Attributes + * @example + * + * ```js + * $('ul').attr(); + * //=> { id: 'fruits' } + * ``` + * + * @returns The attribute's values. + * @see {@link https://api.jquery.com/attr/} + */ +export declare function attr<T extends Node>(this: Cheerio<T>): Record<string, string>; +/** + * Method for setting attributes. Sets the attribute value for only the first + * element in the matched set. If you set an attribute's value to `null`, you + * remove that attribute. You may also pass a `map` and `function`. + * + * @category Attributes + * @example + * + * ```js + * $('.apple').attr('id', 'favorite').html(); + * //=> <li class="apple" id="favorite">Apple</li> + * ``` + * + * @param name - Name of the attribute. + * @param value - The new value of the attribute. + * @returns The instance itself. + * @see {@link https://api.jquery.com/attr/} + */ +export declare function attr<T extends Node>(this: Cheerio<T>, name: string, value?: string | null | ((this: Element, i: number, attrib: string) => string | null)): Cheerio<T>; +/** + * Method for setting multiple attributes at once. Sets the attribute value for + * only the first element in the matched set. If you set an attribute's value to + * `null`, you remove that attribute. + * + * @category Attributes + * @example + * + * ```js + * $('.apple').attr({ id: 'favorite' }).html(); + * //=> <li class="apple" id="favorite">Apple</li> + * ``` + * + * @param values - Map of attribute names and values. + * @returns The instance itself. + * @see {@link https://api.jquery.com/attr/} + */ +export declare function attr<T extends Node>(this: Cheerio<T>, values: Record<string, string | null>): Cheerio<T>; +interface StyleProp { + length: number; + [key: string]: string | number; + [index: number]: string; +} +/** + * Method for getting and setting properties. Gets the property value for only + * the first element in the matched set. + * + * @category Attributes + * @example + * + * ```js + * $('input[type="checkbox"]').prop('checked'); + * //=> false + * + * $('input[type="checkbox"]').prop('checked', true).val(); + * //=> ok + * ``` + * + * @param name - Name of the property. + * @param value - If specified set the property to this. + * @returns If `value` is specified the instance itself, otherwise the prop's value. + * @see {@link https://api.jquery.com/prop/} + */ +export declare function prop<T extends Node>(this: Cheerio<T>, name: 'tagName' | 'nodeName'): T extends Element ? string : undefined; +export declare function prop<T extends Node>(this: Cheerio<T>, name: 'innerHTML' | 'outerHTML'): string | null; +export declare function prop<T extends Node>(this: Cheerio<T>, name: 'style'): StyleProp; +export declare function prop<T extends Node, K extends keyof Element>(this: Cheerio<T>, name: K): Element[K]; +export declare function prop<T extends Node, K extends keyof Element>(this: Cheerio<T>, name: K, value: Element[K] | ((this: Element, i: number, prop: K) => Element[keyof Element])): Cheerio<T>; +export declare function prop<T extends Node>(this: Cheerio<T>, name: Record<string, string | Element[keyof Element] | boolean>): Cheerio<T>; +export declare function prop<T extends Node>(this: Cheerio<T>, name: string, value: string | boolean | null | ((this: Element, i: number, prop: string) => string | boolean)): Cheerio<T>; +export declare function prop<T extends Node>(this: Cheerio<T>, name: string): string; +/** + * Method for getting data attributes, for only the first element in the matched set. + * + * @category Attributes + * @example + * + * ```js + * $('<div data-apple-color="red"></div>').data('apple-color'); + * //=> 'red' + * ``` + * + * @param name - Name of the data attribute. + * @returns The data attribute's value. + * @see {@link https://api.jquery.com/data/} + */ +export declare function data<T extends Node>(this: Cheerio<T>, name: string): unknown | undefined; +/** + * Method for getting all of an element's data attributes, for only the first + * element in the matched set. + * + * @category Attributes + * @example + * + * ```js + * $('<div data-apple-color="red"></div>').data(); + * //=> { appleColor: 'red' } + * ``` + * + * @returns The data attribute's values. + * @see {@link https://api.jquery.com/data/} + */ +export declare function data<T extends Node>(this: Cheerio<T>): Record<string, unknown>; +/** + * Method for setting data attributes, for only the first element in the matched set. + * + * @category Attributes + * @example + * + * ```js + * const apple = $('.apple').data('kind', 'mac'); + * + * apple.data('kind'); + * //=> 'mac' + * ``` + * + * @param name - Name of the data attribute. + * @param value - The new value. + * @returns The instance itself. + * @see {@link https://api.jquery.com/data/} + */ +export declare function data<T extends Node>(this: Cheerio<T>, name: string, value: unknown): Cheerio<T>; +/** + * Method for setting multiple data attributes at once, for only the first + * element in the matched set. + * + * @category Attributes + * @example + * + * ```js + * const apple = $('.apple').data({ kind: 'mac' }); + * + * apple.data('kind'); + * //=> 'mac' + * ``` + * + * @param values - Map of names to values. + * @returns The instance itself. + * @see {@link https://api.jquery.com/data/} + */ +export declare function data<T extends Node>(this: Cheerio<T>, values: Record<string, unknown>): Cheerio<T>; +/** + * Method for getting the value of input, select, and textarea. Note: Support + * for `map`, and `function` has not been added yet. + * + * @category Attributes + * @example + * + * ```js + * $('input[type="text"]').val(); + * //=> input_text + * ``` + * + * @returns The value. + * @see {@link https://api.jquery.com/val/} + */ +export declare function val<T extends Node>(this: Cheerio<T>): string | undefined | string[]; +/** + * Method for setting the value of input, select, and textarea. Note: Support + * for `map`, and `function` has not been added yet. + * + * @category Attributes + * @example + * + * ```js + * $('input[type="text"]').val('test').html(); + * //=> <input type="text" value="test"/> + * ``` + * + * @param value - The new value. + * @returns The instance itself. + * @see {@link https://api.jquery.com/val/} + */ +export declare function val<T extends Node>(this: Cheerio<T>, value: string | string[]): Cheerio<T>; +/** + * Method for removing attributes by `name`. + * + * @category Attributes + * @example + * + * ```js + * $('.pear').removeAttr('class').html(); + * //=> <li>Pear</li> + * + * $('.apple').attr('id', 'favorite'); + * $('.apple').removeAttr('id class').html(); + * //=> <li>Apple</li> + * ``` + * + * @param name - Name of the attribute. + * @returns The instance itself. + * @see {@link https://api.jquery.com/removeAttr/} + */ +export declare function removeAttr<T extends Node>(this: Cheerio<T>, name: string): Cheerio<T>; +/** + * Check to see if *any* of the matched elements have the given `className`. + * + * @category Attributes + * @example + * + * ```js + * $('.pear').hasClass('pear'); + * //=> true + * + * $('apple').hasClass('fruit'); + * //=> false + * + * $('li').hasClass('pear'); + * //=> true + * ``` + * + * @param className - Name of the class. + * @returns Indicates if an element has the given `className`. + * @see {@link https://api.jquery.com/hasClass/} + */ +export declare function hasClass<T extends Node>(this: Cheerio<T>, className: string): boolean; +/** + * Adds class(es) to all of the matched elements. Also accepts a `function`. + * + * @category Attributes + * @example + * + * ```js + * $('.pear').addClass('fruit').html(); + * //=> <li class="pear fruit">Pear</li> + * + * $('.apple').addClass('fruit red').html(); + * //=> <li class="apple fruit red">Apple</li> + * ``` + * + * @param value - Name of new class. + * @returns The instance itself. + * @see {@link https://api.jquery.com/addClass/} + */ +export declare function addClass<T extends Node, R extends ArrayLike<T>>(this: R, value?: string | ((this: Element, i: number, className: string) => string | undefined)): R; +/** + * Removes one or more space-separated classes from the selected elements. If no + * `className` is defined, all classes will be removed. Also accepts a `function`. + * + * @category Attributes + * @example + * + * ```js + * $('.pear').removeClass('pear').html(); + * //=> <li class="">Pear</li> + * + * $('.apple').addClass('red').removeClass().html(); + * //=> <li class="">Apple</li> + * ``` + * + * @param name - Name of the class. If not specified, removes all elements. + * @returns The instance itself. + * @see {@link https://api.jquery.com/removeClass/} + */ +export declare function removeClass<T extends Node, R extends ArrayLike<T>>(this: R, name?: string | ((this: Element, i: number, className: string) => string | undefined)): R; +/** + * Add or remove class(es) from the matched elements, depending on either the + * class's presence or the value of the switch argument. Also accepts a `function`. + * + * @category Attributes + * @example + * + * ```js + * $('.apple.green').toggleClass('fruit green red').html(); + * //=> <li class="apple fruit red">Apple</li> + * + * $('.apple.green').toggleClass('fruit green red', true).html(); + * //=> <li class="apple green fruit red">Apple</li> + * ``` + * + * @param value - Name of the class. Can also be a function. + * @param stateVal - If specified the state of the class. + * @returns The instance itself. + * @see {@link https://api.jquery.com/toggleClass/} + */ +export declare function toggleClass<T extends Node, R extends ArrayLike<T>>(this: R, value?: string | ((this: Element, i: number, className: string, stateVal?: boolean) => string), stateVal?: boolean): R; +export {}; +//# sourceMappingURL=attributes.d.ts.map
\ No newline at end of file diff --git a/node_modules/cheerio/lib/api/attributes.d.ts.map b/node_modules/cheerio/lib/api/attributes.d.ts.map new file mode 100644 index 0000000..c0b4fee --- /dev/null +++ b/node_modules/cheerio/lib/api/attributes.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/api/attributes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AA6F1C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,SAAS,CAAC;AACtB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MA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;;;GAoBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,EACrC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,SAAS,EAAE,MAAM,GAChB,OAAO,CAoBT;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAC7D,IAAI,EAAE,CAAC,EACP,KAAK,CAAC,EACF,MAAM,GACN,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC,GACxE,CAAC,CAyCH;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAChE,IAAI,EAAE,CAAC,EACP,IAAI,CAAC,EACD,MAAM,GACN,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC,GACxE,CAAC,CA0CH;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAChE,IAAI,EAAE,CAAC,EACP,KAAK,CAAC,EACF,MAAM,GACN,CAAC,CACC,IAAI,EAAE,OAAO,EACb,CAAC,EAAE,MAAM,EACT,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,OAAO,KACf,MAAM,CAAC,EAChB,QAAQ,CAAC,EAAE,OAAO,GACjB,CAAC,CA+CH"}
\ No newline at end of file diff --git a/node_modules/cheerio/lib/api/attributes.js b/node_modules/cheerio/lib/api/attributes.js new file mode 100644 index 0000000..d67d310 --- /dev/null +++ b/node_modules/cheerio/lib/api/attributes.js @@ -0,0 +1,591 @@ +"use strict"; +/** + * Methods for getting and modifying attributes. + * + * @module cheerio/attributes + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.toggleClass = exports.removeClass = exports.addClass = exports.hasClass = exports.removeAttr = exports.val = exports.data = exports.prop = exports.attr = void 0; +var static_1 = require("../static"); +var utils_1 = require("../utils"); +var hasOwn = Object.prototype.hasOwnProperty; +var rspace = /\s+/; +var dataAttrPrefix = 'data-'; +/* + * Lookup table for coercing string data-* attributes to their corresponding + * JavaScript primitives + */ +var primitives = { + null: null, + true: true, + false: false, +}; +// Attributes that are booleans +var rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i; +// Matches strings that look like JSON objects or arrays +var rbrace = /^{[^]*}$|^\[[^]*]$/; +function getAttr(elem, name, xmlMode) { + var _a; + if (!elem || !utils_1.isTag(elem)) + return undefined; + (_a = elem.attribs) !== null && _a !== void 0 ? _a : (elem.attribs = {}); + // Return the entire attribs object if no attribute specified + if (!name) { + return elem.attribs; + } + if (hasOwn.call(elem.attribs, name)) { + // Get the (decoded) attribute + return !xmlMode && rboolean.test(name) ? name : elem.attribs[name]; + } + // Mimic the DOM and return text content as value for `option's` + if (elem.name === 'option' && name === 'value') { + return static_1.text(elem.children); + } + // Mimic DOM with default value for radios/checkboxes + if (elem.name === 'input' && + (elem.attribs.type === 'radio' || elem.attribs.type === 'checkbox') && + name === 'value') { + return 'on'; + } + return undefined; +} +/** + * Sets the value of an attribute. The attribute will be deleted if the value is `null`. + * + * @private + * @param el - The element to set the attribute on. + * @param name - The attribute's name. + * @param value - The attribute's value. + */ +function setAttr(el, name, value) { + if (value === null) { + removeAttribute(el, name); + } + else { + el.attribs[name] = "" + value; + } +} +function attr(name, value) { + // Set the value (with attr map support) + if (typeof name === 'object' || value !== undefined) { + if (typeof value === 'function') { + if (typeof name !== 'string') { + { + throw new Error('Bad combination of arguments.'); + } + } + return utils_1.domEach(this, function (el, i) { + if (utils_1.isTag(el)) + setAttr(el, name, value.call(el, i, el.attribs[name])); + }); + } + return utils_1.domEach(this, function (el) { + if (!utils_1.isTag(el)) + return; + if (typeof name === 'object') { + Object.keys(name).forEach(function (objName) { + var objValue = name[objName]; + setAttr(el, objName, objValue); + }); + } + else { + setAttr(el, name, value); + } + }); + } + return arguments.length > 1 + ? this + : getAttr(this[0], name, this.options.xmlMode); +} +exports.attr = attr; +/** + * Gets a node's prop. + * + * @private + * @category Attributes + * @param el - Elenent to get the prop of. + * @param name - Name of the prop. + * @returns The prop's value. + */ +function getProp(el, name, xmlMode) { + if (!el || !utils_1.isTag(el)) + return; + return name in el + ? // @ts-expect-error TS doesn't like us accessing the value directly here. + el[name] + : !xmlMode && rboolean.test(name) + ? getAttr(el, name, false) !== undefined + : getAttr(el, name, xmlMode); +} +/** + * Sets the value of a prop. + * + * @private + * @param el - The element to set the prop on. + * @param name - The prop's name. + * @param value - The prop's value. + */ +function setProp(el, name, value, xmlMode) { + if (name in el) { + // @ts-expect-error Overriding value + el[name] = value; + } + else { + setAttr(el, name, !xmlMode && rboolean.test(name) ? (value ? '' : null) : "" + value); + } +} +function prop(name, value) { + var _this = this; + if (typeof name === 'string' && value === undefined) { + switch (name) { + case 'style': { + var property_1 = this.css(); + var keys = Object.keys(property_1); + keys.forEach(function (p, i) { + property_1[i] = p; + }); + property_1.length = keys.length; + return property_1; + } + case 'tagName': + case 'nodeName': { + var el = this[0]; + return utils_1.isTag(el) ? el.name.toUpperCase() : undefined; + } + case 'outerHTML': + return this.clone().wrap('<container />').parent().html(); + case 'innerHTML': + return this.html(); + default: + return getProp(this[0], name, this.options.xmlMode); + } + } + if (typeof name === 'object' || value !== undefined) { + if (typeof value === 'function') { + if (typeof name === 'object') { + throw new Error('Bad combination of arguments.'); + } + return utils_1.domEach(this, function (el, i) { + if (utils_1.isTag(el)) + setProp(el, name, value.call(el, i, getProp(el, name, _this.options.xmlMode)), _this.options.xmlMode); + }); + } + return utils_1.domEach(this, function (el) { + if (!utils_1.isTag(el)) + return; + if (typeof name === 'object') { + Object.keys(name).forEach(function (key) { + var val = name[key]; + setProp(el, key, val, _this.options.xmlMode); + }); + } + else { + setProp(el, name, value, _this.options.xmlMode); + } + }); + } + return undefined; +} +exports.prop = prop; +/** + * Sets the value of a data attribute. + * + * @private + * @param el - The element to set the data attribute on. + * @param name - The data attribute's name. + * @param value - The data attribute's value. + */ +function setData(el, name, value) { + var _a; + var elem = el; + (_a = elem.data) !== null && _a !== void 0 ? _a : (elem.data = {}); + if (typeof name === 'object') + Object.assign(elem.data, name); + else if (typeof name === 'string' && value !== undefined) { + elem.data[name] = value; + } +} +/** + * Read the specified attribute from the equivalent HTML5 `data-*` attribute, + * and (if present) cache the value in the node's internal data store. If no + * attribute name is specified, read *all* HTML5 `data-*` attributes in this manner. + * + * @private + * @category Attributes + * @param el - Elenent to get the data attribute of. + * @param name - Name of the data attribute. + * @returns The data attribute's value, or a map with all of the data attribute. + */ +function readData(el, name) { + var domNames; + var jsNames; + var value; + if (name == null) { + domNames = Object.keys(el.attribs).filter(function (attrName) { + return attrName.startsWith(dataAttrPrefix); + }); + jsNames = domNames.map(function (domName) { + return utils_1.camelCase(domName.slice(dataAttrPrefix.length)); + }); + } + else { + domNames = [dataAttrPrefix + utils_1.cssCase(name)]; + jsNames = [name]; + } + for (var idx = 0; idx < domNames.length; ++idx) { + var domName = domNames[idx]; + var jsName = jsNames[idx]; + if (hasOwn.call(el.attribs, domName) && + !hasOwn.call(el.data, jsName)) { + value = el.attribs[domName]; + if (hasOwn.call(primitives, value)) { + value = primitives[value]; + } + else if (value === String(Number(value))) { + value = Number(value); + } + else if (rbrace.test(value)) { + try { + value = JSON.parse(value); + } + catch (e) { + /* Ignore */ + } + } + el.data[jsName] = value; + } + } + return name == null ? el.data : value; +} +function data(name, value) { + var _a; + var elem = this[0]; + if (!elem || !utils_1.isTag(elem)) + return; + var dataEl = elem; + (_a = dataEl.data) !== null && _a !== void 0 ? _a : (dataEl.data = {}); + // Return the entire data object if no data specified + if (!name) { + return readData(dataEl); + } + // Set the value (with attr map support) + if (typeof name === 'object' || value !== undefined) { + utils_1.domEach(this, function (el) { + if (utils_1.isTag(el)) + if (typeof name === 'object') + setData(el, name); + else + setData(el, name, value); + }); + return this; + } + if (hasOwn.call(dataEl.data, name)) { + return dataEl.data[name]; + } + return readData(dataEl, name); +} +exports.data = data; +function val(value) { + var querying = arguments.length === 0; + var element = this[0]; + if (!element || !utils_1.isTag(element)) + return querying ? undefined : this; + switch (element.name) { + case 'textarea': + return this.text(value); + case 'select': { + var option = this.find('option:selected'); + if (!querying) { + if (this.attr('multiple') == null && typeof value === 'object') { + return this; + } + this.find('option').removeAttr('selected'); + var values = typeof value !== 'object' ? [value] : value; + for (var i = 0; i < values.length; i++) { + this.find("option[value=\"" + values[i] + "\"]").attr('selected', ''); + } + return this; + } + return this.attr('multiple') + ? option.toArray().map(function (el) { return static_1.text(el.children); }) + : option.attr('value'); + } + case 'input': + case 'option': + return querying + ? this.attr('value') + : this.attr('value', value); + } + return undefined; +} +exports.val = val; +/** + * Remove an attribute. + * + * @private + * @param elem - Node to remove attribute from. + * @param name - Name of the attribute to remove. + */ +function removeAttribute(elem, name) { + if (!elem.attribs || !hasOwn.call(elem.attribs, name)) + return; + delete elem.attribs[name]; +} +/** + * Splits a space-separated list of names to individual names. + * + * @category Attributes + * @param names - Names to split. + * @returns - Split names. + */ +function splitNames(names) { + return names ? names.trim().split(rspace) : []; +} +/** + * Method for removing attributes by `name`. + * + * @category Attributes + * @example + * + * ```js + * $('.pear').removeAttr('class').html(); + * //=> <li>Pear</li> + * + * $('.apple').attr('id', 'favorite'); + * $('.apple').removeAttr('id class').html(); + * //=> <li>Apple</li> + * ``` + * + * @param name - Name of the attribute. + * @returns The instance itself. + * @see {@link https://api.jquery.com/removeAttr/} + */ +function removeAttr(name) { + var attrNames = splitNames(name); + var _loop_1 = function (i) { + utils_1.domEach(this_1, function (elem) { + if (utils_1.isTag(elem)) + removeAttribute(elem, attrNames[i]); + }); + }; + var this_1 = this; + for (var i = 0; i < attrNames.length; i++) { + _loop_1(i); + } + return this; +} +exports.removeAttr = removeAttr; +/** + * Check to see if *any* of the matched elements have the given `className`. + * + * @category Attributes + * @example + * + * ```js + * $('.pear').hasClass('pear'); + * //=> true + * + * $('apple').hasClass('fruit'); + * //=> false + * + * $('li').hasClass('pear'); + * //=> true + * ``` + * + * @param className - Name of the class. + * @returns Indicates if an element has the given `className`. + * @see {@link https://api.jquery.com/hasClass/} + */ +function hasClass(className) { + return this.toArray().some(function (elem) { + var clazz = utils_1.isTag(elem) && elem.attribs.class; + var idx = -1; + if (clazz && className.length) { + while ((idx = clazz.indexOf(className, idx + 1)) > -1) { + var end = idx + className.length; + if ((idx === 0 || rspace.test(clazz[idx - 1])) && + (end === clazz.length || rspace.test(clazz[end]))) { + return true; + } + } + } + return false; + }); +} +exports.hasClass = hasClass; +/** + * Adds class(es) to all of the matched elements. Also accepts a `function`. + * + * @category Attributes + * @example + * + * ```js + * $('.pear').addClass('fruit').html(); + * //=> <li class="pear fruit">Pear</li> + * + * $('.apple').addClass('fruit red').html(); + * //=> <li class="apple fruit red">Apple</li> + * ``` + * + * @param value - Name of new class. + * @returns The instance itself. + * @see {@link https://api.jquery.com/addClass/} + */ +function addClass(value) { + // Support functions + if (typeof value === 'function') { + return utils_1.domEach(this, function (el, i) { + if (utils_1.isTag(el)) { + var className = el.attribs.class || ''; + addClass.call([el], value.call(el, i, className)); + } + }); + } + // Return if no value or not a string or function + if (!value || typeof value !== 'string') + return this; + var classNames = value.split(rspace); + var numElements = this.length; + for (var i = 0; i < numElements; i++) { + var el = this[i]; + // If selected element isn't a tag, move on + if (!utils_1.isTag(el)) + continue; + // If we don't already have classes — always set xmlMode to false here, as it doesn't matter for classes + var className = getAttr(el, 'class', false); + if (!className) { + setAttr(el, 'class', classNames.join(' ').trim()); + } + else { + var setClass = " " + className + " "; + // Check if class already exists + for (var j = 0; j < classNames.length; j++) { + var appendClass = classNames[j] + " "; + if (!setClass.includes(" " + appendClass)) + setClass += appendClass; + } + setAttr(el, 'class', setClass.trim()); + } + } + return this; +} +exports.addClass = addClass; +/** + * Removes one or more space-separated classes from the selected elements. If no + * `className` is defined, all classes will be removed. Also accepts a `function`. + * + * @category Attributes + * @example + * + * ```js + * $('.pear').removeClass('pear').html(); + * //=> <li class="">Pear</li> + * + * $('.apple').addClass('red').removeClass().html(); + * //=> <li class="">Apple</li> + * ``` + * + * @param name - Name of the class. If not specified, removes all elements. + * @returns The instance itself. + * @see {@link https://api.jquery.com/removeClass/} + */ +function removeClass(name) { + // Handle if value is a function + if (typeof name === 'function') { + return utils_1.domEach(this, function (el, i) { + if (utils_1.isTag(el)) + removeClass.call([el], name.call(el, i, el.attribs.class || '')); + }); + } + var classes = splitNames(name); + var numClasses = classes.length; + var removeAll = arguments.length === 0; + return utils_1.domEach(this, function (el) { + if (!utils_1.isTag(el)) + return; + if (removeAll) { + // Short circuit the remove all case as this is the nice one + el.attribs.class = ''; + } + else { + var elClasses = splitNames(el.attribs.class); + var changed = false; + for (var j = 0; j < numClasses; j++) { + var index = elClasses.indexOf(classes[j]); + if (index >= 0) { + elClasses.splice(index, 1); + changed = true; + /* + * We have to do another pass to ensure that there are not duplicate + * classes listed + */ + j--; + } + } + if (changed) { + el.attribs.class = elClasses.join(' '); + } + } + }); +} +exports.removeClass = removeClass; +/** + * Add or remove class(es) from the matched elements, depending on either the + * class's presence or the value of the switch argument. Also accepts a `function`. + * + * @category Attributes + * @example + * + * ```js + * $('.apple.green').toggleClass('fruit green red').html(); + * //=> <li class="apple fruit red">Apple</li> + * + * $('.apple.green').toggleClass('fruit green red', true).html(); + * //=> <li class="apple green fruit red">Apple</li> + * ``` + * + * @param value - Name of the class. Can also be a function. + * @param stateVal - If specified the state of the class. + * @returns The instance itself. + * @see {@link https://api.jquery.com/toggleClass/} + */ +function toggleClass(value, stateVal) { + // Support functions + if (typeof value === 'function') { + return utils_1.domEach(this, function (el, i) { + if (utils_1.isTag(el)) { + toggleClass.call([el], value.call(el, i, el.attribs.class || '', stateVal), stateVal); + } + }); + } + // Return if no value or not a string or function + if (!value || typeof value !== 'string') + return this; + var classNames = value.split(rspace); + var numClasses = classNames.length; + var state = typeof stateVal === 'boolean' ? (stateVal ? 1 : -1) : 0; + var numElements = this.length; + for (var i = 0; i < numElements; i++) { + var el = this[i]; + // If selected element isn't a tag, move on + if (!utils_1.isTag(el)) + continue; + var elementClasses = splitNames(el.attribs.class); + // Check if class already exists + for (var j = 0; j < numClasses; j++) { + // Check if the class name is currently defined + var index = elementClasses.indexOf(classNames[j]); + // Add if stateValue === true or we are toggling and there is no value + if (state >= 0 && index < 0) { + elementClasses.push(classNames[j]); + } + else if (state <= 0 && index >= 0) { + // Otherwise remove but only if the item exists + elementClasses.splice(index, 1); + } + } + el.attribs.class = elementClasses.join(' '); + } + return this; +} +exports.toggleClass = toggleClass; diff --git a/node_modules/cheerio/lib/api/css.d.ts b/node_modules/cheerio/lib/api/css.d.ts new file mode 100644 index 0000000..f63d3b4 --- /dev/null +++ b/node_modules/cheerio/lib/api/css.d.ts @@ -0,0 +1,41 @@ +import type { Element, Node } from 'domhandler'; +import type { Cheerio } from '../cheerio'; +/** + * Get the value of a style property for the first element in the set of matched elements. + * + * @category CSS + * @param names - Optionally the names of the property of interest. + * @returns A map of all of the style properties. + * @see {@link https://api.jquery.com/css/} + */ +export declare function css<T extends Node>(this: Cheerio<T>, names?: string[]): Record<string, string>; +/** + * Get the value of a style property for the first element in the set of matched elements. + * + * @category CSS + * @param names - The name of the property. + * @returns The property value for the given name. + * @see {@link https://api.jquery.com/css/} + */ +export declare function css<T extends Node>(this: Cheerio<T>, name: string): string | undefined; +/** + * Set one CSS property for every matched element. + * + * @category CSS + * @param prop - The name of the property. + * @param val - The new value. + * @returns The instance itself. + * @see {@link https://api.jquery.com/css/} + */ +export declare function css<T extends Node>(this: Cheerio<T>, prop: string, val: string | ((this: Element, i: number, style: string) => string | undefined)): Cheerio<T>; +/** + * Set multiple CSS properties for every matched element. + * + * @category CSS + * @param prop - The name of the property. + * @param val - The new value. + * @returns The instance itself. + * @see {@link https://api.jquery.com/css/} + */ +export declare function css<T extends Node>(this: Cheerio<T>, prop: Record<string, string>): Cheerio<T>; +//# sourceMappingURL=css.d.ts.map
\ No newline at end of file diff --git a/node_modules/cheerio/lib/api/css.d.ts.map b/node_modules/cheerio/lib/api/css.d.ts.map new file mode 100644 index 0000000..8d2e7d4 --- /dev/null +++ b/node_modules/cheerio/lib/api/css.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../src/api/css.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,IAAI,EAChC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,KAAK,CAAC,EAAE,MAAM,EAAE,GACf,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC1B;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,IAAI,EAChC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,SAAS,CAAC;AACtB;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,IAAI,EAChC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,MAAM,EACZ,GAAG,EACC,MAAM,GACN,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC,GACpE,OAAO,CAAC,CAAC,CAAC,CAAC;AACd;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,IAAI,EAChC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3B,OAAO,CAAC,CAAC,CAAC,CAAC"}
\ No newline at end of file diff --git a/node_modules/cheerio/lib/api/css.js b/node_modules/cheerio/lib/api/css.js new file mode 100644 index 0000000..aa7ad09 --- /dev/null +++ b/node_modules/cheerio/lib/api/css.js @@ -0,0 +1,95 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.css = void 0; +var utils_1 = require("../utils"); +function css(prop, val) { + if ((prop != null && val != null) || + // When `prop` is a "plain" object + (typeof prop === 'object' && !Array.isArray(prop))) { + return utils_1.domEach(this, function (el, i) { + if (utils_1.isTag(el)) { + // `prop` can't be an array here anymore. + setCss(el, prop, val, i); + } + }); + } + return getCss(this[0], prop); +} +exports.css = css; +/** + * Set styles of all elements. + * + * @private + * @param el - Element to set style of. + * @param prop - Name of property. + * @param value - Value to set property to. + * @param idx - Optional index within the selection. + */ +function setCss(el, prop, value, idx) { + if (typeof prop === 'string') { + var styles = getCss(el); + var val = typeof value === 'function' ? value.call(el, idx, styles[prop]) : value; + if (val === '') { + delete styles[prop]; + } + else if (val != null) { + styles[prop] = val; + } + el.attribs.style = stringify(styles); + } + else if (typeof prop === 'object') { + Object.keys(prop).forEach(function (k, i) { + setCss(el, k, prop[k], i); + }); + } +} +function getCss(el, prop) { + if (!el || !utils_1.isTag(el)) + return; + var styles = parse(el.attribs.style); + if (typeof prop === 'string') { + return styles[prop]; + } + if (Array.isArray(prop)) { + var newStyles_1 = {}; + prop.forEach(function (item) { + if (styles[item] != null) { + newStyles_1[item] = styles[item]; + } + }); + return newStyles_1; + } + return styles; +} +/** + * Stringify `obj` to styles. + * + * @private + * @category CSS + * @param obj - Object to stringify. + * @returns The serialized styles. + */ +function stringify(obj) { + return Object.keys(obj).reduce(function (str, prop) { return "" + str + (str ? ' ' : '') + prop + ": " + obj[prop] + ";"; }, ''); +} +/** + * Parse `styles`. + * + * @private + * @category CSS + * @param styles - Styles to be parsed. + * @returns The parsed styles. + */ +function parse(styles) { + styles = (styles || '').trim(); + if (!styles) + return {}; + return styles.split(';').reduce(function (obj, str) { + var n = str.indexOf(':'); + // Skip if there is no :, or if it is the first/last character + if (n < 1 || n === str.length - 1) + return obj; + obj[str.slice(0, n).trim()] = str.slice(n + 1).trim(); + return obj; + }, {}); +} diff --git a/node_modules/cheerio/lib/api/forms.d.ts b/node_modules/cheerio/lib/api/forms.d.ts new file mode 100644 index 0000000..32f8739 --- /dev/null +++ b/node_modules/cheerio/lib/api/forms.d.ts @@ -0,0 +1,31 @@ +import type { Node } from 'domhandler'; +import type { Cheerio } from '../cheerio'; +/** + * Encode a set of form elements as a string for submission. + * + * @category Forms + * @returns The serialized form. + * @see {@link https://api.jquery.com/serialize/} + */ +export declare function serialize<T extends Node>(this: Cheerio<T>): string; +interface SerializedField { + name: string; + value: string; +} +/** + * Encode a set of form elements as an array of names and values. + * + * @category Forms + * @example + * + * ```js + * $('<form><input name="foo" value="bar" /></form>').serializeArray(); + * //=> [ { name: 'foo', value: 'bar' } ] + * ``` + * + * @returns The serialized form. + * @see {@link https://api.jquery.com/serializeArray/} + */ +export declare function serializeArray<T extends Node>(this: Cheerio<T>): SerializedField[]; +export {}; +//# sourceMappingURL=forms.d.ts.map
\ No newline at end of file diff --git a/node_modules/cheerio/lib/api/forms.d.ts.map b/node_modules/cheerio/lib/api/forms.d.ts.map new file mode 100644 index 0000000..ee25744 --- /dev/null +++ b/node_modules/cheerio/lib/api/forms.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"forms.d.ts","sourceRoot":"","sources":["../../src/api/forms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAW1C;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAYlE;AAED,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,IAAI,EAC3C,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GACf,eAAe,EAAE,CAsCnB"}
\ No newline at end of file diff --git a/node_modules/cheerio/lib/api/forms.js b/node_modules/cheerio/lib/api/forms.js new file mode 100644 index 0000000..2e881c5 --- /dev/null +++ b/node_modules/cheerio/lib/api/forms.js @@ -0,0 +1,84 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.serializeArray = exports.serialize = void 0; +var utils_1 = require("../utils"); +/* + * https://github.com/jquery/jquery/blob/2.1.3/src/manipulation/var/rcheckableType.js + * https://github.com/jquery/jquery/blob/2.1.3/src/serialize.js + */ +var submittableSelector = 'input,select,textarea,keygen'; +var r20 = /%20/g; +var rCRLF = /\r?\n/g; +/** + * Encode a set of form elements as a string for submission. + * + * @category Forms + * @returns The serialized form. + * @see {@link https://api.jquery.com/serialize/} + */ +function serialize() { + // Convert form elements into name/value objects + var arr = this.serializeArray(); + // Serialize each element into a key/value string + var retArr = arr.map(function (data) { + return encodeURIComponent(data.name) + "=" + encodeURIComponent(data.value); + }); + // Return the resulting serialization + return retArr.join('&').replace(r20, '+'); +} +exports.serialize = serialize; +/** + * Encode a set of form elements as an array of names and values. + * + * @category Forms + * @example + * + * ```js + * $('<form><input name="foo" value="bar" /></form>').serializeArray(); + * //=> [ { name: 'foo', value: 'bar' } ] + * ``` + * + * @returns The serialized form. + * @see {@link https://api.jquery.com/serializeArray/} + */ +function serializeArray() { + var _this = this; + // Resolve all form elements from either forms or collections of form elements + return this.map(function (_, elem) { + var $elem = _this._make(elem); + if (utils_1.isTag(elem) && elem.name === 'form') { + return $elem.find(submittableSelector).toArray(); + } + return $elem.filter(submittableSelector).toArray(); + }) + .filter( + // Verify elements have a name (`attr.name`) and are not disabled (`:enabled`) + '[name!=""]:enabled' + + // And cannot be clicked (`[type=submit]`) or are used in `x-www-form-urlencoded` (`[type=file]`) + ':not(:submit, :button, :image, :reset, :file)' + + // And are either checked/don't have a checkable state + ':matches([checked], :not(:checkbox, :radio))' + // Convert each of the elements to its value(s) + ) + .map(function (_, elem) { + var _a; + var $elem = _this._make(elem); + var name = $elem.attr('name'); // We have filtered for elements with a name before. + // If there is no value set (e.g. `undefined`, `null`), then default value to empty + var value = (_a = $elem.val()) !== null && _a !== void 0 ? _a : ''; + // If we have an array of values (e.g. `<select multiple>`), return an array of key/value pairs + if (Array.isArray(value)) { + return value.map(function (val) { + /* + * We trim replace any line endings (e.g. `\r` or `\r\n` with `\r\n`) to guarantee consistency across platforms + * These can occur inside of `<textarea>'s` + */ + return ({ name: name, value: val.replace(rCRLF, '\r\n') }); + }); + } + // Otherwise (e.g. `<input type="text">`, return only one key/value pair + return { name: name, value: value.replace(rCRLF, '\r\n') }; + }) + .toArray(); +} +exports.serializeArray = serializeArray; diff --git a/node_modules/cheerio/lib/api/manipulation.d.ts b/node_modules/cheerio/lib/api/manipulation.d.ts new file mode 100644 index 0000000..1d2ec9b --- /dev/null +++ b/node_modules/cheerio/lib/api/manipulation.d.ts @@ -0,0 +1,496 @@ +/** + * Methods for modifying the DOM structure. + * + * @module cheerio/manipulation + */ +import { Node } from 'domhandler'; +import type { Cheerio } from '../cheerio'; +import type { BasicAcceptedElems, AcceptedElems } from '../types'; +/** + * Create an array of nodes, recursing into arrays and parsing strings if necessary. + * + * @private + * @category Manipulation + * @param elem - Elements to make an array of. + * @param clone - Optionally clone nodes. + * @returns The array of nodes. + */ +export declare function _makeDomArray<T extends Node>(this: Cheerio<T>, elem?: BasicAcceptedElems<Node>, clone?: boolean): Node[]; +/** + * Insert every element in the set of matched elements to the end of the target. + * + * @category Manipulation + * @example + * + * ```js + * $('<li class="plum">Plum</li>').appendTo('#fruits'); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="apple">Apple</li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // <li class="plum">Plum</li> + * // </ul> + * ``` + * + * @param target - Element to append elements to. + * @returns The instance itself. + * @see {@link https://api.jquery.com/appendTo/} + */ +export declare function appendTo<T extends Node>(this: Cheerio<T>, target: BasicAcceptedElems<Node>): Cheerio<T>; +/** + * Insert every element in the set of matched elements to the beginning of the target. + * + * @category Manipulation + * @example + * + * ```js + * $('<li class="plum">Plum</li>').prependTo('#fruits'); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="plum">Plum</li> + * // <li class="apple">Apple</li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // </ul> + * ``` + * + * @param target - Element to prepend elements to. + * @returns The instance itself. + * @see {@link https://api.jquery.com/prependTo/} + */ +export declare function prependTo<T extends Node>(this: Cheerio<T>, target: BasicAcceptedElems<Node>): Cheerio<T>; +/** + * Inserts content as the *last* child of each of the selected elements. + * + * @category Manipulation + * @example + * + * ```js + * $('ul').append('<li class="plum">Plum</li>'); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="apple">Apple</li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // <li class="plum">Plum</li> + * // </ul> + * ``` + * + * @see {@link https://api.jquery.com/append/} + */ +export declare const append: <T extends Node>(this: Cheerio<T>, ...elems: [(this: Node, i: number, html: string) => BasicAcceptedElems<Node>] | BasicAcceptedElems<Node>[]) => Cheerio<T>; +/** + * Inserts content as the *first* child of each of the selected elements. + * + * @category Manipulation + * @example + * + * ```js + * $('ul').prepend('<li class="plum">Plum</li>'); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="plum">Plum</li> + * // <li class="apple">Apple</li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // </ul> + * ``` + * + * @see {@link https://api.jquery.com/prepend/} + */ +export declare const prepend: <T extends Node>(this: Cheerio<T>, ...elems: [(this: Node, i: number, html: string) => BasicAcceptedElems<Node>] | BasicAcceptedElems<Node>[]) => Cheerio<T>; +/** + * The .wrap() function can take any string or object that could be passed to + * the $() factory function to specify a DOM structure. This structure may be + * nested several levels deep, but should contain only one inmost element. A + * copy of this structure will be wrapped around each of the elements in the set + * of matched elements. This method returns the original set of elements for + * chaining purposes. + * + * @category Manipulation + * @example + * + * ```js + * const redFruit = $('<div class="red-fruit"></div>'); + * $('.apple').wrap(redFruit); + * + * //=> <ul id="fruits"> + * // <div class="red-fruit"> + * // <li class="apple">Apple</li> + * // </div> + * // <li class="orange">Orange</li> + * // <li class="plum">Plum</li> + * // </ul> + * + * const healthy = $('<div class="healthy"></div>'); + * $('li').wrap(healthy); + * + * //=> <ul id="fruits"> + * // <div class="healthy"> + * // <li class="apple">Apple</li> + * // </div> + * // <div class="healthy"> + * // <li class="orange">Orange</li> + * // </div> + * // <div class="healthy"> + * // <li class="plum">Plum</li> + * // </div> + * // </ul> + * ``` + * + * @param wrapper - The DOM structure to wrap around each element in the selection. + * @see {@link https://api.jquery.com/wrap/} + */ +export declare const wrap: <T extends Node>(this: Cheerio<T>, wrapper: AcceptedElems<Node>) => Cheerio<T>; +/** + * The .wrapInner() function can take any string or object that could be passed + * to the $() factory function to specify a DOM structure. This structure may be + * nested several levels deep, but should contain only one inmost element. The + * structure will be wrapped around the content of each of the elements in the + * set of matched elements. + * + * @category Manipulation + * @example + * + * ```js + * const redFruit = $('<div class="red-fruit"></div>'); + * $('.apple').wrapInner(redFruit); + * + * //=> <ul id="fruits"> + * // <li class="apple"> + * // <div class="red-fruit">Apple</div> + * // </li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // </ul> + * + * const healthy = $('<div class="healthy"></div>'); + * $('li').wrapInner(healthy); + * + * //=> <ul id="fruits"> + * // <li class="apple"> + * // <div class="healthy">Apple</div> + * // </li> + * // <li class="orange"> + * // <div class="healthy">Orange</div> + * // </li> + * // <li class="pear"> + * // <div class="healthy">Pear</div> + * // </li> + * // </ul> + * ``` + * + * @param wrapper - The DOM structure to wrap around the content of each element + * in the selection. + * @returns The instance itself, for chaining. + * @see {@link https://api.jquery.com/wrapInner/} + */ +export declare const wrapInner: <T extends Node>(this: Cheerio<T>, wrapper: AcceptedElems<Node>) => Cheerio<T>; +/** + * The .unwrap() function, removes the parents of the set of matched elements + * from the DOM, leaving the matched elements in their place. + * + * @category Manipulation + * @example <caption>without selector</caption> + * + * ```js + * const $ = cheerio.load( + * '<div id=test>\n <div><p>Hello</p></div>\n <div><p>World</p></div>\n</div>' + * ); + * $('#test p').unwrap(); + * + * //=> <div id=test> + * // <p>Hello</p> + * // <p>World</p> + * // </div> + * ``` + * + * @example <caption>with selector</caption> + * + * ```js + * const $ = cheerio.load( + * '<div id=test>\n <p>Hello</p>\n <b><p>World</p></b>\n</div>' + * ); + * $('#test p').unwrap('b'); + * + * //=> <div id=test> + * // <p>Hello</p> + * // <p>World</p> + * // </div> + * ``` + * + * @param selector - A selector to check the parent element against. If an + * element's parent does not match the selector, the element won't be unwrapped. + * @returns The instance itself, for chaining. + * @see {@link https://api.jquery.com/unwrap/} + */ +export declare function unwrap<T extends Node>(this: Cheerio<T>, selector?: string): Cheerio<T>; +/** + * The .wrapAll() function can take any string or object that could be passed to + * the $() function to specify a DOM structure. This structure may be nested + * several levels deep, but should contain only one inmost element. The + * structure will be wrapped around all of the elements in the set of matched + * elements, as a single group. + * + * @category Manipulation + * @example <caption>With markup passed to `wrapAll`</caption> + * + * ```js + * const $ = cheerio.load( + * '<div class="container"><div class="inner">First</div><div class="inner">Second</div></div>' + * ); + * $('.inner').wrapAll("<div class='new'></div>"); + * + * //=> <div class="container"> + * // <div class='new'> + * // <div class="inner">First</div> + * // <div class="inner">Second</div> + * // </div> + * // </div> + * ``` + * + * @example <caption>With an existing cheerio instance</caption> + * + * ```js + * const $ = cheerio.load( + * '<span>Span 1</span><strong>Strong</strong><span>Span 2</span>' + * ); + * const wrap = $('<div><p><em><b></b></em></p></div>'); + * $('span').wrapAll(wrap); + * + * //=> <div> + * // <p> + * // <em> + * // <b> + * // <span>Span 1</span> + * // <span>Span 2</span> + * // </b> + * // </em> + * // </p> + * // </div> + * // <strong>Strong</strong> + * ``` + * + * @param wrapper - The DOM structure to wrap around all matched elements in the + * selection. + * @returns The instance itself. + * @see {@link https://api.jquery.com/wrapAll/} + */ +export declare function wrapAll<T extends Node>(this: Cheerio<T>, wrapper: AcceptedElems<T>): Cheerio<T>; +/** + * Insert content next to each element in the set of matched elements. + * + * @category Manipulation + * @example + * + * ```js + * $('.apple').after('<li class="plum">Plum</li>'); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="apple">Apple</li> + * // <li class="plum">Plum</li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // </ul> + * ``` + * + * @param content - HTML string, DOM element, array of DOM elements or Cheerio + * to insert after each element in the set of matched elements. + * @returns The instance itself. + * @see {@link https://api.jquery.com/after/} + */ +export declare function after<T extends Node>(this: Cheerio<T>, ...elems: [(this: Node, i: number, html: string) => BasicAcceptedElems<Node>] | BasicAcceptedElems<Node>[]): Cheerio<T>; +/** + * Insert every element in the set of matched elements after the target. + * + * @category Manipulation + * @example + * + * ```js + * $('<li class="plum">Plum</li>').insertAfter('.apple'); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="apple">Apple</li> + * // <li class="plum">Plum</li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // </ul> + * ``` + * + * @param target - Element to insert elements after. + * @returns The set of newly inserted elements. + * @see {@link https://api.jquery.com/insertAfter/} + */ +export declare function insertAfter<T extends Node>(this: Cheerio<T>, target: BasicAcceptedElems<Node>): Cheerio<T>; +/** + * Insert content previous to each element in the set of matched elements. + * + * @category Manipulation + * @example + * + * ```js + * $('.apple').before('<li class="plum">Plum</li>'); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="plum">Plum</li> + * // <li class="apple">Apple</li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // </ul> + * ``` + * + * @param content - HTML string, DOM element, array of DOM elements or Cheerio + * to insert before each element in the set of matched elements. + * @returns The instance itself. + * @see {@link https://api.jquery.com/before/} + */ +export declare function before<T extends Node>(this: Cheerio<T>, ...elems: [(this: Node, i: number, html: string) => BasicAcceptedElems<Node>] | BasicAcceptedElems<Node>[]): Cheerio<T>; +/** + * Insert every element in the set of matched elements before the target. + * + * @category Manipulation + * @example + * + * ```js + * $('<li class="plum">Plum</li>').insertBefore('.apple'); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="plum">Plum</li> + * // <li class="apple">Apple</li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // </ul> + * ``` + * + * @param target - Element to insert elements before. + * @returns The set of newly inserted elements. + * @see {@link https://api.jquery.com/insertBefore/} + */ +export declare function insertBefore<T extends Node>(this: Cheerio<T>, target: BasicAcceptedElems<Node>): Cheerio<T>; +/** + * Removes the set of matched elements from the DOM and all their children. + * `selector` filters the set of matched elements to be removed. + * + * @category Manipulation + * @example + * + * ```js + * $('.pear').remove(); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="apple">Apple</li> + * // <li class="orange">Orange</li> + * // </ul> + * ``` + * + * @param selector - Optional selector for elements to remove. + * @returns The instance itself. + * @see {@link https://api.jquery.com/remove/} + */ +export declare function remove<T extends Node>(this: Cheerio<T>, selector?: string): Cheerio<T>; +/** + * Replaces matched elements with `content`. + * + * @category Manipulation + * @example + * + * ```js + * const plum = $('<li class="plum">Plum</li>'); + * $('.pear').replaceWith(plum); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="apple">Apple</li> + * // <li class="orange">Orange</li> + * // <li class="plum">Plum</li> + * // </ul> + * ``` + * + * @param content - Replacement for matched elements. + * @returns The instance itself. + * @see {@link https://api.jquery.com/replaceWith/} + */ +export declare function replaceWith<T extends Node>(this: Cheerio<T>, content: AcceptedElems<Node>): Cheerio<T>; +/** + * Empties an element, removing all its children. + * + * @category Manipulation + * @example + * + * ```js + * $('ul').empty(); + * $.html(); + * //=> <ul id="fruits"></ul> + * ``` + * + * @returns The instance itself. + * @see {@link https://api.jquery.com/empty/} + */ +export declare function empty<T extends Node>(this: Cheerio<T>): Cheerio<T>; +/** + * Gets an HTML content string from the first selected element. If `htmlString` + * is specified, each selected element's content is replaced by the new content. + * + * @category Manipulation + * @example + * + * ```js + * $('.orange').html(); + * //=> Orange + * + * $('#fruits').html('<li class="mango">Mango</li>').html(); + * //=> <li class="mango">Mango</li> + * ``` + * + * @param str - If specified used to replace selection's contents. + * @returns The instance itself. + * @see {@link https://api.jquery.com/html/} + */ +export declare function html<T extends Node>(this: Cheerio<T>): string | null; +export declare function html<T extends Node>(this: Cheerio<T>, str: string | Cheerio<T>): Cheerio<T>; +/** + * Turns the collection to a string. Alias for `.html()`. + * + * @category Manipulation + * @returns The rendered document. + */ +export declare function toString<T extends Node>(this: Cheerio<T>): string; +/** + * Get the combined text contents of each element in the set of matched + * elements, including their descendants. If `textString` is specified, each + * selected element's content is replaced by the new text content. + * + * @category Manipulation + * @example + * + * ```js + * $('.orange').text(); + * //=> Orange + * + * $('ul').text(); + * //=> Apple + * // Orange + * // Pear + * ``` + * + * @param str - If specified replacement for the selected element's contents. + * @returns The instance itself when setting text, otherwise the rendered document. + * @see {@link https://api.jquery.com/text/} + */ +export declare function text<T extends Node>(this: Cheerio<T>): string; +export declare function text<T extends Node>(this: Cheerio<T>, str: string | ((this: Node, i: number, text: string) => string)): Cheerio<T>; +/** + * Clone the cheerio object. + * + * @category Manipulation + * @example + * + * ```js + * const moreFruit = $('#fruits').clone(); + * ``` + * + * @returns The cloned object. + * @see {@link https://api.jquery.com/clone/} + */ +export declare function clone<T extends Node>(this: Cheerio<T>): Cheerio<T>; +//# sourceMappingURL=manipulation.d.ts.map
\ No newline at end of file diff --git a/node_modules/cheerio/lib/api/manipulation.d.ts.map b/node_modules/cheerio/lib/api/manipulation.d.ts.map new file mode 100644 index 0000000..9d68655 --- /dev/null +++ b/node_modules/cheerio/lib/api/man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AAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,GACvB,OAAO,CAAC,CAAC,CAAC,CAAC;AA8Bd;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAEjE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;AAC/D,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,GAC9D,OAAO,CAAC,CAAC,CAAC,CAAC;AA6Bd;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAElE"}
\ No newline at end of file diff --git a/node_modules/cheerio/lib/api/manipulation.js b/node_modules/cheerio/lib/api/manipulation.js new file mode 100644 index 0000000..d84808d --- /dev/null +++ b/node_modules/cheerio/lib/api/manipulation.js @@ -0,0 +1,852 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.clone = exports.text = exports.toString = exports.html = exports.empty = exports.replaceWith = exports.remove = exports.insertBefore = exports.before = exports.insertAfter = exports.after = exports.wrapAll = exports.unwrap = exports.wrapInner = exports.wrap = exports.prepend = exports.append = exports.prependTo = exports.appendTo = exports._makeDomArray = void 0; +var tslib_1 = require("tslib"); +var domhandler_1 = require("domhandler"); +/** + * Methods for modifying the DOM structure. + * + * @module cheerio/manipulation + */ +var domhandler_2 = require("domhandler"); +var parse_1 = tslib_1.__importStar(require("../parse")); +var static_1 = require("../static"); +var utils_1 = require("../utils"); +var htmlparser2_1 = require("htmlparser2"); +/** + * Create an array of nodes, recursing into arrays and parsing strings if necessary. + * + * @private + * @category Manipulation + * @param elem - Elements to make an array of. + * @param clone - Optionally clone nodes. + * @returns The array of nodes. + */ +function _makeDomArray(elem, clone) { + var _this = this; + if (elem == null) { + return []; + } + if (utils_1.isCheerio(elem)) { + return clone ? utils_1.cloneDom(elem.get()) : elem.get(); + } + if (Array.isArray(elem)) { + return elem.reduce(function (newElems, el) { return newElems.concat(_this._makeDomArray(el, clone)); }, []); + } + if (typeof elem === 'string') { + return parse_1.default(elem, this.options, false).children; + } + return clone ? utils_1.cloneDom([elem]) : [elem]; +} +exports._makeDomArray = _makeDomArray; +function _insert(concatenator) { + return function () { + var _this = this; + var elems = []; + for (var _i = 0; _i < arguments.length; _i++) { + elems[_i] = arguments[_i]; + } + var lastIdx = this.length - 1; + return utils_1.domEach(this, function (el, i) { + if (!domhandler_1.hasChildren(el)) + return; + var domSrc = typeof elems[0] === 'function' + ? elems[0].call(el, i, static_1.html(el.children)) + : elems; + var dom = _this._makeDomArray(domSrc, i < lastIdx); + concatenator(dom, el.children, el); + }); + }; +} +/** + * Modify an array in-place, removing some number of elements and adding new + * elements directly following them. + * + * @private + * @category Manipulation + * @param array - Target array to splice. + * @param spliceIdx - Index at which to begin changing the array. + * @param spliceCount - Number of elements to remove from the array. + * @param newElems - Elements to insert into the array. + * @param parent - The parent of the node. + * @returns The spliced array. + */ +function uniqueSplice(array, spliceIdx, spliceCount, newElems, parent) { + var _a, _b; + var spliceArgs = tslib_1.__spreadArray([ + spliceIdx, + spliceCount + ], newElems); + var prev = array[spliceIdx - 1] || null; + var next = array[spliceIdx + spliceCount] || null; + /* + * Before splicing in new elements, ensure they do not already appear in the + * current array. + */ + for (var idx = 0; idx < newElems.length; ++idx) { + var node = newElems[idx]; + var oldParent = node.parent; + if (oldParent) { + var prevIdx = oldParent.children.indexOf(newElems[idx]); + if (prevIdx > -1) { + oldParent.children.splice(prevIdx, 1); + if (parent === oldParent && spliceIdx > prevIdx) { + spliceArgs[0]--; + } + } + } + node.parent = parent; + if (node.prev) { + node.prev.next = (_a = node.next) !== null && _a !== void 0 ? _a : null; + } + if (node.next) { + node.next.prev = (_b = node.prev) !== null && _b !== void 0 ? _b : null; + } + node.prev = newElems[idx - 1] || prev; + node.next = newElems[idx + 1] || next; + } + if (prev) { + prev.next = newElems[0]; + } + if (next) { + next.prev = newElems[newElems.length - 1]; + } + return array.splice.apply(array, spliceArgs); +} +/** + * Insert every element in the set of matched elements to the end of the target. + * + * @category Manipulation + * @example + * + * ```js + * $('<li class="plum">Plum</li>').appendTo('#fruits'); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="apple">Apple</li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // <li class="plum">Plum</li> + * // </ul> + * ``` + * + * @param target - Element to append elements to. + * @returns The instance itself. + * @see {@link https://api.jquery.com/appendTo/} + */ +function appendTo(target) { + var appendTarget = utils_1.isCheerio(target) ? target : this._make(target); + appendTarget.append(this); + return this; +} +exports.appendTo = appendTo; +/** + * Insert every element in the set of matched elements to the beginning of the target. + * + * @category Manipulation + * @example + * + * ```js + * $('<li class="plum">Plum</li>').prependTo('#fruits'); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="plum">Plum</li> + * // <li class="apple">Apple</li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // </ul> + * ``` + * + * @param target - Element to prepend elements to. + * @returns The instance itself. + * @see {@link https://api.jquery.com/prependTo/} + */ +function prependTo(target) { + var prependTarget = utils_1.isCheerio(target) ? target : this._make(target); + prependTarget.prepend(this); + return this; +} +exports.prependTo = prependTo; +/** + * Inserts content as the *last* child of each of the selected elements. + * + * @category Manipulation + * @example + * + * ```js + * $('ul').append('<li class="plum">Plum</li>'); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="apple">Apple</li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // <li class="plum">Plum</li> + * // </ul> + * ``` + * + * @see {@link https://api.jquery.com/append/} + */ +exports.append = _insert(function (dom, children, parent) { + uniqueSplice(children, children.length, 0, dom, parent); +}); +/** + * Inserts content as the *first* child of each of the selected elements. + * + * @category Manipulation + * @example + * + * ```js + * $('ul').prepend('<li class="plum">Plum</li>'); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="plum">Plum</li> + * // <li class="apple">Apple</li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // </ul> + * ``` + * + * @see {@link https://api.jquery.com/prepend/} + */ +exports.prepend = _insert(function (dom, children, parent) { + uniqueSplice(children, 0, 0, dom, parent); +}); +function _wrap(insert) { + return function (wrapper) { + var lastIdx = this.length - 1; + var lastParent = this.parents().last(); + for (var i = 0; i < this.length; i++) { + var el = this[i]; + var wrap_1 = typeof wrapper === 'function' + ? wrapper.call(el, i, el) + : typeof wrapper === 'string' && !utils_1.isHtml(wrapper) + ? lastParent.find(wrapper).clone() + : wrapper; + var wrapperDom = this._makeDomArray(wrap_1, i < lastIdx)[0]; + if (!wrapperDom || !htmlparser2_1.DomUtils.hasChildren(wrapperDom)) + continue; + var elInsertLocation = wrapperDom; + /* + * Find the deepest child. Only consider the first tag child of each node + * (ignore text); stop if no children are found. + */ + var j = 0; + while (j < elInsertLocation.children.length) { + var child = elInsertLocation.children[j]; + if (utils_1.isTag(child)) { + elInsertLocation = child; + j = 0; + } + else { + j++; + } + } + insert(el, elInsertLocation, [wrapperDom]); + } + return this; + }; +} +/** + * The .wrap() function can take any string or object that could be passed to + * the $() factory function to specify a DOM structure. This structure may be + * nested several levels deep, but should contain only one inmost element. A + * copy of this structure will be wrapped around each of the elements in the set + * of matched elements. This method returns the original set of elements for + * chaining purposes. + * + * @category Manipulation + * @example + * + * ```js + * const redFruit = $('<div class="red-fruit"></div>'); + * $('.apple').wrap(redFruit); + * + * //=> <ul id="fruits"> + * // <div class="red-fruit"> + * // <li class="apple">Apple</li> + * // </div> + * // <li class="orange">Orange</li> + * // <li class="plum">Plum</li> + * // </ul> + * + * const healthy = $('<div class="healthy"></div>'); + * $('li').wrap(healthy); + * + * //=> <ul id="fruits"> + * // <div class="healthy"> + * // <li class="apple">Apple</li> + * // </div> + * // <div class="healthy"> + * // <li class="orange">Orange</li> + * // </div> + * // <div class="healthy"> + * // <li class="plum">Plum</li> + * // </div> + * // </ul> + * ``` + * + * @param wrapper - The DOM structure to wrap around each element in the selection. + * @see {@link https://api.jquery.com/wrap/} + */ +exports.wrap = _wrap(function (el, elInsertLocation, wrapperDom) { + var parent = el.parent; + if (!parent) + return; + var siblings = parent.children; + var index = siblings.indexOf(el); + parse_1.update([el], elInsertLocation); + /* + * The previous operation removed the current element from the `siblings` + * array, so the `dom` array can be inserted without removing any + * additional elements. + */ + uniqueSplice(siblings, index, 0, wrapperDom, parent); +}); +/** + * The .wrapInner() function can take any string or object that could be passed + * to the $() factory function to specify a DOM structure. This structure may be + * nested several levels deep, but should contain only one inmost element. The + * structure will be wrapped around the content of each of the elements in the + * set of matched elements. + * + * @category Manipulation + * @example + * + * ```js + * const redFruit = $('<div class="red-fruit"></div>'); + * $('.apple').wrapInner(redFruit); + * + * //=> <ul id="fruits"> + * // <li class="apple"> + * // <div class="red-fruit">Apple</div> + * // </li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // </ul> + * + * const healthy = $('<div class="healthy"></div>'); + * $('li').wrapInner(healthy); + * + * //=> <ul id="fruits"> + * // <li class="apple"> + * // <div class="healthy">Apple</div> + * // </li> + * // <li class="orange"> + * // <div class="healthy">Orange</div> + * // </li> + * // <li class="pear"> + * // <div class="healthy">Pear</div> + * // </li> + * // </ul> + * ``` + * + * @param wrapper - The DOM structure to wrap around the content of each element + * in the selection. + * @returns The instance itself, for chaining. + * @see {@link https://api.jquery.com/wrapInner/} + */ +exports.wrapInner = _wrap(function (el, elInsertLocation, wrapperDom) { + if (!domhandler_1.hasChildren(el)) + return; + parse_1.update(el.children, elInsertLocation); + parse_1.update(wrapperDom, el); +}); +/** + * The .unwrap() function, removes the parents of the set of matched elements + * from the DOM, leaving the matched elements in their place. + * + * @category Manipulation + * @example <caption>without selector</caption> + * + * ```js + * const $ = cheerio.load( + * '<div id=test>\n <div><p>Hello</p></div>\n <div><p>World</p></div>\n</div>' + * ); + * $('#test p').unwrap(); + * + * //=> <div id=test> + * // <p>Hello</p> + * // <p>World</p> + * // </div> + * ``` + * + * @example <caption>with selector</caption> + * + * ```js + * const $ = cheerio.load( + * '<div id=test>\n <p>Hello</p>\n <b><p>World</p></b>\n</div>' + * ); + * $('#test p').unwrap('b'); + * + * //=> <div id=test> + * // <p>Hello</p> + * // <p>World</p> + * // </div> + * ``` + * + * @param selector - A selector to check the parent element against. If an + * element's parent does not match the selector, the element won't be unwrapped. + * @returns The instance itself, for chaining. + * @see {@link https://api.jquery.com/unwrap/} + */ +function unwrap(selector) { + var _this = this; + this.parent(selector) + .not('body') + .each(function (_, el) { + _this._make(el).replaceWith(el.children); + }); + return this; +} +exports.unwrap = unwrap; +/** + * The .wrapAll() function can take any string or object that could be passed to + * the $() function to specify a DOM structure. This structure may be nested + * several levels deep, but should contain only one inmost element. The + * structure will be wrapped around all of the elements in the set of matched + * elements, as a single group. + * + * @category Manipulation + * @example <caption>With markup passed to `wrapAll`</caption> + * + * ```js + * const $ = cheerio.load( + * '<div class="container"><div class="inner">First</div><div class="inner">Second</div></div>' + * ); + * $('.inner').wrapAll("<div class='new'></div>"); + * + * //=> <div class="container"> + * // <div class='new'> + * // <div class="inner">First</div> + * // <div class="inner">Second</div> + * // </div> + * // </div> + * ``` + * + * @example <caption>With an existing cheerio instance</caption> + * + * ```js + * const $ = cheerio.load( + * '<span>Span 1</span><strong>Strong</strong><span>Span 2</span>' + * ); + * const wrap = $('<div><p><em><b></b></em></p></div>'); + * $('span').wrapAll(wrap); + * + * //=> <div> + * // <p> + * // <em> + * // <b> + * // <span>Span 1</span> + * // <span>Span 2</span> + * // </b> + * // </em> + * // </p> + * // </div> + * // <strong>Strong</strong> + * ``` + * + * @param wrapper - The DOM structure to wrap around all matched elements in the + * selection. + * @returns The instance itself. + * @see {@link https://api.jquery.com/wrapAll/} + */ +function wrapAll(wrapper) { + var el = this[0]; + if (el) { + var wrap_2 = this._make(typeof wrapper === 'function' ? wrapper.call(el, 0, el) : wrapper).insertBefore(el); + // If html is given as wrapper, wrap may contain text elements + var elInsertLocation = void 0; + for (var i = 0; i < wrap_2.length; i++) { + if (wrap_2[i].type === 'tag') + elInsertLocation = wrap_2[i]; + } + var j = 0; + /* + * Find the deepest child. Only consider the first tag child of each node + * (ignore text); stop if no children are found. + */ + while (elInsertLocation && j < elInsertLocation.children.length) { + var child = elInsertLocation.children[j]; + if (child.type === 'tag') { + elInsertLocation = child; + j = 0; + } + else { + j++; + } + } + if (elInsertLocation) + this._make(elInsertLocation).append(this); + } + return this; +} +exports.wrapAll = wrapAll; +/* eslint-disable jsdoc/check-param-names*/ +/** + * Insert content next to each element in the set of matched elements. + * + * @category Manipulation + * @example + * + * ```js + * $('.apple').after('<li class="plum">Plum</li>'); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="apple">Apple</li> + * // <li class="plum">Plum</li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // </ul> + * ``` + * + * @param content - HTML string, DOM element, array of DOM elements or Cheerio + * to insert after each element in the set of matched elements. + * @returns The instance itself. + * @see {@link https://api.jquery.com/after/} + */ +function after() { + var _this = this; + var elems = []; + for (var _i = 0; _i < arguments.length; _i++) { + elems[_i] = arguments[_i]; + } + var lastIdx = this.length - 1; + return utils_1.domEach(this, function (el, i) { + var parent = el.parent; + if (!htmlparser2_1.DomUtils.hasChildren(el) || !parent) { + return; + } + var siblings = parent.children; + var index = siblings.indexOf(el); + // If not found, move on + /* istanbul ignore next */ + if (index < 0) + return; + var domSrc = typeof elems[0] === 'function' + ? elems[0].call(el, i, static_1.html(el.children)) + : elems; + var dom = _this._makeDomArray(domSrc, i < lastIdx); + // Add element after `this` element + uniqueSplice(siblings, index + 1, 0, dom, parent); + }); +} +exports.after = after; +/* eslint-enable jsdoc/check-param-names*/ +/** + * Insert every element in the set of matched elements after the target. + * + * @category Manipulation + * @example + * + * ```js + * $('<li class="plum">Plum</li>').insertAfter('.apple'); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="apple">Apple</li> + * // <li class="plum">Plum</li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // </ul> + * ``` + * + * @param target - Element to insert elements after. + * @returns The set of newly inserted elements. + * @see {@link https://api.jquery.com/insertAfter/} + */ +function insertAfter(target) { + var _this = this; + if (typeof target === 'string') { + target = this._make(target); + } + this.remove(); + var clones = []; + this._makeDomArray(target).forEach(function (el) { + var clonedSelf = _this.clone().toArray(); + var parent = el.parent; + if (!parent) { + return; + } + var siblings = parent.children; + var index = siblings.indexOf(el); + // If not found, move on + /* istanbul ignore next */ + if (index < 0) + return; + // Add cloned `this` element(s) after target element + uniqueSplice(siblings, index + 1, 0, clonedSelf, parent); + clones.push.apply(clones, clonedSelf); + }); + return this._make(clones); +} +exports.insertAfter = insertAfter; +/* eslint-disable jsdoc/check-param-names*/ +/** + * Insert content previous to each element in the set of matched elements. + * + * @category Manipulation + * @example + * + * ```js + * $('.apple').before('<li class="plum">Plum</li>'); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="plum">Plum</li> + * // <li class="apple">Apple</li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // </ul> + * ``` + * + * @param content - HTML string, DOM element, array of DOM elements or Cheerio + * to insert before each element in the set of matched elements. + * @returns The instance itself. + * @see {@link https://api.jquery.com/before/} + */ +function before() { + var _this = this; + var elems = []; + for (var _i = 0; _i < arguments.length; _i++) { + elems[_i] = arguments[_i]; + } + var lastIdx = this.length - 1; + return utils_1.domEach(this, function (el, i) { + var parent = el.parent; + if (!htmlparser2_1.DomUtils.hasChildren(el) || !parent) { + return; + } + var siblings = parent.children; + var index = siblings.indexOf(el); + // If not found, move on + /* istanbul ignore next */ + if (index < 0) + return; + var domSrc = typeof elems[0] === 'function' + ? elems[0].call(el, i, static_1.html(el.children)) + : elems; + var dom = _this._makeDomArray(domSrc, i < lastIdx); + // Add element before `el` element + uniqueSplice(siblings, index, 0, dom, parent); + }); +} +exports.before = before; +/* eslint-enable jsdoc/check-param-names*/ +/** + * Insert every element in the set of matched elements before the target. + * + * @category Manipulation + * @example + * + * ```js + * $('<li class="plum">Plum</li>').insertBefore('.apple'); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="plum">Plum</li> + * // <li class="apple">Apple</li> + * // <li class="orange">Orange</li> + * // <li class="pear">Pear</li> + * // </ul> + * ``` + * + * @param target - Element to insert elements before. + * @returns The set of newly inserted elements. + * @see {@link https://api.jquery.com/insertBefore/} + */ +function insertBefore(target) { + var _this = this; + var targetArr = this._make(target); + this.remove(); + var clones = []; + utils_1.domEach(targetArr, function (el) { + var clonedSelf = _this.clone().toArray(); + var parent = el.parent; + if (!parent) { + return; + } + var siblings = parent.children; + var index = siblings.indexOf(el); + // If not found, move on + /* istanbul ignore next */ + if (index < 0) + return; + // Add cloned `this` element(s) after target element + uniqueSplice(siblings, index, 0, clonedSelf, parent); + clones.push.apply(clones, clonedSelf); + }); + return this._make(clones); +} +exports.insertBefore = insertBefore; +/** + * Removes the set of matched elements from the DOM and all their children. + * `selector` filters the set of matched elements to be removed. + * + * @category Manipulation + * @example + * + * ```js + * $('.pear').remove(); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="apple">Apple</li> + * // <li class="orange">Orange</li> + * // </ul> + * ``` + * + * @param selector - Optional selector for elements to remove. + * @returns The instance itself. + * @see {@link https://api.jquery.com/remove/} + */ +function remove(selector) { + // Filter if we have selector + var elems = selector ? this.filter(selector) : this; + utils_1.domEach(elems, function (el) { + htmlparser2_1.DomUtils.removeElement(el); + el.prev = el.next = el.parent = null; + }); + return this; +} +exports.remove = remove; +/** + * Replaces matched elements with `content`. + * + * @category Manipulation + * @example + * + * ```js + * const plum = $('<li class="plum">Plum</li>'); + * $('.pear').replaceWith(plum); + * $.html(); + * //=> <ul id="fruits"> + * // <li class="apple">Apple</li> + * // <li class="orange">Orange</li> + * // <li class="plum">Plum</li> + * // </ul> + * ``` + * + * @param content - Replacement for matched elements. + * @returns The instance itself. + * @see {@link https://api.jquery.com/replaceWith/} + */ +function replaceWith(content) { + var _this = this; + return utils_1.domEach(this, function (el, i) { + var parent = el.parent; + if (!parent) { + return; + } + var siblings = parent.children; + var cont = typeof content === 'function' ? content.call(el, i, el) : content; + var dom = _this._makeDomArray(cont); + /* + * In the case that `dom` contains nodes that already exist in other + * structures, ensure those nodes are properly removed. + */ + parse_1.update(dom, null); + var index = siblings.indexOf(el); + // Completely remove old element + uniqueSplice(siblings, index, 1, dom, parent); + if (!dom.includes(el)) { + el.parent = el.prev = el.next = null; + } + }); +} +exports.replaceWith = replaceWith; +/** + * Empties an element, removing all its children. + * + * @category Manipulation + * @example + * + * ```js + * $('ul').empty(); + * $.html(); + * //=> <ul id="fruits"></ul> + * ``` + * + * @returns The instance itself. + * @see {@link https://api.jquery.com/empty/} + */ +function empty() { + return utils_1.domEach(this, function (el) { + if (!htmlparser2_1.DomUtils.hasChildren(el)) + return; + el.children.forEach(function (child) { + child.next = child.prev = child.parent = null; + }); + el.children.length = 0; + }); +} +exports.empty = empty; +function html(str) { + if (str === undefined) { + var el = this[0]; + if (!el || !htmlparser2_1.DomUtils.hasChildren(el)) + return null; + return static_1.html(el.children, this.options); + } + // Keep main options unchanged + var opts = tslib_1.__assign(tslib_1.__assign({}, this.options), { context: null }); + return utils_1.domEach(this, function (el) { + if (!htmlparser2_1.DomUtils.hasChildren(el)) + return; + el.children.forEach(function (child) { + child.next = child.prev = child.parent = null; + }); + opts.context = el; + var content = utils_1.isCheerio(str) + ? str.toArray() + : parse_1.default("" + str, opts, false).children; + parse_1.update(content, el); + }); +} +exports.html = html; +/** + * Turns the collection to a string. Alias for `.html()`. + * + * @category Manipulation + * @returns The rendered document. + */ +function toString() { + return static_1.html(this, this.options); +} +exports.toString = toString; +function text(str) { + var _this = this; + // If `str` is undefined, act as a "getter" + if (str === undefined) { + return static_1.text(this); + } + if (typeof str === 'function') { + // Function support + return utils_1.domEach(this, function (el, i) { + text.call(_this._make(el), str.call(el, i, static_1.text([el]))); + }); + } + // Append text node to each selected elements + return utils_1.domEach(this, function (el) { + if (!htmlparser2_1.DomUtils.hasChildren(el)) + return; + el.children.forEach(function (child) { + child.next = child.prev = child.parent = null; + }); + var textNode = new domhandler_2.Text(str); + parse_1.update(textNode, el); + }); +} +exports.text = text; +/** + * Clone the cheerio object. + * + * @category Manipulation + * @example + * + * ```js + * const moreFruit = $('#fruits').clone(); + * ``` + * + * @returns The cloned object. + * @see {@link https://api.jquery.com/clone/} + */ +function clone() { + return this._make(utils_1.cloneDom(this.get())); +} +exports.clone = clone; diff --git a/node_modules/cheerio/lib/api/traversing.d.ts b/node_modules/cheerio/lib/api/traversing.d.ts new file mode 100644 index 0000000..7cee2ee --- /dev/null +++ b/node_modules/cheerio/lib/api/traversing.d.ts @@ -0,0 +1,644 @@ +/** + * Methods for traversing the DOM structure. + * + * @module cheerio/traversing + */ +import { Node, Element, Document } from 'domhandler'; +import type { Cheerio } from '../cheerio'; +import type { AcceptedFilters } from '../types'; +/** + * Get the descendants of each element in the current set of matched elements, + * filtered by a selector, jQuery object, or element. + * + * @category Traversing + * @example + * + * ```js + * $('#fruits').find('li').length; + * //=> 3 + * $('#fruits').find($('.apple')).length; + * //=> 1 + * ``` + * + * @param selectorOrHaystack - Element to look for. + * @returns The found elements. + * @see {@link https://api.jquery.com/find/} + */ +export declare function find<T extends Node>(this: Cheerio<T>, selectorOrHaystack?: string | Cheerio<Element> | Element): Cheerio<Element>; +/** + * Get the parent of each element in the current set of matched elements, + * optionally filtered by a selector. + * + * @category Traversing + * @example + * + * ```js + * $('.pear').parent().attr('id'); + * //=> fruits + * ``` + * + * @param selector - If specified filter for parent. + * @returns The parents. + * @see {@link https://api.jquery.com/parent/} + */ +export declare const parent: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>; +/** + * Get a set of parents filtered by `selector` of each element in the current + * set of match elements. + * + * @category Traversing + * @example + * + * ```js + * $('.orange').parents().length; + * //=> 2 + * $('.orange').parents('#fruits').length; + * //=> 1 + * ``` + * + * @param selector - If specified filter for parents. + * @returns The parents. + * @see {@link https://api.jquery.com/parents/} + */ +export declare const parents: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>; +/** + * Get the ancestors of each element in the current set of matched elements, up + * to but not including the element matched by the selector, DOM node, or cheerio object. + * + * @category Traversing + * @example + * + * ```js + * $('.orange').parentsUntil('#food').length; + * //=> 1 + * ``` + * + * @param selector - Selector for element to stop at. + * @param filterSelector - Optional filter for parents. + * @returns The parents. + * @see {@link https://api.jquery.com/parentsUntil/} + */ +export declare const parentsUntil: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | null | undefined, filterSelector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>; +/** + * For each element in the set, get the first element that matches the selector + * by testing the element itself and traversing up through its ancestors in the DOM tree. + * + * @category Traversing + * @example + * + * ```js + * $('.orange').closest(); + * //=> [] + * + * $('.orange').closest('.apple'); + * // => [] + * + * $('.orange').closest('li'); + * //=> [<li class="orange">Orange</li>] + * + * $('.orange').closest('#fruits'); + * //=> [<ul id="fruits"> ... </ul>] + * ``` + * + * @param selector - Selector for the element to find. + * @returns The closest nodes. + * @see {@link https://api.jquery.com/closest/} + */ +export declare function closest<T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Node>): Cheerio<Node>; +/** + * Gets the next sibling of the first selected element, optionally filtered by a selector. + * + * @category Traversing + * @example + * + * ```js + * $('.apple').next().hasClass('orange'); + * //=> true + * ``` + * + * @param selector - If specified filter for sibling. + * @returns The next nodes. + * @see {@link https://api.jquery.com/next/} + */ +export declare const next: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>; +/** + * Gets all the following siblings of the first selected element, optionally + * filtered by a selector. + * + * @category Traversing + * @example + * + * ```js + * $('.apple').nextAll(); + * //=> [<li class="orange">Orange</li>, <li class="pear">Pear</li>] + * $('.apple').nextAll('.orange'); + * //=> [<li class="orange">Orange</li>] + * ``` + * + * @param selector - If specified filter for siblings. + * @returns The next nodes. + * @see {@link https://api.jquery.com/nextAll/} + */ +export declare const nextAll: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>; +/** + * Gets all the following siblings up to but not including the element matched + * by the selector, optionally filtered by another selector. + * + * @category Traversing + * @example + * + * ```js + * $('.apple').nextUntil('.pear'); + * //=> [<li class="orange">Orange</li>] + * ``` + * + * @param selector - Selector for element to stop at. + * @param filterSelector - If specified filter for siblings. + * @returns The next nodes. + * @see {@link https://api.jquery.com/nextUntil/} + */ +export declare const nextUntil: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | null | undefined, filterSelector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>; +/** + * Gets the previous sibling of the first selected element optionally filtered + * by a selector. + * + * @category Traversing + * @example + * + * ```js + * $('.orange').prev().hasClass('apple'); + * //=> true + * ``` + * + * @param selector - If specified filter for siblings. + * @returns The previous nodes. + * @see {@link https://api.jquery.com/prev/} + */ +export declare const prev: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>; +/** + * Gets all the preceding siblings of the first selected element, optionally + * filtered by a selector. + * + * @category Traversing + * @example + * + * ```js + * $('.pear').prevAll(); + * //=> [<li class="orange">Orange</li>, <li class="apple">Apple</li>] + * + * $('.pear').prevAll('.orange'); + * //=> [<li class="orange">Orange</li>] + * ``` + * + * @param selector - If specified filter for siblings. + * @returns The previous nodes. + * @see {@link https://api.jquery.com/prevAll/} + */ +export declare const prevAll: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>; +/** + * Gets all the preceding siblings up to but not including the element matched + * by the selector, optionally filtered by another selector. + * + * @category Traversing + * @example + * + * ```js + * $('.pear').prevUntil('.apple'); + * //=> [<li class="orange">Orange</li>] + * ``` + * + * @param selector - Selector for element to stop at. + * @param filterSelector - If specified filter for siblings. + * @returns The previous nodes. + * @see {@link https://api.jquery.com/prevUntil/} + */ +export declare const prevUntil: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | null | undefined, filterSelector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>; +/** + * Get the siblings of each element (excluding the element) in the set of + * matched elements, optionally filtered by a selector. + * + * @category Traversing + * @example + * + * ```js + * $('.pear').siblings().length; + * //=> 2 + * + * $('.pear').siblings('.orange').length; + * //=> 1 + * ``` + * + * @param selector - If specified filter for siblings. + * @returns The siblings. + * @see {@link https://api.jquery.com/siblings/} + */ +export declare const siblings: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>; +/** + * Gets the children of the first selected element. + * + * @category Traversing + * @example + * + * ```js + * $('#fruits').children().length; + * //=> 3 + * + * $('#fruits').children('.pear').text(); + * //=> Pear + * ``` + * + * @param selector - If specified filter for children. + * @returns The children. + * @see {@link https://api.jquery.com/children/} + */ +export declare const children: <T extends Node>(this: Cheerio<T>, selector?: AcceptedFilters<Element> | undefined) => Cheerio<Element>; +/** + * Gets the children of each element in the set of matched elements, including + * text and comment nodes. + * + * @category Traversing + * @example + * + * ```js + * $('#fruits').contents().length; + * //=> 3 + * ``` + * + * @returns The children. + * @see {@link https://api.jquery.com/contents/} + */ +export declare function contents<T extends Node>(this: Cheerio<T>): Cheerio<Node>; +/** + * Iterates over a cheerio object, executing a function for each matched + * element. When the callback is fired, the function is fired in the context of + * the DOM element, so `this` refers to the current element, which is equivalent + * to the function parameter `element`. To break out of the `each` loop early, + * return with `false`. + * + * @category Traversing + * @example + * + * ```js + * const fruits = []; + * + * $('li').each(function (i, elem) { + * fruits[i] = $(this).text(); + * }); + * + * fruits.join(', '); + * //=> Apple, Orange, Pear + * ``` + * + * @param fn - Function to execute. + * @returns The instance itself, useful for chaining. + * @see {@link https://api.jquery.com/each/} + */ +export declare function each<T>(this: Cheerio<T>, fn: (this: T, i: number, el: T) => void | boolean): Cheerio<T>; +/** + * Pass each element in the current matched set through a function, producing a + * new Cheerio object containing the return values. The function can return an + * individual data item or an array of data items to be inserted into the + * resulting set. If an array is returned, the elements inside the array are + * inserted into the set. If the function returns null or undefined, no element + * will be inserted. + * + * @category Traversing + * @example + * + * ```js + * $('li') + * .map(function (i, el) { + * // this === el + * return $(this).text(); + * }) + * .toArray() + * .join(' '); + * //=> "apple orange pear" + * ``` + * + * @param fn - Function to execute. + * @returns The mapped elements, wrapped in a Cheerio collection. + * @see {@link https://api.jquery.com/map/} + */ +export declare function map<T, M>(this: Cheerio<T>, fn: (this: T, i: number, el: T) => M[] | M | null | undefined): Cheerio<M>; +/** + * Iterates over a cheerio object, reducing the set of selector elements to + * those that match the selector or pass the function's test. + * + * This is the definition for using type guards; have a look below for other + * ways to invoke this method. The function is executed in the context of the + * selected element, so `this` refers to the current element. + * + * @category Traversing + * @example <caption>Function</caption> + * + * ```js + * $('li') + * .filter(function (i, el) { + * // this === el + * return $(this).attr('class') === 'orange'; + * }) + * .attr('class'); //=> orange + * ``` + * + * @param match - Value to look for, following the rules above. + * @returns The filtered collection. + * @see {@link https://api.jquery.com/filter/} + */ +export declare function filter<T, S extends T>(this: Cheerio<T>, match: (this: T, index: number, value: T) => value is S): Cheerio<S>; +/** + * Iterates over a cheerio object, reducing the set of selector elements to + * those that match the selector or pass the function's test. + * + * - When a Cheerio selection is specified, return only the elements contained in + * that selection. + * - When an element is specified, return only that element (if it is contained in + * the original selection). + * - If using the function method, the function is executed in the context of the + * selected element, so `this` refers to the current element. + * + * @category Traversing + * @example <caption>Selector</caption> + * + * ```js + * $('li').filter('.orange').attr('class'); + * //=> orange + * ``` + * + * @example <caption>Function</caption> + * + * ```js + * $('li') + * .filter(function (i, el) { + * // this === el + * return $(this).attr('class') === 'orange'; + * }) + * .attr('class'); //=> orange + * ``` + * + * @param match - Value to look for, following the rules above. See + * {@link AcceptedFilters}. + * @returns The filtered collection. + * @see {@link https://api.jquery.com/filter/} + */ +export declare function filter<T, S extends AcceptedFilters<T>>(this: Cheerio<T>, match: S): Cheerio<S extends string ? Element : T>; +export declare function filterArray<T>(nodes: T[], match: AcceptedFilters<T>, xmlMode?: boolean, root?: Document): Element[] | T[]; +/** + * Checks the current list of elements and returns `true` if *any* of the + * elements match the selector. If using an element or Cheerio selection, + * returns `true` if *any* of the elements match. If using a predicate function, + * the function is executed in the context of the selected element, so `this` + * refers to the current element. + * + * @category Attributes + * @param selector - Selector for the selection. + * @returns Whether or not the selector matches an element of the instance. + * @see {@link https://api.jquery.com/is/} + */ +export declare function is<T>(this: Cheerio<T>, selector?: AcceptedFilters<T>): boolean; +/** + * Remove elements from the set of matched elements. Given a Cheerio object that + * represents a set of DOM elements, the `.not()` method constructs a new + * Cheerio object from a subset of the matching elements. The supplied selector + * is tested against each element; the elements that don't match the selector + * will be included in the result. + * + * The `.not()` method can take a function as its argument in the same way that + * `.filter()` does. Elements for which the function returns `true` are excluded + * from the filtered set; all other elements are included. + * + * @category Traversing + * @example <caption>Selector</caption> + * + * ```js + * $('li').not('.apple').length; + * //=> 2 + * ``` + * + * @example <caption>Function</caption> + * + * ```js + * $('li').not(function (i, el) { + * // this === el + * return $(this).attr('class') === 'orange'; + * }).length; //=> 2 + * ``` + * + * @param match - Value to look for, following the rules above. + * @param container - Optional node to filter instead. + * @returns The filtered collection. + * @see {@link https://api.jquery.com/not/} + */ +export declare function not<T extends Node>(this: Cheerio<T>, match: AcceptedFilters<T>): Cheerio<T>; +/** + * Filters the set of matched elements to only those which have the given DOM + * element as a descendant or which have a descendant that matches the given + * selector. Equivalent to `.filter(':has(selector)')`. + * + * @category Traversing + * @example <caption>Selector</caption> + * + * ```js + * $('ul').has('.pear').attr('id'); + * //=> fruits + * ``` + * + * @example <caption>Element</caption> + * + * ```js + * $('ul').has($('.pear')[0]).attr('id'); + * //=> fruits + * ``` + * + * @param selectorOrHaystack - Element to look for. + * @returns The filtered collection. + * @see {@link https://api.jquery.com/has/} + */ +export declare function has(this: Cheerio<Node | Element>, selectorOrHaystack: string | Cheerio<Element> | Element): Cheerio<Node | Element>; +/** + * Will select the first element of a cheerio object. + * + * @category Traversing + * @example + * + * ```js + * $('#fruits').children().first().text(); + * //=> Apple + * ``` + * + * @returns The first element. + * @see {@link https://api.jquery.com/first/} + */ +export declare function first<T extends Node>(this: Cheerio<T>): Cheerio<T>; +/** + * Will select the last element of a cheerio object. + * + * @category Traversing + * @example + * + * ```js + * $('#fruits').children().last().text(); + * //=> Pear + * ``` + * + * @returns The last element. + * @see {@link https://api.jquery.com/last/} + */ +export declare function last<T>(this: Cheerio<T>): Cheerio<T>; +/** + * Reduce the set of matched elements to the one at the specified index. Use + * `.eq(-i)` to count backwards from the last selected element. + * + * @category Traversing + * @example + * + * ```js + * $('li').eq(0).text(); + * //=> Apple + * + * $('li').eq(-1).text(); + * //=> Pear + * ``` + * + * @param i - Index of the element to select. + * @returns The element at the `i`th position. + * @see {@link https://api.jquery.com/eq/} + */ +export declare function eq<T>(this: Cheerio<T>, i: number): Cheerio<T>; +/** + * Retrieve one of the elements matched by the Cheerio object, at the `i`th position. + * + * @category Traversing + * @example + * + * ```js + * $('li').get(0).tagName; + * //=> li + * ``` + * + * @param i - Element to retrieve. + * @returns The element at the `i`th position. + * @see {@link https://api.jquery.com/get/} + */ +export declare function get<T>(this: Cheerio<T>, i: number): T; +/** + * Retrieve all elements matched by the Cheerio object, as an array. + * + * @category Traversing + * @example + * + * ```js + * $('li').get().length; + * //=> 3 + * ``` + * + * @returns All elements matched by the Cheerio object. + * @see {@link https://api.jquery.com/get/} + */ +export declare function get<T>(this: Cheerio<T>): T[]; +/** + * Retrieve all the DOM elements contained in the jQuery set as an array. + * + * @example + * + * ```js + * $('li').toArray(); + * //=> [ {...}, {...}, {...} ] + * ``` + * + * @returns The contained items. + */ +export declare function toArray<T>(this: Cheerio<T>): T[]; +/** + * Search for a given element from among the matched elements. + * + * @category Traversing + * @example + * + * ```js + * $('.pear').index(); + * //=> 2 $('.orange').index('li'); + * //=> 1 + * $('.apple').index($('#fruit, li')); + * //=> 1 + * ``` + * + * @param selectorOrNeedle - Element to look for. + * @returns The index of the element. + * @see {@link https://api.jquery.com/index/} + */ +export declare function index<T extends Node>(this: Cheerio<T>, selectorOrNeedle?: string | Cheerio<Node> | Node): number; +/** + * Gets the elements matching the specified range (0-based position). + * + * @category Traversing + * @example + * + * ```js + * $('li').slice(1).eq(0).text(); + * //=> 'Orange' + * + * $('li').slice(1, 2).length; + * //=> 1 + * ``` + * + * @param start - An position at which the elements begin to be selected. If + * negative, it indicates an offset from the end of the set. + * @param end - An position at which the elements stop being selected. If + * negative, it indicates an offset from the end of the set. If omitted, the + * range continues until the end of the set. + * @returns The elements matching the specified range. + * @see {@link https://api.jquery.com/slice/} + */ +export declare function slice<T>(this: Cheerio<T>, start?: number, end?: number): Cheerio<T>; +/** + * End the most recent filtering operation in the current chain and return the + * set of matched elements to its previous state. + * + * @category Traversing + * @example + * + * ```js + * $('li').eq(0).end().length; + * //=> 3 + * ``` + * + * @returns The previous state of the set of matched elements. + * @see {@link https://api.jquery.com/end/} + */ +export declare function end<T>(this: Cheerio<T>): Cheerio<Node>; +/** + * Add elements to the set of matched elements. + * + * @category Traversing + * @example + * + * ```js + * $('.apple').add('.orange').length; + * //=> 2 + * ``` + * + * @param other - Elements to add. + * @param context - Optionally the context of the new selection. + * @returns The combined set. + * @see {@link https://api.jquery.com/add/} + */ +export declare function add<S extends Node, T extends Node>(this: Cheerio<T>, other: string | Cheerio<S> | S | S[], context?: Cheerio<S> | string): Cheerio<S | T>; +/** + * Add the previous set of elements on the stack to the current set, optionally + * filtered by a selector. + * + * @category Traversing + * @example + * + * ```js + * $('li').eq(0).addBack('.orange').length; + * //=> 2 + * ``` + * + * @param selector - Selector for the elements to add. + * @returns The combined set. + * @see {@link https://api.jquery.com/addBack/} + */ +export declare function addBack<T extends Node>(this: Cheerio<T>, selector?: string): Cheerio<Node>; +//# sourceMappingURL=traversing.d.ts.map
\ No newline at end of file diff --git a/node_modules/cheerio/lib/api/traversing.d.ts.map b/node_modules/cheerio/lib/api/traversing.d.ts.map new file mode 100644 index 0000000..ec73e8f --- /dev/null +++ b/node_modules/cheerio/lib/api/traversing.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"traversing.d.ts","sourceRoot":"","sources":["../../src/api/traversing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,OAAO,EAA2B,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC9E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAK1C,OAAO,KAAK,EAAkB,eAAe,EAAE,MAAM,UAAU,CAAC;AAIhE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EACjC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,kBAAkB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,GACvD,OAAO,CAAC,OAAO,CAAC,CA4BlB;AA2HD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,MAAM,yFAvHZ,QAAQ,OAAO,CA0HrB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,OAAO,yFA9Ib,QAAQ,OAAO,CAyJrB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,YAAY,uJA3FpB,QAAQ,OAAO,CA+FnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAg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io/lib/api/traversing.js b/node_modules/cheerio/lib/api/traversing.js new file mode 100644 index 0000000..3d9ea8f --- /dev/null +++ b/node_modules/cheerio/lib/api/traversing.js @@ -0,0 +1,866 @@ +"use strict"; +/** + * Methods for traversing the DOM structure. + * + * @module cheerio/traversing + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.addBack = exports.add = exports.end = exports.slice = exports.index = exports.toArray = exports.get = exports.eq = exports.last = exports.first = exports.has = exports.not = exports.is = exports.filterArray = exports.filter = exports.map = exports.each = exports.contents = exports.children = exports.siblings = exports.prevUntil = exports.prevAll = exports.prev = exports.nextUntil = exports.nextAll = exports.next = exports.closest = exports.parentsUntil = exports.parents = exports.parent = exports.find = void 0; +var tslib_1 = require("tslib"); +var domhandler_1 = require("domhandler"); +var select = tslib_1.__importStar(require("cheerio-select")); +var utils_1 = require("../utils"); +var static_1 = require("../static"); +var htmlparser2_1 = require("htmlparser2"); +var uniqueSort = htmlparser2_1.DomUtils.uniqueSort; +var reSiblingSelector = /^\s*[~+]/; +/** + * Get the descendants of each element in the current set of matched elements, + * filtered by a selector, jQuery object, or element. + * + * @category Traversing + * @example + * + * ```js + * $('#fruits').find('li').length; + * //=> 3 + * $('#fruits').find($('.apple')).length; + * //=> 1 + * ``` + * + * @param selectorOrHaystack - Element to look for. + * @returns The found elements. + * @see {@link https://api.jquery.com/find/} + */ +function find(selectorOrHaystack) { + var _a; + if (!selectorOrHaystack) { + return this._make([]); + } + var context = this.toArray(); + if (typeof selectorOrHaystack !== 'string') { + var haystack = utils_1.isCheerio(selectorOrHaystack) + ? selectorOrHaystack.toArray() + : [selectorOrHaystack]; + return this._make(haystack.filter(function (elem) { return context.some(function (node) { return static_1.contains(node, elem); }); })); + } + var elems = reSiblingSelector.test(selectorOrHaystack) + ? context + : this.children().toArray(); + var options = { + context: context, + root: (_a = this._root) === null || _a === void 0 ? void 0 : _a[0], + xmlMode: this.options.xmlMode, + }; + return this._make(select.select(selectorOrHaystack, elems, options)); +} +exports.find = find; +/** + * Creates a matcher, using a particular mapping function. Matchers provide a + * function that finds elements using a generating function, supporting filtering. + * + * @private + * @param matchMap - Mapping function. + * @returns - Function for wrapping generating functions. + */ +function _getMatcher(matchMap) { + return function (fn) { + var postFns = []; + for (var _i = 1; _i < arguments.length; _i++) { + postFns[_i - 1] = arguments[_i]; + } + return function (selector) { + var _a; + var matched = matchMap(fn, this); + if (selector) { + matched = filterArray(matched, selector, this.options.xmlMode, (_a = this._root) === null || _a === void 0 ? void 0 : _a[0]); + } + return this._make( + // Post processing is only necessary if there is more than one element. + this.length > 1 && matched.length > 1 + ? postFns.reduce(function (elems, fn) { return fn(elems); }, matched) + : matched); + }; + }; +} +/** Matcher that adds multiple elements for each entry in the input. */ +var _matcher = _getMatcher(function (fn, elems) { + var _a; + var ret = []; + for (var i = 0; i < elems.length; i++) { + var value = fn(elems[i]); + ret.push(value); + } + return (_a = new Array()).concat.apply(_a, ret); +}); +/** Matcher that adds at most one element for each entry in the input. */ +var _singleMatcher = _getMatcher(function (fn, elems) { + var ret = []; + for (var i = 0; i < elems.length; i++) { + var value = fn(elems[i]); + if (value !== null) { + ret.push(value); + } + } + return ret; +}); +/** + * Matcher that supports traversing until a condition is met. + * + * @returns A function usable for `*Until` methods. + */ +function _matchUntil(nextElem) { + var postFns = []; + for (var _i = 1; _i < arguments.length; _i++) { + postFns[_i - 1] = arguments[_i]; + } + // We use a variable here that is used from within the matcher. + var matches = null; + var innerMatcher = _getMatcher(function (nextElem, elems) { + var matched = []; + utils_1.domEach(elems, function (elem) { + for (var next_1; (next_1 = nextElem(elem)); elem = next_1) { + // FIXME: `matched` might contain duplicates here and the index is too large. + if (matches === null || matches === void 0 ? void 0 : matches(next_1, matched.length)) + break; + matched.push(next_1); + } + }); + return matched; + }).apply(void 0, tslib_1.__spreadArray([nextElem], postFns)); + return function (selector, filterSelector) { + var _this = this; + // Override `matches` variable with the new target. + matches = + typeof selector === 'string' + ? function (elem) { return select.is(elem, selector, _this.options); } + : selector + ? getFilterFn(selector) + : null; + var ret = innerMatcher.call(this, filterSelector); + // Set `matches` to `null`, so we don't waste memory. + matches = null; + return ret; + }; +} +function _removeDuplicates(elems) { + return Array.from(new Set(elems)); +} +/** + * Get the parent of each element in the current set of matched elements, + * optionally filtered by a selector. + * + * @category Traversing + * @example + * + * ```js + * $('.pear').parent().attr('id'); + * //=> fruits + * ``` + * + * @param selector - If specified filter for parent. + * @returns The parents. + * @see {@link https://api.jquery.com/parent/} + */ +exports.parent = _singleMatcher(function (_a) { + var parent = _a.parent; + return (parent && !domhandler_1.isDocument(parent) ? parent : null); +}, _removeDuplicates); +/** + * Get a set of parents filtered by `selector` of each element in the current + * set of match elements. + * + * @category Traversing + * @example + * + * ```js + * $('.orange').parents().length; + * //=> 2 + * $('.orange').parents('#fruits').length; + * //=> 1 + * ``` + * + * @param selector - If specified filter for parents. + * @returns The parents. + * @see {@link https://api.jquery.com/parents/} + */ +exports.parents = _matcher(function (elem) { + var matched = []; + while (elem.parent && !domhandler_1.isDocument(elem.parent)) { + matched.push(elem.parent); + elem = elem.parent; + } + return matched; +}, uniqueSort, function (elems) { return elems.reverse(); }); +/** + * Get the ancestors of each element in the current set of matched elements, up + * to but not including the element matched by the selector, DOM node, or cheerio object. + * + * @category Traversing + * @example + * + * ```js + * $('.orange').parentsUntil('#food').length; + * //=> 1 + * ``` + * + * @param selector - Selector for element to stop at. + * @param filterSelector - Optional filter for parents. + * @returns The parents. + * @see {@link https://api.jquery.com/parentsUntil/} + */ +exports.parentsUntil = _matchUntil(function (_a) { + var parent = _a.parent; + return (parent && !domhandler_1.isDocument(parent) ? parent : null); +}, uniqueSort, function (elems) { return elems.reverse(); }); +/** + * For each element in the set, get the first element that matches the selector + * by testing the element itself and traversing up through its ancestors in the DOM tree. + * + * @category Traversing + * @example + * + * ```js + * $('.orange').closest(); + * //=> [] + * + * $('.orange').closest('.apple'); + * // => [] + * + * $('.orange').closest('li'); + * //=> [<li class="orange">Orange</li>] + * + * $('.orange').closest('#fruits'); + * //=> [<ul id="fruits"> ... </ul>] + * ``` + * + * @param selector - Selector for the element to find. + * @returns The closest nodes. + * @see {@link https://api.jquery.com/closest/} + */ +function closest(selector) { + var _this = this; + var set = []; + if (!selector) { + return this._make(set); + } + utils_1.domEach(this, function (elem) { + var _a; + while (elem && elem.type !== 'root') { + if (!selector || + filterArray([elem], selector, _this.options.xmlMode, (_a = _this._root) === null || _a === void 0 ? void 0 : _a[0]) + .length) { + // Do not add duplicate elements to the set + if (elem && !set.includes(elem)) { + set.push(elem); + } + break; + } + elem = elem.parent; + } + }); + return this._make(set); +} +exports.closest = closest; +/** + * Gets the next sibling of the first selected element, optionally filtered by a selector. + * + * @category Traversing + * @example + * + * ```js + * $('.apple').next().hasClass('orange'); + * //=> true + * ``` + * + * @param selector - If specified filter for sibling. + * @returns The next nodes. + * @see {@link https://api.jquery.com/next/} + */ +exports.next = _singleMatcher(function (elem) { return htmlparser2_1.DomUtils.nextElementSibling(elem); }); +/** + * Gets all the following siblings of the first selected element, optionally + * filtered by a selector. + * + * @category Traversing + * @example + * + * ```js + * $('.apple').nextAll(); + * //=> [<li class="orange">Orange</li>, <li class="pear">Pear</li>] + * $('.apple').nextAll('.orange'); + * //=> [<li class="orange">Orange</li>] + * ``` + * + * @param selector - If specified filter for siblings. + * @returns The next nodes. + * @see {@link https://api.jquery.com/nextAll/} + */ +exports.nextAll = _matcher(function (elem) { + var matched = []; + while (elem.next) { + elem = elem.next; + if (utils_1.isTag(elem)) + matched.push(elem); + } + return matched; +}, _removeDuplicates); +/** + * Gets all the following siblings up to but not including the element matched + * by the selector, optionally filtered by another selector. + * + * @category Traversing + * @example + * + * ```js + * $('.apple').nextUntil('.pear'); + * //=> [<li class="orange">Orange</li>] + * ``` + * + * @param selector - Selector for element to stop at. + * @param filterSelector - If specified filter for siblings. + * @returns The next nodes. + * @see {@link https://api.jquery.com/nextUntil/} + */ +exports.nextUntil = _matchUntil(function (el) { return htmlparser2_1.DomUtils.nextElementSibling(el); }, _removeDuplicates); +/** + * Gets the previous sibling of the first selected element optionally filtered + * by a selector. + * + * @category Traversing + * @example + * + * ```js + * $('.orange').prev().hasClass('apple'); + * //=> true + * ``` + * + * @param selector - If specified filter for siblings. + * @returns The previous nodes. + * @see {@link https://api.jquery.com/prev/} + */ +exports.prev = _singleMatcher(function (elem) { return htmlparser2_1.DomUtils.prevElementSibling(elem); }); +/** + * Gets all the preceding siblings of the first selected element, optionally + * filtered by a selector. + * + * @category Traversing + * @example + * + * ```js + * $('.pear').prevAll(); + * //=> [<li class="orange">Orange</li>, <li class="apple">Apple</li>] + * + * $('.pear').prevAll('.orange'); + * //=> [<li class="orange">Orange</li>] + * ``` + * + * @param selector - If specified filter for siblings. + * @returns The previous nodes. + * @see {@link https://api.jquery.com/prevAll/} + */ +exports.prevAll = _matcher(function (elem) { + var matched = []; + while (elem.prev) { + elem = elem.prev; + if (utils_1.isTag(elem)) + matched.push(elem); + } + return matched; +}, _removeDuplicates); +/** + * Gets all the preceding siblings up to but not including the element matched + * by the selector, optionally filtered by another selector. + * + * @category Traversing + * @example + * + * ```js + * $('.pear').prevUntil('.apple'); + * //=> [<li class="orange">Orange</li>] + * ``` + * + * @param selector - Selector for element to stop at. + * @param filterSelector - If specified filter for siblings. + * @returns The previous nodes. + * @see {@link https://api.jquery.com/prevUntil/} + */ +exports.prevUntil = _matchUntil(function (el) { return htmlparser2_1.DomUtils.prevElementSibling(el); }, _removeDuplicates); +/** + * Get the siblings of each element (excluding the element) in the set of + * matched elements, optionally filtered by a selector. + * + * @category Traversing + * @example + * + * ```js + * $('.pear').siblings().length; + * //=> 2 + * + * $('.pear').siblings('.orange').length; + * //=> 1 + * ``` + * + * @param selector - If specified filter for siblings. + * @returns The siblings. + * @see {@link https://api.jquery.com/siblings/} + */ +exports.siblings = _matcher(function (elem) { + return htmlparser2_1.DomUtils.getSiblings(elem).filter(function (el) { return utils_1.isTag(el) && el !== elem; }); +}, uniqueSort); +/** + * Gets the children of the first selected element. + * + * @category Traversing + * @example + * + * ```js + * $('#fruits').children().length; + * //=> 3 + * + * $('#fruits').children('.pear').text(); + * //=> Pear + * ``` + * + * @param selector - If specified filter for children. + * @returns The children. + * @see {@link https://api.jquery.com/children/} + */ +exports.children = _matcher(function (elem) { return htmlparser2_1.DomUtils.getChildren(elem).filter(utils_1.isTag); }, _removeDuplicates); +/** + * Gets the children of each element in the set of matched elements, including + * text and comment nodes. + * + * @category Traversing + * @example + * + * ```js + * $('#fruits').contents().length; + * //=> 3 + * ``` + * + * @returns The children. + * @see {@link https://api.jquery.com/contents/} + */ +function contents() { + var elems = this.toArray().reduce(function (newElems, elem) { + return domhandler_1.hasChildren(elem) ? newElems.concat(elem.children) : newElems; + }, []); + return this._make(elems); +} +exports.contents = contents; +/** + * Iterates over a cheerio object, executing a function for each matched + * element. When the callback is fired, the function is fired in the context of + * the DOM element, so `this` refers to the current element, which is equivalent + * to the function parameter `element`. To break out of the `each` loop early, + * return with `false`. + * + * @category Traversing + * @example + * + * ```js + * const fruits = []; + * + * $('li').each(function (i, elem) { + * fruits[i] = $(this).text(); + * }); + * + * fruits.join(', '); + * //=> Apple, Orange, Pear + * ``` + * + * @param fn - Function to execute. + * @returns The instance itself, useful for chaining. + * @see {@link https://api.jquery.com/each/} + */ +function each(fn) { + var i = 0; + var len = this.length; + while (i < len && fn.call(this[i], i, this[i]) !== false) + ++i; + return this; +} +exports.each = each; +/** + * Pass each element in the current matched set through a function, producing a + * new Cheerio object containing the return values. The function can return an + * individual data item or an array of data items to be inserted into the + * resulting set. If an array is returned, the elements inside the array are + * inserted into the set. If the function returns null or undefined, no element + * will be inserted. + * + * @category Traversing + * @example + * + * ```js + * $('li') + * .map(function (i, el) { + * // this === el + * return $(this).text(); + * }) + * .toArray() + * .join(' '); + * //=> "apple orange pear" + * ``` + * + * @param fn - Function to execute. + * @returns The mapped elements, wrapped in a Cheerio collection. + * @see {@link https://api.jquery.com/map/} + */ +function map(fn) { + var elems = []; + for (var i = 0; i < this.length; i++) { + var el = this[i]; + var val = fn.call(el, i, el); + if (val != null) { + elems = elems.concat(val); + } + } + return this._make(elems); +} +exports.map = map; +/** + * Creates a function to test if a filter is matched. + * + * @param match - A filter. + * @returns A function that determines if a filter has been matched. + */ +function getFilterFn(match) { + if (typeof match === 'function') { + return function (el, i) { return match.call(el, i, el); }; + } + if (utils_1.isCheerio(match)) { + return function (el) { return Array.prototype.includes.call(match, el); }; + } + return function (el) { + return match === el; + }; +} +function filter(match) { + var _a; + return this._make(filterArray(this.toArray(), match, this.options.xmlMode, (_a = this._root) === null || _a === void 0 ? void 0 : _a[0])); +} +exports.filter = filter; +function filterArray(nodes, match, xmlMode, root) { + return typeof match === 'string' + ? select.filter(match, nodes, { xmlMode: xmlMode, root: root }) + : nodes.filter(getFilterFn(match)); +} +exports.filterArray = filterArray; +/** + * Checks the current list of elements and returns `true` if *any* of the + * elements match the selector. If using an element or Cheerio selection, + * returns `true` if *any* of the elements match. If using a predicate function, + * the function is executed in the context of the selected element, so `this` + * refers to the current element. + * + * @category Attributes + * @param selector - Selector for the selection. + * @returns Whether or not the selector matches an element of the instance. + * @see {@link https://api.jquery.com/is/} + */ +function is(selector) { + var nodes = this.toArray(); + return typeof selector === 'string' + ? select.some(nodes.filter(utils_1.isTag), selector, this.options) + : selector + ? nodes.some(getFilterFn(selector)) + : false; +} +exports.is = is; +/** + * Remove elements from the set of matched elements. Given a Cheerio object that + * represents a set of DOM elements, the `.not()` method constructs a new + * Cheerio object from a subset of the matching elements. The supplied selector + * is tested against each element; the elements that don't match the selector + * will be included in the result. + * + * The `.not()` method can take a function as its argument in the same way that + * `.filter()` does. Elements for which the function returns `true` are excluded + * from the filtered set; all other elements are included. + * + * @category Traversing + * @example <caption>Selector</caption> + * + * ```js + * $('li').not('.apple').length; + * //=> 2 + * ``` + * + * @example <caption>Function</caption> + * + * ```js + * $('li').not(function (i, el) { + * // this === el + * return $(this).attr('class') === 'orange'; + * }).length; //=> 2 + * ``` + * + * @param match - Value to look for, following the rules above. + * @param container - Optional node to filter instead. + * @returns The filtered collection. + * @see {@link https://api.jquery.com/not/} + */ +function not(match) { + var nodes = this.toArray(); + if (typeof match === 'string') { + var matches_1 = new Set(select.filter(match, nodes, this.options)); + nodes = nodes.filter(function (el) { return !matches_1.has(el); }); + } + else { + var filterFn_1 = getFilterFn(match); + nodes = nodes.filter(function (el, i) { return !filterFn_1(el, i); }); + } + return this._make(nodes); +} +exports.not = not; +/** + * Filters the set of matched elements to only those which have the given DOM + * element as a descendant or which have a descendant that matches the given + * selector. Equivalent to `.filter(':has(selector)')`. + * + * @category Traversing + * @example <caption>Selector</caption> + * + * ```js + * $('ul').has('.pear').attr('id'); + * //=> fruits + * ``` + * + * @example <caption>Element</caption> + * + * ```js + * $('ul').has($('.pear')[0]).attr('id'); + * //=> fruits + * ``` + * + * @param selectorOrHaystack - Element to look for. + * @returns The filtered collection. + * @see {@link https://api.jquery.com/has/} + */ +function has(selectorOrHaystack) { + var _this = this; + return this.filter(typeof selectorOrHaystack === 'string' + ? // Using the `:has` selector here short-circuits searches. + ":has(" + selectorOrHaystack + ")" + : function (_, el) { return _this._make(el).find(selectorOrHaystack).length > 0; }); +} +exports.has = has; +/** + * Will select the first element of a cheerio object. + * + * @category Traversing + * @example + * + * ```js + * $('#fruits').children().first().text(); + * //=> Apple + * ``` + * + * @returns The first element. + * @see {@link https://api.jquery.com/first/} + */ +function first() { + return this.length > 1 ? this._make(this[0]) : this; +} +exports.first = first; +/** + * Will select the last element of a cheerio object. + * + * @category Traversing + * @example + * + * ```js + * $('#fruits').children().last().text(); + * //=> Pear + * ``` + * + * @returns The last element. + * @see {@link https://api.jquery.com/last/} + */ +function last() { + return this.length > 0 ? this._make(this[this.length - 1]) : this; +} +exports.last = last; +/** + * Reduce the set of matched elements to the one at the specified index. Use + * `.eq(-i)` to count backwards from the last selected element. + * + * @category Traversing + * @example + * + * ```js + * $('li').eq(0).text(); + * //=> Apple + * + * $('li').eq(-1).text(); + * //=> Pear + * ``` + * + * @param i - Index of the element to select. + * @returns The element at the `i`th position. + * @see {@link https://api.jquery.com/eq/} + */ +function eq(i) { + var _a; + i = +i; + // Use the first identity optimization if possible + if (i === 0 && this.length <= 1) + return this; + if (i < 0) + i = this.length + i; + return this._make((_a = this[i]) !== null && _a !== void 0 ? _a : []); +} +exports.eq = eq; +function get(i) { + if (i == null) { + return this.toArray(); + } + return this[i < 0 ? this.length + i : i]; +} +exports.get = get; +/** + * Retrieve all the DOM elements contained in the jQuery set as an array. + * + * @example + * + * ```js + * $('li').toArray(); + * //=> [ {...}, {...}, {...} ] + * ``` + * + * @returns The contained items. + */ +function toArray() { + return Array.prototype.slice.call(this); +} +exports.toArray = toArray; +/** + * Search for a given element from among the matched elements. + * + * @category Traversing + * @example + * + * ```js + * $('.pear').index(); + * //=> 2 $('.orange').index('li'); + * //=> 1 + * $('.apple').index($('#fruit, li')); + * //=> 1 + * ``` + * + * @param selectorOrNeedle - Element to look for. + * @returns The index of the element. + * @see {@link https://api.jquery.com/index/} + */ +function index(selectorOrNeedle) { + var $haystack; + var needle; + if (selectorOrNeedle == null) { + $haystack = this.parent().children(); + needle = this[0]; + } + else if (typeof selectorOrNeedle === 'string') { + $haystack = this._make(selectorOrNeedle); + needle = this[0]; + } + else { + $haystack = this; + needle = utils_1.isCheerio(selectorOrNeedle) + ? selectorOrNeedle[0] + : selectorOrNeedle; + } + return Array.prototype.indexOf.call($haystack, needle); +} +exports.index = index; +/** + * Gets the elements matching the specified range (0-based position). + * + * @category Traversing + * @example + * + * ```js + * $('li').slice(1).eq(0).text(); + * //=> 'Orange' + * + * $('li').slice(1, 2).length; + * //=> 1 + * ``` + * + * @param start - An position at which the elements begin to be selected. If + * negative, it indicates an offset from the end of the set. + * @param end - An position at which the elements stop being selected. If + * negative, it indicates an offset from the end of the set. If omitted, the + * range continues until the end of the set. + * @returns The elements matching the specified range. + * @see {@link https://api.jquery.com/slice/} + */ +function slice(start, end) { + return this._make(Array.prototype.slice.call(this, start, end)); +} +exports.slice = slice; +/** + * End the most recent filtering operation in the current chain and return the + * set of matched elements to its previous state. + * + * @category Traversing + * @example + * + * ```js + * $('li').eq(0).end().length; + * //=> 3 + * ``` + * + * @returns The previous state of the set of matched elements. + * @see {@link https://api.jquery.com/end/} + */ +function end() { + var _a; + return (_a = this.prevObject) !== null && _a !== void 0 ? _a : this._make([]); +} +exports.end = end; +/** + * Add elements to the set of matched elements. + * + * @category Traversing + * @example + * + * ```js + * $('.apple').add('.orange').length; + * //=> 2 + * ``` + * + * @param other - Elements to add. + * @param context - Optionally the context of the new selection. + * @returns The combined set. + * @see {@link https://api.jquery.com/add/} + */ +function add(other, context) { + var selection = this._make(other, context); + var contents = uniqueSort(tslib_1.__spreadArray(tslib_1.__spreadArray([], this.get()), selection.get())); + return this._make(contents); +} +exports.add = add; +/** + * Add the previous set of elements on the stack to the current set, optionally + * filtered by a selector. + * + * @category Traversing + * @example + * + * ```js + * $('li').eq(0).addBack('.orange').length; + * //=> 2 + * ``` + * + * @param selector - Selector for the elements to add. + * @returns The combined set. + * @see {@link https://api.jquery.com/addBack/} + */ +function addBack(selector) { + return this.prevObject + ? this.add(selector ? this.prevObject.filter(selector) : this.prevObject) + : this; +} +exports.addBack = addBack; diff --git a/node_modules/cheerio/lib/cheerio.d.ts b/node_modules/cheerio/lib/cheerio.d.ts new file mode 100644 index 0000000..0564193 --- /dev/null +++ b/node_modules/cheerio/lib/cheerio.d.ts @@ -0,0 +1,53 @@ +import { InternalOptions } from './options'; +import type { Node, Document } from 'domhandler'; +import { BasicAcceptedElems } from './types'; +import * as Attributes from './api/attributes'; +import * as Traversing from './api/traversing'; +import * as Manipulation from './api/manipulation'; +import * as Css from './api/css'; +import * as Forms from './api/forms'; +declare type AttributesType = typeof Attributes; +declare type TraversingType = typeof Traversing; +declare type ManipulationType = typeof Manipulation; +declare type CssType = typeof Css; +declare type FormsType = typeof Forms; +export declare class Cheerio<T> implements ArrayLike<T> { + length: number; + [index: number]: T; + options: InternalOptions; + /** + * The root of the document. Can be set by using the `root` argument of the constructor. + * + * @private + */ + _root: Cheerio<Document> | undefined; + /** @function */ + find: typeof Traversing.find; + /** + * 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. + */ + constructor(selector?: T extends Node ? BasicAcceptedElems<T> : Cheerio<T> | T[], context?: BasicAcceptedElems<Node> | null, root?: BasicAcceptedElems<Document> | null, options?: InternalOptions); + prevObject: Cheerio<Node> | undefined; + /** + * 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. + */ + _make<T>(dom: Cheerio<T> | T[] | T | string, context?: BasicAcceptedElems<Node>): Cheerio<T>; +} +export interface Cheerio<T> extends AttributesType, TraversingType, ManipulationType, CssType, FormsType, Iterable<T> { + cheerio: '[cheerio object]'; + splice: typeof Array.prototype.slice; +} +export {}; +//# sourceMappingURL=cheerio.d.ts.map
\ No newline at end of file diff --git a/node_modules/cheerio/lib/cheerio.d.ts.map b/node_modules/cheerio/lib/cheerio.d.ts.map new file mode 100644 index 0000000..16c32c3 --- /dev/null +++ b/node_modules/cheerio/lib/cheerio.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"cheerio.d.ts","sourceRoot":"","sources":["../src/cheerio.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAA6B,MAAM,WAAW,CAAC;AAEvE,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,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AAC;IACb,OAAO,EAAE,kBAAkB,CAAC;IAE5B,MAAM,EAAE,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC;CACtC"}
\ No newline at end of file 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'); +} diff --git a/node_modules/cheerio/lib/index.d.ts b/node_modules/cheerio/lib/index.d.ts new file mode 100644 index 0000000..e651f38 --- /dev/null +++ b/node_modules/cheerio/lib/index.d.ts @@ -0,0 +1,91 @@ +/** + * The main types of Cheerio objects. + * + * @category Cheerio + */ +export type { Cheerio } from './cheerio'; +/** + * Types used in signatures of Cheerio methods. + * + * @category Cheerio + */ +export * from './types'; +export type { CheerioOptions, HTMLParser2Options, Parse5Options, } from './options'; +/** + * Re-exporting all of the node types. + * + * @category DOM Node + */ +export type { Node, NodeWithChildren, Element, Document } from 'domhandler'; +export * from './load'; +declare const _default: import("./load").CheerioAPI; +/** + * The default cheerio instance. + * + * @deprecated Use the function returned by `load` instead. + */ +export default _default; +import * as staticMethods from './static'; +/** + * In order to promote consistency with the jQuery library, users are encouraged + * to instead use the static method of the same name. + * + * @deprecated + * @example + * + * ```js + * const $ = cheerio.load('<div><p></p></div>'); + * + * $.contains($('div').get(0), $('p').get(0)); + * //=> true + * + * $.contains($('p').get(0), $('div').get(0)); + * //=> false + * ``` + * + * @returns {boolean} + */ +export declare const contains: typeof staticMethods.contains; +/** + * In order to promote consistency with the jQuery library, users are encouraged + * to instead use the static method of the same name. + * + * @deprecated + * @example + * + * ```js + * const $ = cheerio.load(''); + * + * $.merge([1, 2], [3, 4]); + * //=> [1, 2, 3, 4] + * ``` + */ +export declare const merge: typeof staticMethods.merge; +/** + * In order to promote consistency with the jQuery library, users are encouraged + * to instead use the static method of the same name as it is defined on the + * "loaded" Cheerio factory function. + * + * @deprecated See {@link static/parseHTML}. + * @example + * + * ```js + * const $ = cheerio.load(''); + * $.parseHTML('<b>markup</b>'); + * ``` + */ +export declare const parseHTML: typeof staticMethods.parseHTML; +/** + * Users seeking to access the top-level element of a parsed document should + * instead use the `root` static method of a "loaded" Cheerio function. + * + * @deprecated + * @example + * + * ```js + * const $ = cheerio.load(''); + * $.root(); + * ``` + */ +export declare const root: typeof staticMethods.root; +//# sourceMappingURL=index.d.ts.map
\ No newline at end of file diff --git a/node_modules/cheerio/lib/index.d.ts.map b/node_modules/cheerio/lib/index.d.ts.map new file mode 100644 index 0000000..6213cd7 --- /dev/null +++ b/node_modules/cheerio/lib/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC;;;;GAIG;AACH,cAAc,SAAS,CAAC;AACxB,YAAY,EACV,cAAc,EACd,kBAAkB,EAClB,aAAa,GACd,MAAM,WAAW,CAAC;AACnB;;;;GAIG;AACH,YAAY,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE5E,cAAc,QAAQ,CAAC;;AAGvB;;;;GAIG;AACH,wBAAwB;AAExB,OAAO,KAAK,aAAa,MAAM,UAAU,CAAC;AAE1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAQ,QAAQ,+BAAkB,CAAC;AAE1C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAQ,KAAK,4BAAkB,CAAC;AAEvC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAQ,SAAS,gCAAkB,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,eAAO,MAAQ,IAAI,2BAAkB,CAAC"}
\ No newline at end of file diff --git a/node_modules/cheerio/lib/index.js b/node_modules/cheerio/lib/index.js new file mode 100644 index 0000000..98095d8 --- /dev/null +++ b/node_modules/cheerio/lib/index.js @@ -0,0 +1,81 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.root = exports.parseHTML = exports.merge = exports.contains = void 0; +var tslib_1 = require("tslib"); +/** + * Types used in signatures of Cheerio methods. + * + * @category Cheerio + */ +tslib_1.__exportStar(require("./types"), exports); +tslib_1.__exportStar(require("./load"), exports); +var load_1 = require("./load"); +/** + * The default cheerio instance. + * + * @deprecated Use the function returned by `load` instead. + */ +exports.default = load_1.load([]); +var staticMethods = tslib_1.__importStar(require("./static")); +/** + * In order to promote consistency with the jQuery library, users are encouraged + * to instead use the static method of the same name. + * + * @deprecated + * @example + * + * ```js + * const $ = cheerio.load('<div><p></p></div>'); + * + * $.contains($('div').get(0), $('p').get(0)); + * //=> true + * + * $.contains($('p').get(0), $('div').get(0)); + * //=> false + * ``` + * + * @returns {boolean} + */ +exports.contains = staticMethods.contains; +/** + * In order to promote consistency with the jQuery library, users are encouraged + * to instead use the static method of the same name. + * + * @deprecated + * @example + * + * ```js + * const $ = cheerio.load(''); + * + * $.merge([1, 2], [3, 4]); + * //=> [1, 2, 3, 4] + * ``` + */ +exports.merge = staticMethods.merge; +/** + * In order to promote consistency with the jQuery library, users are encouraged + * to instead use the static method of the same name as it is defined on the + * "loaded" Cheerio factory function. + * + * @deprecated See {@link static/parseHTML}. + * @example + * + * ```js + * const $ = cheerio.load(''); + * $.parseHTML('<b>markup</b>'); + * ``` + */ +exports.parseHTML = staticMethods.parseHTML; +/** + * Users seeking to access the top-level element of a parsed document should + * instead use the `root` static method of a "loaded" Cheerio function. + * + * @deprecated + * @example + * + * ```js + * const $ = cheerio.load(''); + * $.root(); + * ``` + */ +exports.root = staticMethods.root; diff --git a/node_modules/cheerio/lib/load.d.ts b/node_modules/cheerio/lib/load.d.ts new file mode 100644 index 0000000..0dbc24f --- /dev/null +++ b/node_modules/cheerio/lib/load.d.ts @@ -0,0 +1,73 @@ +/// <reference types="node" /> +import { CheerioOptions, InternalOptions } from './options'; +import * as staticMethods from './static'; +import { Cheerio } from './cheerio'; +import type { Node, Document, Element } from 'domhandler'; +import type * as Load from './load'; +import { SelectorType, BasicAcceptedElems } from './types'; +declare type StaticType = typeof staticMethods; +declare type LoadType = typeof Load; +/** + * A querying function, bound to a document created from the provided markup. + * + * Also provides several helper methods for dealing with the document as a whole. + */ +export interface CheerioAPI extends StaticType, LoadType { + /** + * This selector method is the starting point for traversing and manipulating + * the document. Like jQuery, it's the primary method for selecting elements + * in the document. + * + * `selector` searches within the `context` scope which searches within the + * `root` scope. + * + * @example + * + * ```js + * $('.apple', '#fruits').text(); + * //=> Apple + * + * $('ul .pear').attr('class'); + * //=> pear + * + * $('li[class=orange]').html(); + * //=> Orange + * ``` + * + * @param selector - Either a selector to look for within the document, or the + * contents of a new Cheerio instance. + * @param context - Either a selector to look for within the root, or the + * contents of the document to query. + * @param root - Optional HTML document string. + */ + <T extends Node, S extends string>(selector?: S | BasicAcceptedElems<T>, context?: BasicAcceptedElems<Node> | null, root?: BasicAcceptedElems<Document>, options?: CheerioOptions): Cheerio<S extends SelectorType ? Element : T>; + /** + * The root the document was originally loaded with. + * + * @private + */ + _root: Document; + /** + * The options the document was originally loaded with. + * + * @private + */ + _options: InternalOptions; + /** Mimic jQuery's prototype alias for plugin authors. */ + fn: typeof Cheerio.prototype; +} +/** + * Create a querying function, bound to a document created from the provided + * markup. Note that similar to web browser contexts, this operation may + * introduce `<html>`, `<head>`, and `<body>` elements; set `isDocument` to + * `false` to switch to fragment mode and disable this. + * + * @param content - Markup to be loaded. + * @param options - Options for the created instance. + * @param isDocument - Allows parser to be switched to fragment mode. + * @returns The loaded document. + * @see {@link https://cheerio.js.org#loading} for additional usage information. + */ +export declare function load(content: string | Node | Node[] | Buffer, options?: CheerioOptions | null, isDocument?: boolean): CheerioAPI; +export {}; +//# sourceMappingURL=load.d.ts.map
\ No newline at end of file diff --git a/node_modules/cheerio/lib/load.d.ts.map b/node_modules/cheerio/lib/load.d.ts.map new file mode 100644 index 0000000..37da605 --- /dev/null +++ b/node_modules/cheerio/lib/load.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,cAAc,EACd,eAAe,EAGhB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,aAAa,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,KAAK,IAAI,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE3D,aAAK,UAAU,GAAG,OAAO,aAAa,CAAC;AACvC,aAAK,QAAQ,GAAG,OAAO,IAAI,CAAC;AAE5B;;;;GAIG;AACH,MAAM,WAAW,UAAW,SAAQ,UAAU,EAAE,QAAQ;IACtD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,MAAM,EAC/B,QAAQ,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,EACpC,OAAO,CAAC,EAAE,kBAAkB,CAAC,IAAI,CAAC,GAAG,IAAI,EACzC,IAAI,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,EACnC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,SAAS,YAAY,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC;IAEjD;;;;OAIG;IACH,KAAK,EAAE,QAAQ,CAAC;IAEhB;;;;OAIG;IACH,QAAQ,EAAE,eAAe,CAAC;IAE1B,yDAAyD;IACzD,EAAE,EAAE,OAAO,OAAO,CAAC,SAAS,CAAC;CAC9B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,IAAI,CAClB,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,EAAE,GAAG,MAAM,EACxC,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI,EAC/B,UAAU,UAAO,GAChB,UAAU,CAsCZ"}
\ No newline at end of file diff --git a/node_modules/cheerio/lib/load.js b/node_modules/cheerio/lib/load.js new file mode 100644 index 0000000..2603cea --- /dev/null +++ b/node_modules/cheerio/lib/load.js @@ -0,0 +1,53 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.load = void 0; +var tslib_1 = require("tslib"); +var options_1 = tslib_1.__importStar(require("./options")); +var staticMethods = tslib_1.__importStar(require("./static")); +var cheerio_1 = require("./cheerio"); +var parse_1 = tslib_1.__importDefault(require("./parse")); +/** + * Create a querying function, bound to a document created from the provided + * markup. Note that similar to web browser contexts, this operation may + * introduce `<html>`, `<head>`, and `<body>` elements; set `isDocument` to + * `false` to switch to fragment mode and disable this. + * + * @param content - Markup to be loaded. + * @param options - Options for the created instance. + * @param isDocument - Allows parser to be switched to fragment mode. + * @returns The loaded document. + * @see {@link https://cheerio.js.org#loading} for additional usage information. + */ +function load(content, options, isDocument) { + if (isDocument === void 0) { isDocument = true; } + if (content == null) { + throw new Error('cheerio.load() expects a string'); + } + var internalOpts = tslib_1.__assign(tslib_1.__assign({}, options_1.default), options_1.flatten(options)); + var root = parse_1.default(content, internalOpts, isDocument); + /** Create an extended class here, so that extensions only live on one instance. */ + var LoadedCheerio = /** @class */ (function (_super) { + tslib_1.__extends(LoadedCheerio, _super); + function LoadedCheerio() { + return _super !== null && _super.apply(this, arguments) || this; + } + return LoadedCheerio; + }(cheerio_1.Cheerio)); + function initialize(selector, context, r, opts) { + if (r === void 0) { r = root; } + return new LoadedCheerio(selector, context, r, tslib_1.__assign(tslib_1.__assign({}, internalOpts), options_1.flatten(opts))); + } + // Add in static methods & properties + Object.assign(initialize, staticMethods, { + load: load, + // `_root` and `_options` are used in static methods. + _root: root, + _options: internalOpts, + // Add `fn` for plugins + fn: LoadedCheerio.prototype, + // Add the prototype here to maintain `instanceof` behavior. + prototype: LoadedCheerio.prototype, + }); + return initialize; +} +exports.load = load; diff --git a/node_modules/cheerio/lib/options.d.ts b/node_modules/cheerio/lib/options.d.ts new file mode 100644 index 0000000..d1c8df3 --- /dev/null +++ b/node_modules/cheerio/lib/options.d.ts @@ -0,0 +1,31 @@ +import type { DomHandlerOptions } from 'domhandler'; +import type { ParserOptions } from 'htmlparser2'; +/** Options accepted by htmlparser2, the default parser for XML. */ +export interface HTMLParser2Options extends DomHandlerOptions, ParserOptions { +} +/** Options for parse5, the default parser for HTML. */ +export interface Parse5Options { + /** Disable scripting in parse5, so noscript tags would be parsed. */ + scriptingEnabled?: boolean; + /** Enable location support for parse5. */ + sourceCodeLocationInfo?: boolean; +} +/** Internal options for Cheerio. */ +export interface InternalOptions extends HTMLParser2Options, Parse5Options { + _useHtmlParser2?: boolean; +} +/** + * Options accepted by Cheerio. + * + * Please note that parser-specific options are *only recognized* if the + * relevant parser is used. + */ +export interface CheerioOptions extends HTMLParser2Options, Parse5Options { + /** Suggested way of configuring htmlparser2 when wanting to parse XML. */ + xml?: HTMLParser2Options | boolean; +} +declare const defaultOpts: CheerioOptions; +/** Cheerio default options. */ +export default defaultOpts; +export declare function flatten(options?: CheerioOptions | null): InternalOptions | undefined; +//# sourceMappingURL=options.d.ts.map
\ No newline at end of file diff --git a/node_modules/cheerio/lib/options.d.ts.map b/node_modules/cheerio/lib/options.d.ts.map new file mode 100644 index 0000000..8b6d57f --- /dev/null +++ b/node_modules/cheerio/lib/options.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,mEAAmE;AACnE,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB,EAAE,aAAa;CAAG;AAC/E,uDAAuD;AACvD,MAAM,WAAW,aAAa;IAC5B,qEAAqE;IACrE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,0CAA0C;IAC1C,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,oCAAoC;AACpC,MAAM,WAAW,eAAgB,SAAQ,kBAAkB,EAAE,aAAa;IACxE,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAe,SAAQ,kBAAkB,EAAE,aAAa;IACvE,0EAA0E;IAC1E,GAAG,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC;CACpC;AAED,QAAA,MAAM,WAAW,EAAE,cAGlB,CAAC;AAEF,+BAA+B;AAC/B,eAAe,WAAW,CAAC;AAO3B,wBAAgB,OAAO,CACrB,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI,GAC9B,eAAe,GAAG,SAAS,CAM7B"}
\ No newline at end of file diff --git a/node_modules/cheerio/lib/options.js b/node_modules/cheerio/lib/options.js new file mode 100644 index 0000000..cddb475 --- /dev/null +++ b/node_modules/cheerio/lib/options.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.flatten = void 0; +var tslib_1 = require("tslib"); +var defaultOpts = { + xml: false, + decodeEntities: true, +}; +/** Cheerio default options. */ +exports.default = defaultOpts; +var xmlModeDefault = { + _useHtmlParser2: true, + xmlMode: true, +}; +function flatten(options) { + return (options === null || options === void 0 ? void 0 : options.xml) + ? typeof options.xml === 'boolean' + ? xmlModeDefault + : tslib_1.__assign(tslib_1.__assign({}, xmlModeDefault), options.xml) + : options !== null && options !== void 0 ? options : undefined; +} +exports.flatten = flatten; diff --git a/node_modules/cheerio/lib/parse.d.ts b/node_modules/cheerio/lib/parse.d.ts new file mode 100644 index 0000000..87adbe1 --- /dev/null +++ b/node_modules/cheerio/lib/parse.d.ts @@ -0,0 +1,13 @@ +/// <reference types="node" /> +import { Node, Document, NodeWithChildren } from 'domhandler'; +import type { InternalOptions } from './options'; +export default function parse(content: string | Document | Node | Node[] | Buffer, options: InternalOptions, isDocument: boolean): Document; +/** + * Update the dom structure, for one changed layer. + * + * @param newChilds - The new children. + * @param parent - The new parent. + * @returns The parent node. + */ +export declare function update(newChilds: Node[] | Node, parent: NodeWithChildren | null): Node | null; +//# sourceMappingURL=parse.d.ts.map
\ No newline at end of file diff --git a/node_modules/cheerio/lib/parse.d.ts.map b/node_modules/cheerio/lib/parse.d.ts.map new file mode 100644 index 0000000..8b429ec --- /dev/null +++ b/node_modules/cheerio/lib/parse.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":";AAGA,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,gBAAgB,EAEjB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAKjD,MAAM,CAAC,OAAO,UAAU,KAAK,CAC3B,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,GAAG,IAAI,EAAE,GAAG,MAAM,EACnD,OAAO,EAAE,eAAe,EACxB,UAAU,EAAE,OAAO,GAClB,QAAQ,CAyBV;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CACpB,SAAS,EAAE,IAAI,EAAE,GAAG,IAAI,EACxB,MAAM,EAAE,gBAAgB,GAAG,IAAI,GAC9B,IAAI,GAAG,IAAI,CA+Bb"}
\ No newline at end of file diff --git a/node_modules/cheerio/lib/parse.js b/node_modules/cheerio/lib/parse.js new file mode 100644 index 0000000..cd92fc9 --- /dev/null +++ b/node_modules/cheerio/lib/parse.js @@ -0,0 +1,67 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.update = void 0; +var htmlparser2_1 = require("htmlparser2"); +var htmlparser2_adapter_1 = require("./parsers/htmlparser2-adapter"); +var parse5_adapter_1 = require("./parsers/parse5-adapter"); +var domhandler_1 = require("domhandler"); +/* + * Parser + */ +function parse(content, options, isDocument) { + if (typeof Buffer !== 'undefined' && Buffer.isBuffer(content)) { + content = content.toString(); + } + if (typeof content === 'string') { + return options.xmlMode || options._useHtmlParser2 + ? htmlparser2_adapter_1.parse(content, options) + : parse5_adapter_1.parse(content, options, isDocument); + } + var doc = content; + if (!Array.isArray(doc) && domhandler_1.isDocument(doc)) { + // If `doc` is already a root, just return it + return doc; + } + // Add conent to new root element + var root = new domhandler_1.Document([]); + // Update the DOM using the root + update(doc, root); + return root; +} +exports.default = parse; +/** + * Update the dom structure, for one changed layer. + * + * @param newChilds - The new children. + * @param parent - The new parent. + * @returns The parent node. + */ +function update(newChilds, parent) { + // Normalize + var arr = Array.isArray(newChilds) ? newChilds : [newChilds]; + // Update parent + if (parent) { + parent.children = arr; + } + else { + parent = null; + } + // Update neighbors + for (var i = 0; i < arr.length; i++) { + var node = arr[i]; + // Cleanly remove existing nodes from their previous structures. + if (node.parent && node.parent.children !== arr) { + htmlparser2_1.DomUtils.removeElement(node); + } + if (parent) { + node.prev = arr[i - 1] || null; + node.next = arr[i + 1] || null; + } + else { + node.prev = node.next = null; + } + node.parent = parent; + } + return parent; +} +exports.update = update; diff --git a/node_modules/cheerio/lib/parsers/htmlparser2-adapter.d.ts b/node_modules/cheerio/lib/parsers/htmlparser2-adapter.d.ts new file mode 100644 index 0000000..7437310 --- /dev/null +++ b/node_modules/cheerio/lib/parsers/htmlparser2-adapter.d.ts @@ -0,0 +1,3 @@ +export { parseDocument as parse } from 'htmlparser2'; +export { default as render } from 'dom-serializer'; +//# sourceMappingURL=htmlparser2-adapter.d.ts.map
\ No newline at end of file diff --git a/node_modules/cheerio/lib/parsers/htmlparser2-adapter.d.ts.map b/node_modules/cheerio/lib/parsers/htmlparser2-adapter.d.ts.map new file mode 100644 index 0000000..eaf18b9 --- /dev/null +++ b/node_modules/cheerio/lib/parsers/htmlparser2-adapter.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"htmlparser2-adapter.d.ts","sourceRoot":"","sources":["../../src/parsers/htmlparser2-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,KAAK,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,gBAAgB,CAAC"}
\ No newline at end of file diff --git a/node_modules/cheerio/lib/parsers/htmlparser2-adapter.js b/node_modules/cheerio/lib/parsers/htmlparser2-adapter.js new file mode 100644 index 0000000..a05f08d --- /dev/null +++ b/node_modules/cheerio/lib/parsers/htmlparser2-adapter.js @@ -0,0 +1,10 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.render = exports.parse = void 0; +var htmlparser2_1 = require("htmlparser2"); +Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return htmlparser2_1.parseDocument; } }); +var dom_serializer_1 = require("dom-serializer"); +Object.defineProperty(exports, "render", { enumerable: true, get: function () { return __importDefault(dom_serializer_1).default; } }); diff --git a/node_modules/cheerio/lib/parsers/parse5-adapter.d.ts b/node_modules/cheerio/lib/parsers/parse5-adapter.d.ts new file mode 100644 index 0000000..c262aec --- /dev/null +++ b/node_modules/cheerio/lib/parsers/parse5-adapter.d.ts @@ -0,0 +1,9 @@ +import { Node, Document } from 'domhandler'; +import type { InternalOptions } from '../options'; +interface Parse5Options extends InternalOptions { + context?: Node; +} +export declare function parse(content: string, options: Parse5Options, isDocument?: boolean): Document; +export declare function render(dom: Node | ArrayLike<Node>): string; +export {}; +//# sourceMappingURL=parse5-adapter.d.ts.map
\ No newline at end of file diff --git a/node_modules/cheerio/lib/parsers/parse5-adapter.d.ts.map b/node_modules/cheerio/lib/parsers/parse5-adapter.d.ts.map new file mode 100644 index 0000000..0f3fa87 --- /dev/null +++ b/node_modules/cheerio/lib/parsers/parse5-adapter.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"parse5-adapter.d.ts","sourceRoot":"","sources":["../../src/parsers/parse5-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAc,MAAM,YAAY,CAAC;AAGxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,UAAU,aAAc,SAAQ,eAAe;IAC7C,OAAO,CAAC,EAAE,IAAI,CAAC;CAChB;AAED,wBAAgB,KAAK,CACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,aAAa,EACtB,UAAU,CAAC,EAAE,OAAO,GACnB,QAAQ,CAiBV;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,MAAM,CAgB1D"}
\ No newline at end of file diff --git a/node_modules/cheerio/lib/parsers/parse5-adapter.js b/node_modules/cheerio/lib/parsers/parse5-adapter.js new file mode 100644 index 0000000..4b480b1 --- /dev/null +++ b/node_modules/cheerio/lib/parsers/parse5-adapter.js @@ -0,0 +1,41 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.render = exports.parse = void 0; +var tslib_1 = require("tslib"); +var domhandler_1 = require("domhandler"); +var parse5_1 = require("parse5"); +var parse5_htmlparser2_tree_adapter_1 = tslib_1.__importDefault(require("parse5-htmlparser2-tree-adapter")); +function parse(content, options, isDocument) { + var opts = { + scriptingEnabled: typeof options.scriptingEnabled === 'boolean' + ? options.scriptingEnabled + : true, + treeAdapter: parse5_htmlparser2_tree_adapter_1.default, + sourceCodeLocationInfo: options.sourceCodeLocationInfo, + }; + var context = options.context; + // @ts-expect-error The tree adapter unfortunately doesn't return the exact types. + return isDocument + ? parse5_1.parse(content, opts) + : // @ts-expect-error Same issue again. + parse5_1.parseFragment(context, content, opts); +} +exports.parse = parse; +function render(dom) { + var _a; + /* + * `dom-serializer` passes over the special "root" node and renders the + * node's children in its place. To mimic this behavior with `parse5`, an + * equivalent operation must be applied to the input array. + */ + var nodes = 'length' in dom ? dom : [dom]; + for (var index = 0; index < nodes.length; index += 1) { + var node = nodes[index]; + if (domhandler_1.isDocument(node)) { + (_a = Array.prototype.splice).call.apply(_a, tslib_1.__spreadArray([nodes, index, 1], node.children)); + } + } + // @ts-expect-error Types don't align here either. + return parse5_1.serialize({ children: nodes }, { treeAdapter: parse5_htmlparser2_tree_adapter_1.default }); +} +exports.render = render; diff --git a/node_modules/cheerio/lib/static.d.ts b/node_modules/cheerio/lib/static.d.ts new file mode 100644 index 0000000..666c243 --- /dev/null +++ b/node_modules/cheerio/lib/static.d.ts @@ -0,0 +1,88 @@ +import type { CheerioAPI, Cheerio } from '.'; +import { Node, Document } from 'domhandler'; +import { CheerioOptions } from './options'; +/** + * Renders the document. + * + * @param options - Options for the renderer. + * @returns The rendered document. + */ +export declare function html(this: CheerioAPI | void, options?: CheerioOptions): string; +/** + * Renders the document. + * + * @param dom - Element to render. + * @param options - Options for the renderer. + * @returns The rendered document. + */ +export declare function html(this: CheerioAPI | void, dom?: string | ArrayLike<Node> | Node, options?: CheerioOptions): string; +/** + * Render the document as XML. + * + * @param dom - Element to render. + * @returns THe rendered document. + */ +export declare function xml(this: CheerioAPI, dom?: string | ArrayLike<Node> | Node): string; +/** + * Render the document as text. + * + * @param elements - Elements to render. + * @returns The rendered document. + */ +export declare function text(this: CheerioAPI | void, elements?: ArrayLike<Node>): string; +/** + * Parses a string into an array of DOM nodes. The `context` argument has no + * meaning for Cheerio, but it is maintained for API compatibility with jQuery. + * + * @param data - Markup that will be parsed. + * @param context - Will be ignored. If it is a boolean it will be used as the + * value of `keepScripts`. + * @param keepScripts - If false all scripts will be removed. + * @returns The parsed DOM. + * @alias Cheerio.parseHTML + * @see {@link https://api.jquery.com/jQuery.parseHTML/} + */ +export declare function parseHTML(this: CheerioAPI, data: string, context?: unknown | boolean, keepScripts?: boolean): Node[]; +export declare function parseHTML(this: CheerioAPI, data?: '' | null): null; +/** + * Sometimes you need to work with the top-level root element. To query it, you + * can use `$.root()`. + * + * @example + * + * ```js + * $.root().append('<ul id="vegetables"></ul>').html(); + * //=> <ul id="fruits">...</ul><ul id="vegetables"></ul> + * ``` + * + * @returns Cheerio instance wrapping the root node. + * @alias Cheerio.root + */ +export declare function root(this: CheerioAPI): Cheerio<Document>; +/** + * Checks to see if the `contained` DOM element is a descendant of the + * `container` DOM element. + * + * @param container - Potential parent node. + * @param contained - Potential child node. + * @returns Indicates if the nodes contain one another. + * @alias Cheerio.contains + * @see {@link https://api.jquery.com/jQuery.contains/} + */ +export declare function contains(container: Node, contained: Node): boolean; +interface WritableArrayLike<T> extends ArrayLike<T> { + length: number; + [n: number]: T; +} +/** + * $.merge(). + * + * @param arr1 - First array. + * @param arr2 - Second array. + * @returns `arr1`, with elements of `arr2` inserted. + * @alias Cheerio.merge + * @see {@link https://api.jquery.com/jQuery.merge/} + */ +export declare function merge<T>(arr1: WritableArrayLike<T>, arr2: ArrayLike<T>): ArrayLike<T> | undefined; +export {}; +//# sourceMappingURL=static.d.ts.map
\ No newline at end of file diff --git a/node_modules/cheerio/lib/static.d.ts.map b/node_modules/cheerio/lib/static.d.ts.map new file mode 100644 index 0000000..1c99261 --- /dev/null +++ b/node_modules/che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EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CAExD;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,GAAG,OAAO,CAmBlE;AAED,UAAU,iBAAiB,CAAC,CAAC,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,CAAC,EACrB,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC1B,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,GACjB,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAY1B"}
\ No newline at end of file diff --git a/node_modules/cheerio/lib/static.js b/node_modules/cheerio/lib/static.js new file mode 100644 index 0000000..7e9fbb3 --- /dev/null +++ b/node_modules/cheerio/lib/static.js @@ -0,0 +1,207 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.merge = exports.contains = exports.root = exports.parseHTML = exports.text = exports.xml = exports.html = void 0; +var tslib_1 = require("tslib"); +var options_1 = tslib_1.__importStar(require("./options")); +var cheerio_select_1 = require("cheerio-select"); +var htmlparser2_1 = require("htmlparser2"); +var parse5_adapter_1 = require("./parsers/parse5-adapter"); +var htmlparser2_adapter_1 = require("./parsers/htmlparser2-adapter"); +/** + * Helper function to render a DOM. + * + * @param that - Cheerio instance to render. + * @param dom - The DOM to render. Defaults to `that`'s root. + * @param options - Options for rendering. + * @returns The rendered document. + */ +function render(that, dom, options) { + var _a; + var toRender = dom + ? typeof dom === 'string' + ? cheerio_select_1.select(dom, (_a = that === null || that === void 0 ? void 0 : that._root) !== null && _a !== void 0 ? _a : [], options) + : dom + : that === null || that === void 0 ? void 0 : that._root.children; + if (!toRender) + return ''; + return options.xmlMode || options._useHtmlParser2 + ? htmlparser2_adapter_1.render(toRender, options) + : parse5_adapter_1.render(toRender); +} +/** + * Checks if a passed object is an options object. + * + * @param dom - Object to check if it is an options object. + * @returns Whether the object is an options object. + */ +function isOptions(dom) { + return (typeof dom === 'object' && + dom != null && + !('length' in dom) && + !('type' in dom)); +} +function html(dom, options) { + /* + * Be flexible about parameters, sometimes we call html(), + * with options as only parameter + * check dom argument for dom element specific properties + * assume there is no 'length' or 'type' properties in the options object + */ + if (!options && isOptions(dom)) { + options = dom; + dom = undefined; + } + /* + * Sometimes `$.html()` is used without preloading html, + * so fallback non-existing options to the default ones. + */ + var opts = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, options_1.default), (this ? this._options : {})), options_1.flatten(options !== null && options !== void 0 ? options : {})); + return render(this || undefined, dom, opts); +} +exports.html = html; +/** + * Render the document as XML. + * + * @param dom - Element to render. + * @returns THe rendered document. + */ +function xml(dom) { + var options = tslib_1.__assign(tslib_1.__assign({}, this._options), { xmlMode: true }); + return render(this, dom, options); +} +exports.xml = xml; +/** + * Render the document as text. + * + * @param elements - Elements to render. + * @returns The rendered document. + */ +function text(elements) { + var elems = elements ? elements : this ? this.root() : []; + var ret = ''; + for (var i = 0; i < elems.length; i++) { + var elem = elems[i]; + if (htmlparser2_1.DomUtils.isText(elem)) + ret += elem.data; + else if (htmlparser2_1.DomUtils.hasChildren(elem) && + elem.type !== htmlparser2_1.ElementType.Comment && + elem.type !== htmlparser2_1.ElementType.Script && + elem.type !== htmlparser2_1.ElementType.Style) { + ret += text(elem.children); + } + } + return ret; +} +exports.text = text; +function parseHTML(data, context, keepScripts) { + if (keepScripts === void 0) { keepScripts = typeof context === 'boolean' ? context : false; } + if (!data || typeof data !== 'string') { + return null; + } + if (typeof context === 'boolean') { + keepScripts = context; + } + var parsed = this.load(data, options_1.default, false); + if (!keepScripts) { + parsed('script').remove(); + } + /* + * The `children` array is used by Cheerio internally to group elements that + * share the same parents. When nodes created through `parseHTML` are + * inserted into previously-existing DOM structures, they will be removed + * from the `children` array. The results of `parseHTML` should remain + * constant across these operations, so a shallow copy should be returned. + */ + return parsed.root()[0].children.slice(); +} +exports.parseHTML = parseHTML; +/** + * Sometimes you need to work with the top-level root element. To query it, you + * can use `$.root()`. + * + * @example + * + * ```js + * $.root().append('<ul id="vegetables"></ul>').html(); + * //=> <ul id="fruits">...</ul><ul id="vegetables"></ul> + * ``` + * + * @returns Cheerio instance wrapping the root node. + * @alias Cheerio.root + */ +function root() { + return this(this._root); +} +exports.root = root; +/** + * Checks to see if the `contained` DOM element is a descendant of the + * `container` DOM element. + * + * @param container - Potential parent node. + * @param contained - Potential child node. + * @returns Indicates if the nodes contain one another. + * @alias Cheerio.contains + * @see {@link https://api.jquery.com/jQuery.contains/} + */ +function contains(container, contained) { + // According to the jQuery API, an element does not "contain" itself + if (contained === container) { + return false; + } + /* + * Step up the descendants, stopping when the root element is reached + * (signaled by `.parent` returning a reference to the same object) + */ + var next = contained; + while (next && next !== next.parent) { + next = next.parent; + if (next === container) { + return true; + } + } + return false; +} +exports.contains = contains; +/** + * $.merge(). + * + * @param arr1 - First array. + * @param arr2 - Second array. + * @returns `arr1`, with elements of `arr2` inserted. + * @alias Cheerio.merge + * @see {@link https://api.jquery.com/jQuery.merge/} + */ +function merge(arr1, arr2) { + if (!isArrayLike(arr1) || !isArrayLike(arr2)) { + return; + } + var newLength = arr1.length; + var len = +arr2.length; + for (var i = 0; i < len; i++) { + arr1[newLength++] = arr2[i]; + } + arr1.length = newLength; + return arr1; +} +exports.merge = merge; +/** + * @param item - Item to check. + * @returns Indicates if the item is array-like. + */ +function isArrayLike(item) { + if (Array.isArray(item)) { + return true; + } + if (typeof item !== 'object' || + !Object.prototype.hasOwnProperty.call(item, 'length') || + typeof item.length !== 'number' || + item.length < 0) { + return false; + } + for (var i = 0; i < item.length; i++) { + if (!(i in item)) { + return false; + } + } + return true; +} diff --git a/node_modules/cheerio/lib/types.d.ts b/node_modules/cheerio/lib/types.d.ts new file mode 100644 index 0000000..d590e7c --- /dev/null +++ b/node_modules/cheerio/lib/types.d.ts @@ -0,0 +1,20 @@ +declare type LowercaseLetters = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z'; +declare type AlphaNumeric = LowercaseLetters | Uppercase<LowercaseLetters> | `${number}`; +declare type SelectorSpecial = '.' | '#' | ':' | '|' | '>' | '+' | '~' | '['; +/** + * Type for identifying selectors. Allows us to "upgrade" queries using + * selectors to return `Element`s. + */ +export declare type SelectorType = `${SelectorSpecial}${AlphaNumeric}${string}` | `${AlphaNumeric}${string}`; +import type { Cheerio } from './cheerio'; +import type { Node } from 'domhandler'; +/** Elements that can be passed to manipulation methods. */ +export declare type BasicAcceptedElems<T extends Node> = Cheerio<T> | T[] | T | string; +/** Elements that can be passed to manipulation methods, including functions. */ +export declare type AcceptedElems<T extends Node> = BasicAcceptedElems<T> | ((this: T, i: number, el: T) => BasicAcceptedElems<T>); +/** Function signature, for traversal methods. */ +export declare type FilterFunction<T> = (this: T, i: number, el: T) => boolean; +/** Supported filter types, for traversal methods. */ +export declare type AcceptedFilters<T> = string | FilterFunction<T> | T | Cheerio<T>; +export {}; +//# sourceMappingURL=types.d.ts.map
\ No newline at end of file diff --git a/node_modules/cheerio/lib/types.d.ts.map b/node_modules/cheerio/lib/types.d.ts.map new file mode 100644 index 0000000..39e3f4d --- /dev/null +++ b/node_modules/cheerio/lib/types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,aAAK,gBAAgB,GACjB,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,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ib/types.js b/node_modules/cheerio/lib/types.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/node_modules/cheerio/lib/types.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/node_modules/cheerio/lib/utils.d.ts b/node_modules/cheerio/lib/utils.d.ts new file mode 100644 index 0000000..1e5e0c1 --- /dev/null +++ b/node_modules/cheerio/lib/utils.d.ts @@ -0,0 +1,73 @@ +import { DomUtils } from 'htmlparser2'; +import { Node } from 'domhandler'; +import type { Cheerio } from './cheerio'; +/** + * Check if the DOM element is a tag. + * + * `isTag(type)` includes `<script>` and `<style>` tags. + * + * @private + * @category Utils + * @param type - DOM node to check. + * @returns Whether the node is a tag. + */ +export declare const isTag: typeof DomUtils.isTag; +/** + * Checks if an object is a Cheerio instance. + * + * @category Utils + * @param maybeCheerio - The object to check. + * @returns Whether the object is a Cheerio instance. + */ +export declare function isCheerio<T>(maybeCheerio: any): maybeCheerio is Cheerio<T>; +/** + * Convert a string to camel case notation. + * + * @private + * @category Utils + * @param str - String to be converted. + * @returns String in camel case notation. + */ +export declare function camelCase(str: string): string; +/** + * Convert a string from camel case to "CSS case", where word boundaries are + * described by hyphens ("-") and all characters are lower-case. + * + * @private + * @category Utils + * @param str - String to be converted. + * @returns String in "CSS case". + */ +export declare function cssCase(str: string): string; +/** + * Iterate over each DOM element without creating intermediary Cheerio instances. + * + * This is indented for use internally to avoid otherwise unnecessary memory + * pressure introduced by _make. + * + * @category Utils + * @param array - Array to iterate over. + * @param fn - Function to call. + * @returns The original instance. + */ +export declare function domEach<T extends Node, Arr extends ArrayLike<T> = Cheerio<T>>(array: Arr, fn: (elem: T, index: number) => void): Arr; +/** + * Create a deep copy of the given DOM structure. Sets the parents of the copies + * of the passed nodes to `null`. + * + * @private + * @category Utils + * @param dom - The htmlparser2-compliant DOM structure. + * @returns - The cloned DOM. + */ +export declare function cloneDom<T extends Node>(dom: T | T[]): T[]; +/** + * Check if string is HTML. + * + * @private + * @category Utils + * @param str - String to check. + * @returns Indicates if `str` is HTML. + */ +export declare function isHtml(str: string): boolean; +//# sourceMappingURL=utils.d.ts.map
\ No newline at end of file diff --git a/node_modules/cheerio/lib/utils.d.ts.map b/node_modules/cheerio/lib/utils.d.ts.map new file mode 100644 index 0000000..20ca00a --- /dev/null +++ b/node_modules/cheerio/lib/utils.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,IAAI,EAAuB,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;;;;;;;;GASG;AACH,eAAO,MAAQ,KAAK,uBAAa,CAAC;AAElC;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,YAAY,EAAE,GAAG,GAAG,YAAY,IAAI,OAAO,CAAC,CAAC,CAAC,CAE1E;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,IAAI,EAAE,GAAG,SAAS,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAC3E,KAAK,EAAE,GAAG,EACV,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GACnC,GAAG,CAIL;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,CAa1D;AAUD;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAG3C"}
\ No newline at end of file diff --git a/node_modules/cheerio/lib/utils.js b/node_modules/cheerio/lib/utils.js new file mode 100644 index 0000000..2133d64 --- /dev/null +++ b/node_modules/cheerio/lib/utils.js @@ -0,0 +1,111 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isHtml = exports.cloneDom = exports.domEach = exports.cssCase = exports.camelCase = exports.isCheerio = exports.isTag = void 0; +var htmlparser2_1 = require("htmlparser2"); +var domhandler_1 = require("domhandler"); +/** + * Check if the DOM element is a tag. + * + * `isTag(type)` includes `<script>` and `<style>` tags. + * + * @private + * @category Utils + * @param type - DOM node to check. + * @returns Whether the node is a tag. + */ +exports.isTag = htmlparser2_1.DomUtils.isTag; +/** + * Checks if an object is a Cheerio instance. + * + * @category Utils + * @param maybeCheerio - The object to check. + * @returns Whether the object is a Cheerio instance. + */ +function isCheerio(maybeCheerio) { + return maybeCheerio.cheerio != null; +} +exports.isCheerio = isCheerio; +/** + * Convert a string to camel case notation. + * + * @private + * @category Utils + * @param str - String to be converted. + * @returns String in camel case notation. + */ +function camelCase(str) { + return str.replace(/[_.-](\w|$)/g, function (_, x) { return x.toUpperCase(); }); +} +exports.camelCase = camelCase; +/** + * Convert a string from camel case to "CSS case", where word boundaries are + * described by hyphens ("-") and all characters are lower-case. + * + * @private + * @category Utils + * @param str - String to be converted. + * @returns String in "CSS case". + */ +function cssCase(str) { + return str.replace(/[A-Z]/g, '-$&').toLowerCase(); +} +exports.cssCase = cssCase; +/** + * Iterate over each DOM element without creating intermediary Cheerio instances. + * + * This is indented for use internally to avoid otherwise unnecessary memory + * pressure introduced by _make. + * + * @category Utils + * @param array - Array to iterate over. + * @param fn - Function to call. + * @returns The original instance. + */ +function domEach(array, fn) { + var len = array.length; + for (var i = 0; i < len; i++) + fn(array[i], i); + return array; +} +exports.domEach = domEach; +/** + * Create a deep copy of the given DOM structure. Sets the parents of the copies + * of the passed nodes to `null`. + * + * @private + * @category Utils + * @param dom - The htmlparser2-compliant DOM structure. + * @returns - The cloned DOM. + */ +function cloneDom(dom) { + var clone = 'length' in dom + ? Array.prototype.map.call(dom, function (el) { return domhandler_1.cloneNode(el, true); }) + : [domhandler_1.cloneNode(dom, true)]; + // Add a root node around the cloned nodes + var root = new domhandler_1.Document(clone); + clone.forEach(function (node) { + node.parent = root; + }); + return clone; +} +exports.cloneDom = cloneDom; +/** + * A simple way to check for HTML strings. Tests for a `<` within a string, + * immediate followed by a letter and eventually followed by a `>`. + * + * @private + */ +var quickExpr = /<[a-zA-Z][^]*>/; +/** + * Check if string is HTML. + * + * @private + * @category Utils + * @param str - String to check. + * @returns Indicates if `str` is HTML. + */ +function isHtml(str) { + // Run the regex + return quickExpr.test(str); +} +exports.isHtml = isHtml; |