Skip to content

Commit

Permalink
Merge 10cd693 into 803af1c
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Oct 24, 2022
2 parents 803af1c + 10cd693 commit 7a85725
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.json
Expand Up @@ -88,6 +88,8 @@
"dot-notation": 0,
"curly": [2, "multi-line"],

"jsdoc/require-returns-check": 0, // Broken with overloaded fns

"@typescript-eslint/prefer-for-of": 0,
"@typescript-eslint/member-ordering": 0,
"@typescript-eslint/explicit-function-return-type": 0,
Expand Down
27 changes: 18 additions & 9 deletions src/api/attributes.ts
Expand Up @@ -86,7 +86,8 @@ function getAttr(
}

/**
* Sets the value of an attribute. The attribute will be deleted if the value is `null`.
* 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.
Expand Down Expand Up @@ -291,7 +292,8 @@ interface StyleProp {
*
* @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.
* @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 AnyNode>(
Expand Down Expand Up @@ -495,13 +497,15 @@ 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
* @param el - Element 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 attributes.
* @returns The data attribute's value, or a map with all of the data
* attributes.
*/
function readData(el: DataElement, name?: string): unknown {
let domNames;
Expand Down Expand Up @@ -549,7 +553,8 @@ function readData(el: DataElement, name?: string): unknown {
}

/**
* Method for getting data attributes, for only the first element in the matched set.
* Method for getting data attributes, for only the first element in the matched
* set.
*
* @category Attributes
* @example
Expand All @@ -560,7 +565,8 @@ function readData(el: DataElement, name?: string): unknown {
* ```
*
* @param name - Name of the data attribute.
* @returns The data attribute's value, or `undefined` if the attribute does not exist.
* @returns The data attribute's value, or `undefined` if the attribute does not
* exist.
* @see {@link https://api.jquery.com/data/}
*/
export function data<T extends AnyNode>(
Expand All @@ -586,7 +592,8 @@ 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.
* Method for setting data attributes, for only the first element in the matched
* set.
*
* @category Attributes
* @example
Expand Down Expand Up @@ -917,7 +924,8 @@ export function addClass<T extends AnyNode, R extends ArrayLike<T>>(

/**
* 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`.
* `className` is defined, all classes will be removed. Also accepts a
* `function`.
*
* @category Attributes
* @example
Expand Down Expand Up @@ -986,7 +994,8 @@ export function removeClass<T extends AnyNode, R extends ArrayLike<T>>(

/**
* 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`.
* class's presence or the value of the switch argument. Also accepts a
* `function`.
*
* @category Attributes
* @example
Expand Down
6 changes: 4 additions & 2 deletions src/api/css.ts
Expand Up @@ -3,7 +3,8 @@ import type { Element, AnyNode } from 'domhandler';
import type { Cheerio } from '../cheerio.js';

/**
* Get the value of a style property for the first element in the set of matched elements.
* 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 properties of interest.
Expand All @@ -15,7 +16,8 @@ export function css<T extends AnyNode>(
names?: string[]
): Record<string, string> | undefined;
/**
* Get the value of a style property for the first element in the set of matched elements.
* 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.
Expand Down
15 changes: 10 additions & 5 deletions src/api/manipulation.ts
Expand Up @@ -13,7 +13,8 @@ import type { Cheerio } from '../cheerio.js';
import type { BasicAcceptedElems, AcceptedElems } from '../types.js';

/**
* Create an array of nodes, recursing into arrays and parsing strings if necessary.
* Create an array of nodes, recursing into arrays and parsing strings if
* necessary.
*
* @private
* @category Manipulation
Expand Down Expand Up @@ -185,7 +186,8 @@ export function appendTo<T extends AnyNode>(
}

/**
* Insert every element in the set of matched elements to the beginning of the target.
* Insert every element in the set of matched elements to the beginning of the
* target.
*
* @category Manipulation
* @example
Expand Down Expand Up @@ -354,7 +356,8 @@ function _wrap(
* // </ul>
* ```
*
* @param wrapper - The DOM structure to wrap around each element in the selection.
* @param wrapper - The DOM structure to wrap around each element in the
* selection.
* @see {@link https://api.jquery.com/wrap/}
*/
export const wrap = _wrap((el, elInsertLocation, wrapperDom) => {
Expand Down Expand Up @@ -457,7 +460,8 @@ export const wrapInner = _wrap((el, elInsertLocation, wrapperDom) => {
* ```
*
* @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.
* 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/}
*/
Expand Down Expand Up @@ -995,7 +999,8 @@ export function toString<T extends AnyNode>(this: Cheerio<T>): string {
*/
export function text<T extends AnyNode>(this: Cheerio<T>): string;
/**
* Set the content of each element in the set of matched elements to the specified text.
* Set the content of each element in the set of matched elements to the
* specified text.
*
* @category Manipulation
* @example
Expand Down
3 changes: 2 additions & 1 deletion src/api/traversing.spec.ts
Expand Up @@ -1441,7 +1441,8 @@ describe('$(...)', () => {
});

/**
* Element order is undefined in this case, so it should not be asserted here.
* Element order is undefined in this case, so it should not be asserted
* here.
*
* If the collection consists of elements from different documents or ones
* not in any document, the sort order is undefined.
Expand Down
15 changes: 10 additions & 5 deletions src/api/traversing.ts
Expand Up @@ -84,7 +84,8 @@ export function find<T extends AnyNode>(

/**
* Creates a matcher, using a particular mapping function. Matchers provide a
* function that finds elements using a generating function, supporting filtering.
* function that finds elements using a generating function, supporting
* filtering.
*
* @private
* @param matchMap - Mapping function.
Expand Down Expand Up @@ -257,7 +258,8 @@ export const parents = _matcher(

/**
* 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.
* to but not including the element matched by the selector, DOM node, or
* cheerio object.
*
* @category Traversing
* @example
Expand All @@ -280,7 +282,8 @@ export const parentsUntil = _matchUntil(

/**
* 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.
* by testing the element itself and traversing up through its ancestors in the
* DOM tree.
*
* @category Traversing
* @example
Expand Down Expand Up @@ -340,7 +343,8 @@ export function closest<T extends AnyNode>(
}

/**
* Gets the next sibling of the first selected element, optionally filtered by a selector.
* Gets the next sibling of the first selected element, optionally filtered by a
* selector.
*
* @category Traversing
* @example
Expand Down Expand Up @@ -910,7 +914,8 @@ export 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.
* Retrieve one of the elements matched by the Cheerio object, at the `i`th
* position.
*
* @category Traversing
* @example
Expand Down
3 changes: 2 additions & 1 deletion src/cheerio.ts
Expand Up @@ -20,7 +20,8 @@ export abstract class Cheerio<T> implements ArrayLike<T> {

options: InternalOptions;
/**
* The root of the document. Can be set by using the `root` argument of the constructor.
* The root of the document. Can be set by using the `root` argument of the
* constructor.
*
* @private
*/
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Expand Up @@ -38,7 +38,8 @@ const parse = getParse((content, options, isDocument, context) =>

// Duplicate docs due to https://github.com/TypeStrong/typedoc/issues/1616
/**
* Create a querying function, bound to a document created from the provided markup.
* Create a querying function, bound to a document created from the provided
* markup.
*
* Note that similar to web browser contexts, this operation may introduce
* `<html>`, `<head>`, and `<body>` elements; set `isDocument` to `false` to
Expand Down
11 changes: 8 additions & 3 deletions src/load.ts
Expand Up @@ -15,7 +15,8 @@ type StaticType = typeof staticMethods;
/**
* A querying function, bound to a document created from the provided markup.
*
* Also provides several helper methods for dealing with the document as a whole.
* Also provides several helper methods for dealing with the document as a
* whole.
*/
export interface CheerioAPI extends StaticType {
/**
Expand Down Expand Up @@ -80,7 +81,8 @@ export function getLoad(
) => string
) {
/**
* Create a querying function, bound to a document created from the provided markup.
* Create a querying function, bound to a document created from the provided
* markup.
*
* Note that similar to web browser contexts, this operation may introduce
* `<html>`, `<head>`, and `<body>` elements; set `isDocument` to `false` to
Expand All @@ -104,7 +106,10 @@ export function getLoad(
const internalOpts = { ...defaultOptions, ...flattenOptions(options) };
const initialRoot = parse(content, internalOpts, isDocument, null);

/** Create an extended class here, so that extensions only live on one instance. */
/**
* Create an extended class here, so that extensions only live on one
* instance.
*/
class LoadedCheerio<T> extends Cheerio<T> {
_make<T>(
selector?: ArrayLike<T> | T | string,
Expand Down
3 changes: 2 additions & 1 deletion src/utils.ts
Expand Up @@ -50,7 +50,8 @@ export function cssCase(str: string): string {
}

/**
* Iterate over each DOM element without creating intermediary Cheerio instances.
* Iterate over each DOM element without creating intermediary Cheerio
* instances.
*
* This is indented for use internally to avoid otherwise unnecessary memory
* pressure introduced by _make.
Expand Down

0 comments on commit 7a85725

Please sign in to comment.