Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump dependencies, update types #2503

Merged
merged 1 commit into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,808 changes: 1,433 additions & 1,375 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,20 @@
"node": ">= 6"
},
"dependencies": {
"cheerio-select": "^1.6.0",
"dom-serializer": "^1.3.2",
"domhandler": "^4.3.1",
"domutils": "^2.8.0",
"htmlparser2": "^7.2.0",
"cheerio-select": "^2.0.0",
"dom-serializer": "^2.0.0",
"domhandler": "^5.0.3",
"domutils": "^3.0.1",
"htmlparser2": "^8.0.1",
"parse5": "^7.0.0",
"parse5-htmlparser2-tree-adapter": "^6.0.1",
"parse5-htmlparser2-tree-adapter": "^7.0.0",
"tslib": "^2.4.0"
},
"devDependencies": {
"@octokit/graphql": "^4.8.0",
"@types/benchmark": "^2.1.1",
"@types/jest": "^27.4.1",
"@types/jsdom": "^16.2.14",
"@types/node": "^17.0.30",
"@types/parse5": "^6.0.3",
"@types/parse5-htmlparser2-tree-adapter": "^6.0.1",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"benchmark": "^2.1.4",
Expand Down
72 changes: 38 additions & 34 deletions src/api/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { text } from '../static';
import { isTag, domEach, camelCase, cssCase } from '../utils';
import type { Node, Element } from 'domhandler';
import type { AnyNode, Element } from 'domhandler';
import type { Cheerio } from '../cheerio';
import { innerText, textContent } from 'domutils';
const hasOwn = Object.prototype.hasOwnProperty;
Expand Down Expand Up @@ -40,17 +40,17 @@ const rbrace = /^{[^]*}$|^\[[^]*]$/;
* @returns The attribute's value.
*/
function getAttr(
elem: Node,
elem: AnyNode,
name: undefined,
xmlMode?: boolean
): Record<string, string>;
function getAttr(
elem: Node,
elem: AnyNode,
name: string,
xmlMode?: boolean
): string | undefined;
function getAttr(
elem: Node,
elem: AnyNode,
name: string | undefined,
xmlMode?: boolean
): Record<string, string> | string | undefined {
Expand Down Expand Up @@ -117,7 +117,7 @@ function setAttr(el: Element, name: string, value: string | null) {
* @returns The attribute's value.
* @see {@link https://api.jquery.com/attr/}
*/
export function attr<T extends Node>(
export function attr<T extends AnyNode>(
this: Cheerio<T>,
name: string
): string | undefined;
Expand All @@ -136,7 +136,9 @@ export function attr<T extends Node>(
* @returns The attribute's values.
* @see {@link https://api.jquery.com/attr/}
*/
export function attr<T extends Node>(this: Cheerio<T>): Record<string, string>;
export function attr<T extends AnyNode>(
this: Cheerio<T>
): Record<string, string>;

/**
* Method for setting attributes. Sets the attribute value for only the first
Expand All @@ -156,7 +158,7 @@ export function attr<T extends Node>(this: Cheerio<T>): Record<string, string>;
* @returns The instance itself.
* @see {@link https://api.jquery.com/attr/}
*/
export function attr<T extends Node>(
export function attr<T extends AnyNode>(
this: Cheerio<T>,
name: string,
value?:
Expand All @@ -181,11 +183,11 @@ export function attr<T extends Node>(
* @returns The instance itself.
* @see {@link https://api.jquery.com/attr/}
*/
export function attr<T extends Node>(
export function attr<T extends AnyNode>(
this: Cheerio<T>,
values: Record<string, string | null>
): Cheerio<T>;
export function attr<T extends Node>(
export function attr<T extends AnyNode>(
this: Cheerio<T>,
name?: string | Record<string, string | null>,
value?:
Expand Down Expand Up @@ -234,7 +236,7 @@ export function attr<T extends Node>(
* @returns The prop's value.
*/
function getProp(
el: Node | undefined,
el: AnyNode | undefined,
name: string,
xmlMode?: boolean
): string | undefined | Element[keyof Element] {
Expand Down Expand Up @@ -295,34 +297,34 @@ interface StyleProp {
* @returns If `value` is specified the instance itself, otherwise the prop's value.
* @see {@link https://api.jquery.com/prop/}
*/
export function prop<T extends Node>(
export function prop<T extends AnyNode>(
this: Cheerio<T>,
name: 'tagName' | 'nodeName'
): T extends Element ? string : undefined;
export function prop<T extends Node>(
export function prop<T extends AnyNode>(
this: Cheerio<T>,
name: 'innerHTML' | 'outerHTML' | 'innerText' | 'textContent'
): string | null;
export function prop<T extends Node>(
export function prop<T extends AnyNode>(
this: Cheerio<T>,
name: 'style'
): StyleProp;
export function prop<T extends Node, K extends keyof Element>(
export function prop<T extends AnyNode, K extends keyof Element>(
this: Cheerio<T>,
name: K
): Element[K];
export function prop<T extends Node, K extends keyof Element>(
export function prop<T extends AnyNode, K extends keyof Element>(
this: Cheerio<T>,
name: K,
value:
| Element[K]
| ((this: Element, i: number, prop: K) => Element[keyof Element])
): Cheerio<T>;
export function prop<T extends Node>(
export function prop<T extends AnyNode>(
this: Cheerio<T>,
name: Record<string, string | Element[keyof Element] | boolean>
): Cheerio<T>;
export function prop<T extends Node>(
export function prop<T extends AnyNode>(
this: Cheerio<T>,
name: string,
value:
Expand All @@ -331,8 +333,8 @@ export function prop<T extends Node>(
| null
| ((this: Element, i: number, prop: string) => string | boolean)
): Cheerio<T>;
export function prop<T extends Node>(this: Cheerio<T>, name: string): string;
export function prop<T extends Node>(
export function prop<T extends AnyNode>(this: Cheerio<T>, name: string): string;
export function prop<T extends AnyNode>(
this: Cheerio<T>,
name: string | Record<string, string | Element[keyof Element] | boolean>,
value?:
Expand Down Expand Up @@ -442,7 +444,7 @@ function setData(
/**
* 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.
* attribute name is specified, read _all_ HTML5 `data-*` attributes in this manner.
*
* @private
* @category Attributes
Expand Down Expand Up @@ -510,7 +512,7 @@ function readData(el: DataElement, name?: string): unknown {
* @returns The data attribute's value.
* @see {@link https://api.jquery.com/data/}
*/
export function data<T extends Node>(
export function data<T extends AnyNode>(
this: Cheerio<T>,
name: string
): unknown | undefined;
Expand All @@ -529,7 +531,9 @@ export function data<T extends Node>(
* @returns The data attribute's values.
* @see {@link https://api.jquery.com/data/}
*/
export function data<T extends Node>(this: Cheerio<T>): Record<string, unknown>;
export function data<T extends AnyNode>(
this: Cheerio<T>
): Record<string, unknown>;
/**
* Method for setting data attributes, for only the first element in the matched set.
*
Expand All @@ -548,7 +552,7 @@ export function data<T extends Node>(this: Cheerio<T>): Record<string, unknown>;
* @returns The instance itself.
* @see {@link https://api.jquery.com/data/}
*/
export function data<T extends Node>(
export function data<T extends AnyNode>(
this: Cheerio<T>,
name: string,
value: unknown
Expand All @@ -571,11 +575,11 @@ export function data<T extends Node>(
* @returns The instance itself.
* @see {@link https://api.jquery.com/data/}
*/
export function data<T extends Node>(
export function data<T extends AnyNode>(
this: Cheerio<T>,
values: Record<string, unknown>
): Cheerio<T>;
export function data<T extends Node>(
export function data<T extends AnyNode>(
this: Cheerio<T>,
name?: string | Record<string, unknown>,
value?: unknown
Expand Down Expand Up @@ -623,7 +627,7 @@ export function data<T extends Node>(
* @returns The value.
* @see {@link https://api.jquery.com/val/}
*/
export function val<T extends Node>(
export function val<T extends AnyNode>(
this: Cheerio<T>
): string | undefined | string[];
/**
Expand All @@ -642,11 +646,11 @@ export function val<T extends Node>(
* @returns The instance itself.
* @see {@link https://api.jquery.com/val/}
*/
export function val<T extends Node>(
export function val<T extends AnyNode>(
this: Cheerio<T>,
value: string | string[]
): Cheerio<T>;
export function val<T extends Node>(
export function val<T extends AnyNode>(
this: Cheerio<T>,
value?: string | string[]
): string | string[] | Cheerio<T> | undefined {
Expand Down Expand Up @@ -732,7 +736,7 @@ function splitNames(names?: string): string[] {
* @returns The instance itself.
* @see {@link https://api.jquery.com/removeAttr/}
*/
export function removeAttr<T extends Node>(
export function removeAttr<T extends AnyNode>(
this: Cheerio<T>,
name: string
): Cheerio<T> {
Expand All @@ -748,7 +752,7 @@ export function removeAttr<T extends Node>(
}

/**
* Check to see if *any* of the matched elements have the given `className`.
* Check to see if _any_ of the matched elements have the given `className`.
*
* @category Attributes
* @example
Expand All @@ -768,7 +772,7 @@ export function removeAttr<T extends Node>(
* @returns Indicates if an element has the given `className`.
* @see {@link https://api.jquery.com/hasClass/}
*/
export function hasClass<T extends Node>(
export function hasClass<T extends AnyNode>(
this: Cheerio<T>,
className: string
): boolean {
Expand Down Expand Up @@ -811,7 +815,7 @@ export function hasClass<T extends Node>(
* @returns The instance itself.
* @see {@link https://api.jquery.com/addClass/}
*/
export function addClass<T extends Node, R extends ArrayLike<T>>(
export function addClass<T extends AnyNode, R extends ArrayLike<T>>(
this: R,
value?:
| string
Expand Down Expand Up @@ -878,7 +882,7 @@ export function addClass<T extends Node, R extends ArrayLike<T>>(
* @returns The instance itself.
* @see {@link https://api.jquery.com/removeClass/}
*/
export function removeClass<T extends Node, R extends ArrayLike<T>>(
export function removeClass<T extends AnyNode, R extends ArrayLike<T>>(
this: R,
name?:
| string
Expand Down Expand Up @@ -947,7 +951,7 @@ export function removeClass<T extends Node, R extends ArrayLike<T>>(
* @returns The instance itself.
* @see {@link https://api.jquery.com/toggleClass/}
*/
export function toggleClass<T extends Node, R extends ArrayLike<T>>(
export function toggleClass<T extends AnyNode, R extends ArrayLike<T>>(
this: R,
value?:
| string
Expand Down
18 changes: 9 additions & 9 deletions src/api/css.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { domEach, isTag } from '../utils';
import type { Element, Node } from 'domhandler';
import type { Element, AnyNode } from 'domhandler';
import type { Cheerio } from '../cheerio';

/**
Expand All @@ -10,7 +10,7 @@ import type { Cheerio } from '../cheerio';
* @returns A map of all of the style properties.
* @see {@link https://api.jquery.com/css/}
*/
export function css<T extends Node>(
export function css<T extends AnyNode>(
this: Cheerio<T>,
names?: string[]
): Record<string, string>;
Expand All @@ -22,7 +22,7 @@ export function css<T extends Node>(
* @returns The property value for the given name.
* @see {@link https://api.jquery.com/css/}
*/
export function css<T extends Node>(
export function css<T extends AnyNode>(
this: Cheerio<T>,
name: string
): string | undefined;
Expand All @@ -35,7 +35,7 @@ export function css<T extends Node>(
* @returns The instance itself.
* @see {@link https://api.jquery.com/css/}
*/
export function css<T extends Node>(
export function css<T extends AnyNode>(
this: Cheerio<T>,
prop: string,
val:
Expand All @@ -51,11 +51,11 @@ export function css<T extends Node>(
* @returns The instance itself.
* @see {@link https://api.jquery.com/css/}
*/
export function css<T extends Node>(
export function css<T extends AnyNode>(
this: Cheerio<T>,
prop: Record<string, string>
): Cheerio<T>;
export function css<T extends Node>(
export function css<T extends AnyNode>(
this: Cheerio<T>,
prop?: string | string[] | Record<string, string>,
val?:
Expand Down Expand Up @@ -125,7 +125,7 @@ function setCss(
* @param props - Optionally the names of the properties of interest.
* @returns The parsed styles.
*/
function getCss(el?: Node, props?: string[]): Record<string, string>;
function getCss(el?: AnyNode, props?: string[]): Record<string, string>;
/**
* Get a property from the parsed styles of the first element.
*
Expand All @@ -135,9 +135,9 @@ function getCss(el?: Node, props?: string[]): Record<string, string>;
* @param prop - Name of the prop.
* @returns The value of the property.
*/
function getCss(el: Node, prop: string): string | undefined;
function getCss(el: AnyNode, prop: string): string | undefined;
function getCss(
el?: Node,
el?: AnyNode,
prop?: string | string[]
): Record<string, string> | string | undefined {
if (!el || !isTag(el)) return;
Expand Down
8 changes: 4 additions & 4 deletions src/api/forms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Node } from 'domhandler';
import type { AnyNode } from 'domhandler';
import type { Cheerio } from '../cheerio';
import { isTag } from '../utils';

Expand All @@ -17,7 +17,7 @@ const rCRLF = /\r?\n/g;
* @returns The serialized form.
* @see {@link https://api.jquery.com/serialize/}
*/
export function serialize<T extends Node>(this: Cheerio<T>): string {
export function serialize<T extends AnyNode>(this: Cheerio<T>): string {
// Convert form elements into name/value objects
const arr = this.serializeArray();

Expand Down Expand Up @@ -50,7 +50,7 @@ interface SerializedField {
* @returns The serialized form.
* @see {@link https://api.jquery.com/serializeArray/}
*/
export function serializeArray<T extends Node>(
export function serializeArray<T extends AnyNode>(
this: Cheerio<T>
): SerializedField[] {
// Resolve all form elements from either forms or collections of form elements
Expand All @@ -70,7 +70,7 @@ export function serializeArray<T extends Node>(
':matches([checked], :not(:checkbox, :radio))'
// Convert each of the elements to its value(s)
)
.map<Node, SerializedField>((_, elem) => {
.map<AnyNode, SerializedField>((_, elem) => {
const $elem = this._make(elem);
const name = $elem.attr('name') as string; // We have filtered for elements with a name before.
// If there is no value set (e.g. `undefined`, `null`), then default value to empty
Expand Down
Loading