diff options
Diffstat (limited to 'node_modules/cheerio/lib/api')
-rw-r--r-- | node_modules/cheerio/lib/api/attributes.d.ts | 317 | ||||
-rw-r--r-- | node_modules/cheerio/lib/api/attributes.d.ts.map | 1 | ||||
-rw-r--r-- | node_modules/cheerio/lib/api/attributes.js | 591 | ||||
-rw-r--r-- | node_modules/cheerio/lib/api/css.d.ts | 41 | ||||
-rw-r--r-- | node_modules/cheerio/lib/api/css.d.ts.map | 1 | ||||
-rw-r--r-- | node_modules/cheerio/lib/api/css.js | 95 | ||||
-rw-r--r-- | node_modules/cheerio/lib/api/forms.d.ts | 31 | ||||
-rw-r--r-- | node_modules/cheerio/lib/api/forms.d.ts.map | 1 | ||||
-rw-r--r-- | node_modules/cheerio/lib/api/forms.js | 84 | ||||
-rw-r--r-- | node_modules/cheerio/lib/api/manipulation.d.ts | 496 | ||||
-rw-r--r-- | node_modules/cheerio/lib/api/manipulation.d.ts.map | 1 | ||||
-rw-r--r-- | node_modules/cheerio/lib/api/manipulation.js | 852 | ||||
-rw-r--r-- | node_modules/cheerio/lib/api/traversing.d.ts | 644 | ||||
-rw-r--r-- | node_modules/cheerio/lib/api/traversing.d.ts.map | 1 | ||||
-rw-r--r-- | node_modules/cheerio/lib/api/traversing.js | 866 |
15 files changed, 4022 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,E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,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/manipulation.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"manipulation.d.ts","sourceRoot":"","sources":["../../src/api/manipulation.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAmC,MAAM,YAAY,CAAC;AAKnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAElE;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,IAAI,EAC1C,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,IAAI,CAAC,EAAE,kBAAkB,CAAC,IAAI,CAAC,EAC/B,KAAK,CAAC,EAAE,OAAO,GACd,IAAI,EAAE,CAiBR;AAoGD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,EACrC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,MAAM,EAAE,kBAAkB,CAAC,IAAI,CAAC,GAC/B,OAAO,CAAC,CAAC,CAAC,CAMZ;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,EACtC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,MAAM,EAAE,kBAAkB,CAAC,IAAI,CAAC,GAC/B,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ipulation.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,CA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AAG,CAAC,GAAG,CAAC,EAAE,EACpC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,GAC5B,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAIhB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,IAAI,EACpC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAIf"}
\ No newline at end of file diff --git a/node_modules/cheerio/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; |