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

add wrapAll into types #1740

Merged
merged 1 commit into from
Feb 16, 2021
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
4 changes: 2 additions & 2 deletions lib/api/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ exports.unwrap = function (selector) {
* // </div>
* // <strong>Strong</strong>
*
* @param {Cheerio} wrapper - The DOM structure to wrap around all matched
* elements in the selection.
* @param {Cheerio | string | Element | Element[] | Function} wrapper - The DOM
* structure to wrap around all matched elements in the selection.
* @see {@link https://api.jquery.com/wrapAll/}
* @returns {Cheerio} The instance itself.
*/
Expand Down
9 changes: 7 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ParserOptions } from 'htmlparser2';

declare namespace cheerio {
type AttrFunction = (this: Element, i: number, currentValue: string) => any;
type WrapFunction = (this: Element) => any;

interface Cheerio {
// Document References
Expand Down Expand Up @@ -194,6 +195,10 @@ declare namespace cheerio {
wrap(content: Document): Cheerio;
wrap(content: Cheerio): Cheerio;

wrapAll(
wrapper: Cheerio | string | Element | Element[] | WrapFunction
): Cheerio;

css(propertyName: string): string;
css(propertyNames: string[]): string[];
css(propertyName: string, value: string): Cheerio;
Expand Down Expand Up @@ -270,11 +275,11 @@ declare namespace cheerio {
interface CheerioAPI extends Root {
version: string;
load(
html: string | { toString(): string },
html: string | Buffer | { toString(): string },
options?: CheerioParserOptions | null,
isDocument?: boolean
): Root;
load(element: Element, options?: CheerioParserOptions): Root;
load(element: Element | Element[], options?: CheerioParserOptions): Root;
}
}

Expand Down
8 changes: 8 additions & 0 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ $el.text('text');
// .wrap( content )
$el.wrap($('<div class="red-fruit"></div>')).html();

// .wrapAll( wrapper )
$el.wrapAll($('<div class="red-fruit"></div>'));
$el.wrapAll($('<div class="red-fruit"></div>').get());
$el.wrapAll('<div class="red-fruit"></div>');
$el.wrapAll(function () {
return '<div class="red-fruit"></div>';
});

// .css
$el.css('width');
$el.css(['width', 'height']);
Expand Down