Skip to content

Commit

Permalink
chore(types): Add wrapAll (#1740)
Browse files Browse the repository at this point in the history
  • Loading branch information
5saviahv committed Feb 16, 2021
1 parent 1a86118 commit b360762
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
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

0 comments on commit b360762

Please sign in to comment.