From 22a25ded9f7d9c9a96cce8d1bc12475ca0434201 Mon Sep 17 00:00:00 2001 From: Minteck Date: Wed, 9 Feb 2022 17:58:07 +0100 Subject: Major update --- node_modules/cheerio/LICENSE | 21 + node_modules/cheerio/Readme.md | 319 ++++++++ node_modules/cheerio/lib/api/attributes.d.ts | 317 ++++++++ node_modules/cheerio/lib/api/attributes.d.ts.map | 1 + node_modules/cheerio/lib/api/attributes.js | 591 ++++++++++++++ node_modules/cheerio/lib/api/css.d.ts | 41 + node_modules/cheerio/lib/api/css.d.ts.map | 1 + node_modules/cheerio/lib/api/css.js | 95 +++ node_modules/cheerio/lib/api/forms.d.ts | 31 + node_modules/cheerio/lib/api/forms.d.ts.map | 1 + node_modules/cheerio/lib/api/forms.js | 84 ++ node_modules/cheerio/lib/api/manipulation.d.ts | 496 ++++++++++++ node_modules/cheerio/lib/api/manipulation.d.ts.map | 1 + node_modules/cheerio/lib/api/manipulation.js | 852 ++++++++++++++++++++ node_modules/cheerio/lib/api/traversing.d.ts | 644 +++++++++++++++ node_modules/cheerio/lib/api/traversing.d.ts.map | 1 + node_modules/cheerio/lib/api/traversing.js | 866 +++++++++++++++++++++ node_modules/cheerio/lib/cheerio.d.ts | 53 ++ node_modules/cheerio/lib/cheerio.d.ts.map | 1 + node_modules/cheerio/lib/cheerio.js | 115 +++ node_modules/cheerio/lib/index.d.ts | 91 +++ node_modules/cheerio/lib/index.d.ts.map | 1 + node_modules/cheerio/lib/index.js | 81 ++ node_modules/cheerio/lib/load.d.ts | 73 ++ node_modules/cheerio/lib/load.d.ts.map | 1 + node_modules/cheerio/lib/load.js | 53 ++ node_modules/cheerio/lib/options.d.ts | 31 + node_modules/cheerio/lib/options.d.ts.map | 1 + node_modules/cheerio/lib/options.js | 22 + node_modules/cheerio/lib/parse.d.ts | 13 + node_modules/cheerio/lib/parse.d.ts.map | 1 + node_modules/cheerio/lib/parse.js | 67 ++ .../cheerio/lib/parsers/htmlparser2-adapter.d.ts | 3 + .../lib/parsers/htmlparser2-adapter.d.ts.map | 1 + .../cheerio/lib/parsers/htmlparser2-adapter.js | 10 + .../cheerio/lib/parsers/parse5-adapter.d.ts | 9 + .../cheerio/lib/parsers/parse5-adapter.d.ts.map | 1 + node_modules/cheerio/lib/parsers/parse5-adapter.js | 41 + node_modules/cheerio/lib/static.d.ts | 88 +++ node_modules/cheerio/lib/static.d.ts.map | 1 + node_modules/cheerio/lib/static.js | 207 +++++ node_modules/cheerio/lib/types.d.ts | 20 + node_modules/cheerio/lib/types.d.ts.map | 1 + node_modules/cheerio/lib/types.js | 2 + node_modules/cheerio/lib/utils.d.ts | 73 ++ node_modules/cheerio/lib/utils.d.ts.map | 1 + node_modules/cheerio/lib/utils.js | 111 +++ node_modules/cheerio/package.json | 114 +++ 48 files changed, 5649 insertions(+) create mode 100644 node_modules/cheerio/LICENSE create mode 100644 node_modules/cheerio/Readme.md create mode 100644 node_modules/cheerio/lib/api/attributes.d.ts create mode 100644 node_modules/cheerio/lib/api/attributes.d.ts.map create mode 100644 node_modules/cheerio/lib/api/attributes.js create mode 100644 node_modules/cheerio/lib/api/css.d.ts create mode 100644 node_modules/cheerio/lib/api/css.d.ts.map create mode 100644 node_modules/cheerio/lib/api/css.js create mode 100644 node_modules/cheerio/lib/api/forms.d.ts create mode 100644 node_modules/cheerio/lib/api/forms.d.ts.map create mode 100644 node_modules/cheerio/lib/api/forms.js create mode 100644 node_modules/cheerio/lib/api/manipulation.d.ts create mode 100644 node_modules/cheerio/lib/api/manipulation.d.ts.map create mode 100644 node_modules/cheerio/lib/api/manipulation.js create mode 100644 node_modules/cheerio/lib/api/traversing.d.ts create mode 100644 node_modules/cheerio/lib/api/traversing.d.ts.map create mode 100644 node_modules/cheerio/lib/api/traversing.js create mode 100644 node_modules/cheerio/lib/cheerio.d.ts create mode 100644 node_modules/cheerio/lib/cheerio.d.ts.map create mode 100644 node_modules/cheerio/lib/cheerio.js create mode 100644 node_modules/cheerio/lib/index.d.ts create mode 100644 node_modules/cheerio/lib/index.d.ts.map create mode 100644 node_modules/cheerio/lib/index.js create mode 100644 node_modules/cheerio/lib/load.d.ts create mode 100644 node_modules/cheerio/lib/load.d.ts.map create mode 100644 node_modules/cheerio/lib/load.js create mode 100644 node_modules/cheerio/lib/options.d.ts create mode 100644 node_modules/cheerio/lib/options.d.ts.map create mode 100644 node_modules/cheerio/lib/options.js create mode 100644 node_modules/cheerio/lib/parse.d.ts create mode 100644 node_modules/cheerio/lib/parse.d.ts.map create mode 100644 node_modules/cheerio/lib/parse.js create mode 100644 node_modules/cheerio/lib/parsers/htmlparser2-adapter.d.ts create mode 100644 node_modules/cheerio/lib/parsers/htmlparser2-adapter.d.ts.map create mode 100644 node_modules/cheerio/lib/parsers/htmlparser2-adapter.js create mode 100644 node_modules/cheerio/lib/parsers/parse5-adapter.d.ts create mode 100644 node_modules/cheerio/lib/parsers/parse5-adapter.d.ts.map create mode 100644 node_modules/cheerio/lib/parsers/parse5-adapter.js create mode 100644 node_modules/cheerio/lib/static.d.ts create mode 100644 node_modules/cheerio/lib/static.d.ts.map create mode 100644 node_modules/cheerio/lib/static.js create mode 100644 node_modules/cheerio/lib/types.d.ts create mode 100644 node_modules/cheerio/lib/types.d.ts.map create mode 100644 node_modules/cheerio/lib/types.js create mode 100644 node_modules/cheerio/lib/utils.d.ts create mode 100644 node_modules/cheerio/lib/utils.d.ts.map create mode 100644 node_modules/cheerio/lib/utils.js create mode 100644 node_modules/cheerio/package.json (limited to 'node_modules/cheerio') diff --git a/node_modules/cheerio/LICENSE b/node_modules/cheerio/LICENSE new file mode 100644 index 0000000..40b9100 --- /dev/null +++ b/node_modules/cheerio/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 Matt Mueller + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/node_modules/cheerio/Readme.md b/node_modules/cheerio/Readme.md new file mode 100644 index 0000000..449d371 --- /dev/null +++ b/node_modules/cheerio/Readme.md @@ -0,0 +1,319 @@ +

cheerio

+ +
Fast, flexible & lean implementation of core jQuery designed specifically for the server.
+ +
+ + Build Status + + + Coverage + + + OpenCollective backers + + + OpenCollective sponsors + +
+ +
+ +[中文文档 (Chinese Readme)](https://github.com/cheeriojs/cheerio/wiki/Chinese-README) + +```js +const cheerio = require('cheerio'); +const $ = cheerio.load('

Hello world

'); + +$('h2.title').text('Hello there!'); +$('h2').addClass('welcome'); + +$.html(); +//=>

Hello there!

+``` + +## Note + +We are currently working on the 1.0.0 release of cheerio on the `main` branch. The source code for the last published version, `0.22.0`, can be found [here](https://github.com/cheeriojs/cheerio/tree/aa90399c9c02f12432bfff97b8f1c7d8ece7c307). + +## Installation + +`npm install cheerio` + +## Features + +**❤ Familiar syntax:** +Cheerio implements a subset of core jQuery. Cheerio removes all the DOM inconsistencies and browser cruft from the jQuery library, revealing its truly gorgeous API. + +**ϟ Blazingly fast:** +Cheerio works with a very simple, consistent DOM model. As a result parsing, manipulating, and rendering are incredibly efficient. + +**❁ Incredibly flexible:** +Cheerio wraps around [parse5](https://github.com/inikulin/parse5) parser and can optionally use @FB55's forgiving [htmlparser2](https://github.com/fb55/htmlparser2/). Cheerio can parse nearly any HTML or XML document. + +## Cheerio is not a web browser + +Cheerio parses markup and provides an API for traversing/manipulating the resulting data structure. It does not interpret the result as a web browser does. Specifically, it does _not_ produce a visual rendering, apply CSS, load external resources, or execute JavaScript. This makes Cheerio **much, much faster than other solutions**. If your use case requires any of this functionality, you should consider projects like [Puppeteer](https://github.com/puppeteer/puppeteer) or [JSDom](https://github.com/jsdom/jsdom). + +## API + +### Markup example we'll be using: + +```html + +``` + +This is the HTML markup we will be using in all of the API examples. + +### Loading + +First you need to load in the HTML. This step in jQuery is implicit, since jQuery operates on the one, baked-in DOM. With Cheerio, we need to pass in the HTML document. + +This is the _preferred_ method: + +```js +// ES6 or TypeScript: +import * as cheerio from 'cheerio'; + +// In other environments: +const cheerio = require('cheerio'); + +const $ = cheerio.load(''); + +$.html(); +//=> +``` + +Similar to web browser contexts, `load` will introduce ``, ``, and `` elements if they are not already present. You can set `load`'s third argument to `false` to disable this. + +```js +const $ = cheerio.load('', null, false); + +$.html(); +//=> '' +``` + +Optionally, you can also load in the HTML by passing the string as the context: + +```js +$('ul', ''); +``` + +Or as the root: + +```js +$('li', 'ul', ''); +``` + +If you need to modify parsing options for XML input, you may pass an extra +object to `.load()`: + +```js +const $ = cheerio.load('', { + xml: { + normalizeWhitespace: true, + }, +}); +``` + +The options in the `xml` object are taken directly from [htmlparser2](https://github.com/fb55/htmlparser2/wiki/Parser-options), therefore any options that can be used in `htmlparser2` are valid in cheerio as well. When `xml` is set, the default options are: + +```js +{ + xmlMode: true, + decodeEntities: true, // Decode HTML entities. + withStartIndices: false, // Add a `startIndex` property to nodes. + withEndIndices: false, // Add an `endIndex` property to nodes. +} +``` + +For a full list of options and their effects, see [domhandler](https://github.com/fb55/DomHandler) and +[htmlparser2's options](https://github.com/fb55/htmlparser2/wiki/Parser-options). + +Some users may wish to parse markup with the `htmlparser2` library, and +traverse/manipulate the resulting structure with Cheerio. This may be the case +for those upgrading from pre-1.0 releases of Cheerio (which relied on +`htmlparser2`), for those dealing with invalid markup (because `htmlparser2` is +more forgiving), or for those operating in performance-critical situations +(because `htmlparser2` may be faster in some cases). Note that "more forgiving" +means `htmlparser2` has error-correcting mechanisms that aren't always a match +for the standards observed by web browsers. This behavior may be useful when +parsing non-HTML content. + +To support these cases, `load` also accepts a `htmlparser2`-compatible data +structure as its first argument. Users may install `htmlparser2`, use it to +parse input, and pass the result to `load`: + +```js +// Usage as of htmlparser2 version 6: +const htmlparser2 = require('htmlparser2'); +const dom = htmlparser2.parseDocument(document, options); + +const $ = cheerio.load(dom); +``` + +### Selectors + +Cheerio's selector implementation is nearly identical to jQuery's, so the API is very similar. + +#### \$( selector, [context], [root] ) + +`selector` searches within the `context` scope which searches within the `root` scope. `selector` and `context` can be a string expression, DOM Element, array of DOM elements, or cheerio object. `root` is typically the HTML document string. + +This selector method is the starting point for traversing and manipulating the document. Like jQuery, it's the primary method for selecting elements in the document. + +```js +$('.apple', '#fruits').text(); +//=> Apple + +$('ul .pear').attr('class'); +//=> pear + +$('li[class=orange]').html(); +//=> Orange +``` + +##### XML Namespaces + +You can select with XML Namespaces but [due to the CSS specification](https://www.w3.org/TR/2011/REC-css3-selectors-20110929/#attribute-selectors), the colon (`:`) needs to be escaped for the selector to be valid. + +```js +$('[xml\\:id="main"'); +``` + +### Rendering + +When you're ready to render the document, you can call the `html` method on the "root" selection: + +```js +$.root().html(); +//=> +// +// +// +// +// +``` + +If you want to render the [`outerHTML`](https://developer.mozilla.org/en-US/docs/Web/API/Element/outerHTML) of a selection, you can use the `html` utility functon: + +```js +cheerio.html($('.pear')); +//=>
  • Pear
  • +``` + +By default, `html` will leave some tags open. Sometimes you may instead want to render a valid XML document. For example, you might parse the following XML snippet: + +```js +const $ = cheerio.load( + '' +); +``` + +... and later want to render to XML. To do this, you can use the 'xml' utility function: + +```js +$.xml(); +//=> +``` + +You may also render the text content of a Cheerio object using the `text` static method: + +```js +const $ = cheerio.load('This is content.'); +cheerio.text($('body')); +//=> This is content. +``` + +### Plugins + +Once you have loaded a document, you may extend the prototype or the equivalent `fn` property with custom plugin methods: + +```js +const $ = cheerio.load('Hello, world!'); +$.prototype.logHtml = function () { + console.log(this.html()); +}; + +$('body').logHtml(); // logs "Hello, world!" to the console +``` + +If you're using TypeScript, you should also add a type definition for your new method: + +```ts +declare module 'cheerio' { + interface Cheerio { + logHtml(this: Cheerio): void; + } +} +``` + +### The "DOM Node" object + +Cheerio collections are made up of objects that bear some resemblance to [browser-based DOM nodes](https://developer.mozilla.org/en-US/docs/Web/API/Node). You can expect them to define the following properties: + +- `tagName` +- `parentNode` +- `previousSibling` +- `nextSibling` +- `nodeValue` +- `firstChild` +- `childNodes` +- `lastChild` + +## Screencasts + +[https://vimeo.com/31950192](https://vimeo.com/31950192) + +> This video tutorial is a follow-up to Nettut's "How to Scrape Web Pages with Node.js and jQuery", using cheerio instead of JSDOM + jQuery. This video shows how easy it is to use cheerio and how much faster cheerio is than JSDOM + jQuery. + +## Cheerio in the real world + +Are you using cheerio in production? Add it to the [wiki](https://github.com/cheeriojs/cheerio/wiki/Cheerio-in-Production)! + +## Sponsors + +Does your company use Cheerio in production? Please consider [sponsoring this project](https://github.com/cheeriojs/cheerio?sponsor=1)! Your help will allow maintainers to dedicate more time and resources to its development and support. + + + +![Substack](https://avatars.githubusercontent.com/u/53023767?v=4&s=128) +![Airbnb](https://images.opencollective.com/airbnb/d327d66/logo.png) + + + +## Backers + +[Become a backer](https://github.com/cheeriojs/cheerio?sponsor=1) to show your support for Cheerio and help us maintain and improve this open source project. + + + +![Espen Klem](https://images.opencollective.com/espenklem/6075b19/avatar.png) +![Nishant Singh](https://avatars.githubusercontent.com/u/10304344?u=9cd1389a1a8211b64979ca3693f96d90f5bf0be9&v=4&s=128) + + + +## Special Thanks + +This library stands on the shoulders of some incredible developers. A special thanks to: + +**• @FB55 for node-htmlparser2 & CSSSelect:** +Felix has a knack for writing speedy parsing engines. He completely re-wrote both @tautologistic's `node-htmlparser` and @harry's `node-soupselect` from the ground up, making both of them much faster and more flexible. Cheerio would not be possible without his foundational work + +**• @jQuery team for jQuery:** +The core API is the best of its class and despite dealing with all the browser inconsistencies the code base is extremely clean and easy to follow. Much of cheerio's implementation and documentation is from jQuery. Thanks guys. + +**• @visionmedia:** +The style, the structure, the open-source"-ness" of this library comes from studying TJ's style and using many of his libraries. This dude consistently pumps out high-quality libraries and has always been more than willing to help or answer questions. You rock TJ. + +## License + +MIT 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(this: Cheerio, 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(this: Cheerio): Record; +/** + * 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(); + * //=>
  • Apple
  • + * ``` + * + * @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(this: Cheerio, name: string, value?: string | null | ((this: Element, i: number, attrib: string) => string | null)): Cheerio; +/** + * 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(); + * //=>
  • Apple
  • + * ``` + * + * @param values - Map of attribute names and values. + * @returns The instance itself. + * @see {@link https://api.jquery.com/attr/} + */ +export declare function attr(this: Cheerio, values: Record): Cheerio; +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(this: Cheerio, name: 'tagName' | 'nodeName'): T extends Element ? string : undefined; +export declare function prop(this: Cheerio, name: 'innerHTML' | 'outerHTML'): string | null; +export declare function prop(this: Cheerio, name: 'style'): StyleProp; +export declare function prop(this: Cheerio, name: K): Element[K]; +export declare function prop(this: Cheerio, name: K, value: Element[K] | ((this: Element, i: number, prop: K) => Element[keyof Element])): Cheerio; +export declare function prop(this: Cheerio, name: Record): Cheerio; +export declare function prop(this: Cheerio, name: string, value: string | boolean | null | ((this: Element, i: number, prop: string) => string | boolean)): Cheerio; +export declare function prop(this: Cheerio, name: string): string; +/** + * Method for getting data attributes, for only the first element in the matched set. + * + * @category Attributes + * @example + * + * ```js + * $('
    ').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(this: Cheerio, 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 + * $('
    ').data(); + * //=> { appleColor: 'red' } + * ``` + * + * @returns The data attribute's values. + * @see {@link https://api.jquery.com/data/} + */ +export declare function data(this: Cheerio): Record; +/** + * 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(this: Cheerio, name: string, value: unknown): Cheerio; +/** + * 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(this: Cheerio, values: Record): Cheerio; +/** + * 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(this: Cheerio): 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(); + * //=> + * ``` + * + * @param value - The new value. + * @returns The instance itself. + * @see {@link https://api.jquery.com/val/} + */ +export declare function val(this: Cheerio, value: string | string[]): Cheerio; +/** + * Method for removing attributes by `name`. + * + * @category Attributes + * @example + * + * ```js + * $('.pear').removeAttr('class').html(); + * //=>
  • Pear
  • + * + * $('.apple').attr('id', 'favorite'); + * $('.apple').removeAttr('id class').html(); + * //=>
  • Apple
  • + * ``` + * + * @param name - Name of the attribute. + * @returns The instance itself. + * @see {@link https://api.jquery.com/removeAttr/} + */ +export declare function removeAttr(this: Cheerio, name: string): Cheerio; +/** + * 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(this: Cheerio, className: string): boolean; +/** + * Adds class(es) to all of the matched elements. Also accepts a `function`. + * + * @category Attributes + * @example + * + * ```js + * $('.pear').addClass('fruit').html(); + * //=>
  • Pear
  • + * + * $('.apple').addClass('fruit red').html(); + * //=>
  • Apple
  • + * ``` + * + * @param value - Name of new class. + * @returns The instance itself. + * @see {@link https://api.jquery.com/addClass/} + */ +export declare function addClass>(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(); + * //=>
  • Pear
  • + * + * $('.apple').addClass('red').removeClass().html(); + * //=>
  • Apple
  • + * ``` + * + * @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>(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(); + * //=>
  • Apple
  • + * + * $('.apple.green').toggleClass('fruit green red', true).html(); + * //=>
  • Apple
  • + * ``` + * + * @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>(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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M,GAAG,SAAS,CAAC,GACxE,CAAC,CA0CH;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAChE,IAAI,EAAE,CAAC,EACP,KAAK,CAAC,EACF,MAAM,GACN,CAAC,CACC,IAAI,EAAE,OAAO,EACb,CAAC,EAAE,MAAM,EACT,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,OAAO,KACf,MAAM,CAAC,EAChB,QAAQ,CAAC,EAAE,OAAO,GACjB,CAAC,CA+CH"} \ No newline at end of file diff --git a/node_modules/cheerio/lib/api/attributes.js b/node_modules/cheerio/lib/api/attributes.js new file mode 100644 index 0000000..d67d310 --- /dev/null +++ b/node_modules/cheerio/lib/api/attributes.js @@ -0,0 +1,591 @@ +"use strict"; +/** + * Methods for getting and modifying attributes. + * + * @module cheerio/attributes + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.toggleClass = exports.removeClass = exports.addClass = exports.hasClass = exports.removeAttr = exports.val = exports.data = exports.prop = exports.attr = void 0; +var static_1 = require("../static"); +var utils_1 = require("../utils"); +var hasOwn = Object.prototype.hasOwnProperty; +var rspace = /\s+/; +var dataAttrPrefix = 'data-'; +/* + * Lookup table for coercing string data-* attributes to their corresponding + * JavaScript primitives + */ +var primitives = { + null: null, + true: true, + false: false, +}; +// Attributes that are booleans +var rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i; +// Matches strings that look like JSON objects or arrays +var rbrace = /^{[^]*}$|^\[[^]*]$/; +function getAttr(elem, name, xmlMode) { + var _a; + if (!elem || !utils_1.isTag(elem)) + return undefined; + (_a = elem.attribs) !== null && _a !== void 0 ? _a : (elem.attribs = {}); + // Return the entire attribs object if no attribute specified + if (!name) { + return elem.attribs; + } + if (hasOwn.call(elem.attribs, name)) { + // Get the (decoded) attribute + return !xmlMode && rboolean.test(name) ? name : elem.attribs[name]; + } + // Mimic the DOM and return text content as value for `option's` + if (elem.name === 'option' && name === 'value') { + return static_1.text(elem.children); + } + // Mimic DOM with default value for radios/checkboxes + if (elem.name === 'input' && + (elem.attribs.type === 'radio' || elem.attribs.type === 'checkbox') && + name === 'value') { + return 'on'; + } + return undefined; +} +/** + * Sets the value of an attribute. The attribute will be deleted if the value is `null`. + * + * @private + * @param el - The element to set the attribute on. + * @param name - The attribute's name. + * @param value - The attribute's value. + */ +function setAttr(el, name, value) { + if (value === null) { + removeAttribute(el, name); + } + else { + el.attribs[name] = "" + value; + } +} +function attr(name, value) { + // Set the value (with attr map support) + if (typeof name === 'object' || value !== undefined) { + if (typeof value === 'function') { + if (typeof name !== 'string') { + { + throw new Error('Bad combination of arguments.'); + } + } + return utils_1.domEach(this, function (el, i) { + if (utils_1.isTag(el)) + setAttr(el, name, value.call(el, i, el.attribs[name])); + }); + } + return utils_1.domEach(this, function (el) { + if (!utils_1.isTag(el)) + return; + if (typeof name === 'object') { + Object.keys(name).forEach(function (objName) { + var objValue = name[objName]; + setAttr(el, objName, objValue); + }); + } + else { + setAttr(el, name, value); + } + }); + } + return arguments.length > 1 + ? this + : getAttr(this[0], name, this.options.xmlMode); +} +exports.attr = attr; +/** + * Gets a node's prop. + * + * @private + * @category Attributes + * @param el - Elenent to get the prop of. + * @param name - Name of the prop. + * @returns The prop's value. + */ +function getProp(el, name, xmlMode) { + if (!el || !utils_1.isTag(el)) + return; + return name in el + ? // @ts-expect-error TS doesn't like us accessing the value directly here. + el[name] + : !xmlMode && rboolean.test(name) + ? getAttr(el, name, false) !== undefined + : getAttr(el, name, xmlMode); +} +/** + * Sets the value of a prop. + * + * @private + * @param el - The element to set the prop on. + * @param name - The prop's name. + * @param value - The prop's value. + */ +function setProp(el, name, value, xmlMode) { + if (name in el) { + // @ts-expect-error Overriding value + el[name] = value; + } + else { + setAttr(el, name, !xmlMode && rboolean.test(name) ? (value ? '' : null) : "" + value); + } +} +function prop(name, value) { + var _this = this; + if (typeof name === 'string' && value === undefined) { + switch (name) { + case 'style': { + var property_1 = this.css(); + var keys = Object.keys(property_1); + keys.forEach(function (p, i) { + property_1[i] = p; + }); + property_1.length = keys.length; + return property_1; + } + case 'tagName': + case 'nodeName': { + var el = this[0]; + return utils_1.isTag(el) ? el.name.toUpperCase() : undefined; + } + case 'outerHTML': + return this.clone().wrap('').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(); + * //=>
  • Pear
  • + * + * $('.apple').attr('id', 'favorite'); + * $('.apple').removeAttr('id class').html(); + * //=>
  • Apple
  • + * ``` + * + * @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(); + * //=>
  • Pear
  • + * + * $('.apple').addClass('fruit red').html(); + * //=>
  • Apple
  • + * ``` + * + * @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(); + * //=>
  • Pear
  • + * + * $('.apple').addClass('red').removeClass().html(); + * //=>
  • Apple
  • + * ``` + * + * @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(); + * //=>
  • Apple
  • + * + * $('.apple.green').toggleClass('fruit green red', true).html(); + * //=>
  • Apple
  • + * ``` + * + * @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(this: Cheerio, names?: string[]): Record; +/** + * 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(this: Cheerio, 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(this: Cheerio, prop: string, val: string | ((this: Element, i: number, style: string) => string | undefined)): Cheerio; +/** + * 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(this: Cheerio, prop: Record): Cheerio; +//# 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(this: Cheerio): string; +interface SerializedField { + name: string; + value: string; +} +/** + * Encode a set of form elements as an array of names and values. + * + * @category Forms + * @example + * + * ```js + * $('
    ').serializeArray(); + * //=> [ { name: 'foo', value: 'bar' } ] + * ``` + * + * @returns The serialized form. + * @see {@link https://api.jquery.com/serializeArray/} + */ +export declare function serializeArray(this: Cheerio): 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 + * $('
    ').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. `