Skip to content

Latest commit

 

History

History
560 lines (340 loc) · 13 KB

modules.md

File metadata and controls

560 lines (340 loc) · 13 KB

portadom / Exports

portadom

Table of contents

Interfaces

Type Aliases

Functions

Type Aliases

AnyHandle

Ƭ AnyHandle<T>: JSHandle<T> | ElementHandle<T>

Any instance that is a Playwright Handle.

Type parameters

Name Type
T any

Defined in

src/dom/domUtils.ts:39


BrowserPortadom

Ƭ BrowserPortadom<T>: Portadom<T, Element>

Implementation of Portadom in browser (using Browser API)

Type parameters

Name Type
T extends Element = Element

Defined in

src/dom/dom.ts:13


CheerioPortadom

Ƭ CheerioPortadom<El>: Portadom<El, Cheerio<AnyNode>>

Implementation of Portadom in Cheerio

Type parameters

Name Type
El extends Cheerio<AnyNode> = Cheerio<AnyNode>

Defined in

src/dom/dom.ts:235


HandleLike

Ƭ HandleLike<T>: Locator | JSHandle<T> | ElementHandle<T>

Any instance that is a Playwright Handle, or can be converted to one.

Type parameters

Name Type
T any

Defined in

src/dom/domUtils.ts:41


PlaywrightHandlePortadom

Ƭ PlaywrightHandlePortadom<El>: Portadom<El, Locator | ElementHandle<Node>>

Implementation of Portadom in Playwright using Handles

Type parameters

Name Type
El extends Locator | ElementHandle<Node> = Locator | ElementHandle<Node>

Defined in

src/dom/dom.ts:459


PlaywrightLocatorPortadom

Ƭ PlaywrightLocatorPortadom<El>: Portadom<El, Locator>

Implementation of Portadom in Playwright using Locators

Type parameters

Name Type
El extends Locator = Locator

Defined in

src/dom/dom.ts:800


PlaywrightPortapage

Ƭ PlaywrightPortapage<T>: Portapage<T, PWIST, { container: PWIST["container"] ; page: T }>

Implementation of Portapage in Playwright

Type parameters

Name Type
T extends Page = Page

Defined in

src/page/page.ts:23

Functions

browserPortadom

browserPortadom<El>(node): BrowserPortadom<El>

Implementation of Portadom in browser (using Browser API)

Type parameters

Name Type
El extends Element<El>

Parameters

Name Type
node El

Returns

BrowserPortadom<El>

Defined in

src/dom/dom.ts:16


cheerioPortadom

cheerioPortadom<El>(cheerioNode, srcUrl): CheerioPortadom<El>

Implementation of Portadom in Cheerio

Type parameters

Name Type
El extends Cheerio<AnyNode, El>

Parameters

Name Type
cheerioNode El
srcUrl null | string

Returns

CheerioPortadom<El>

Defined in

src/dom/dom.ts:241


createPlaywrightElementSerializer

createPlaywrightElementSerializer<T>(page): Promise<{ resolveId: (id: string) => Promise<JSHandle<null> | ElementHandle<Element>> ; resolveIds: (ids: string[]) => Promise<JSHandle<(null | Element)[]>> ; serializeEls: (elsHandle: JSHandle<Element[]>) => Promise<string[]> }>

Helper methods that allow to represent HTML Elements on the Page as string IDs

We use this so we can identify which elements have already been processed, and which have not. Normally, the elements are represented via Playwright JSHandle/ElementHandle. However, if two Handles are pointing to the same Element, we're unable to count them as one, because it's two instances that don't have any IDs of the Elemenets. On the other hand, using the string IDs, two different JSHandles will return the same string if they point to the same Element, so we cache the IDs outside of Playwright in Sets or Maps.

Type parameters

Name Type
T extends Page<T>

Parameters

Name Type
page T

Returns

Promise<{ resolveId: (id: string) => Promise<JSHandle<null> | ElementHandle<Element>> ; resolveIds: (ids: string[]) => Promise<JSHandle<(null | Element)[]>> ; serializeEls: (elsHandle: JSHandle<Element[]>) => Promise<string[]> }>

Defined in

src/page/pageUtils.ts:20


createPortadomArrayPromise

createPortadomArrayPromise<El, BaseEl>(promiseDom): PortadomArrayPromise<El, BaseEl>

Wrapper for a Promise that resolves to a n Array of Portadom instances. This allows us to chain Portadom methods before the Promise is resolved.

Example:

const dom = Promise.resolve(browserPortadom({}));

Instead of:

const resA = await (await dom).findOne('..');
const resB = await (await dom).text();

You can call:

const domP = createPortadomArrayPromise(dom);
const resA = await domP.findOne('..');
const resB = await domP.text();

Type parameters

Name
El
BaseEl

Parameters

Name Type
promiseDom MaybePromise<Portadom<El, BaseEl>[]>

Returns

PortadomArrayPromise<El, BaseEl>

Defined in

src/dom/types.ts:642


createPortadomPromise

createPortadomPromise<El, BaseEl>(promiseDom): PortadomPromise<El, BaseEl>

Wrapper for a Promise that resolves to a Portadom instance. This allows us to chain Portadom methods before the Promise is resolved.

Example:

const dom = Promise.resolve(browserPortadom({}));

Instead of:

const resA = await (await dom).findOne('..');
const resB = await (await dom).text();

You can call:

const domP = createPortadomPromise(dom);
const resA = await domP.findOne('..');
const resB = await domP.text();

Type parameters

Name
El
BaseEl

Parameters

Name Type
promiseDom MaybePromise<null | Portadom<El, BaseEl>>

Returns

PortadomPromise<El, BaseEl>

Defined in

src/dom/types.ts:251


handleIsLocator

handleIsLocator<T>(h): h is Locator

Type parameters

Name
T

Parameters

Name Type
h HandleLike<T>

Returns

h is Locator

Defined in

src/dom/domUtils.ts:43


mergeHandles

mergeHandles<T>(handles, options?): Promise<JSHandle<T[]>>

Join several Locators and Handles in a single JSHandle.

Locators are evaluated to their matching elements.

To override how Locators are resolved, supply own locatorResolver function.

Type parameters

Name Type
T any

Parameters

Name Type
handles HandleLike<T>[]
options? Object
options.locatorResolver? (loc: Locator) => MaybePromise<MaybeArray<AnyHandle<T>>>

Returns

Promise<JSHandle<T[]>>

Defined in

src/dom/domUtils.ts:54


playwrightHandlePortadom

playwrightHandlePortadom<El>(node, page): PlaywrightHandlePortadom<El>

Implementation of Portadom in Playwright using Handles

Type parameters

Name Type
El extends ElementHandle<Node> | Locator

Parameters

Name Type
node El
page Page

Returns

PlaywrightHandlePortadom<El>

Defined in

src/dom/dom.ts:470


playwrightLocatorPortadom

playwrightLocatorPortadom<El>(node, page): PlaywrightLocatorPortadom<El>

Implementation of Portadom in Playwright using Locators

Type parameters

Name Type
El extends Locator

Parameters

Name Type
node El
page Page

Returns

PlaywrightLocatorPortadom<El>

Defined in

src/dom/dom.ts:803


playwrightPortapage

playwrightPortapage<T>(page): Promise<PlaywrightPortapage<T>>

Implementation of Portapage in Playwright

Type parameters

Name Type
T extends Page<T>

Parameters

Name Type
page T

Returns

Promise<PlaywrightPortapage<T>>

Defined in

src/page/page.ts:30


splitCheerioSelection

splitCheerioSelection(cheerioSel): Cheerio<AnyNode>[]

Given a Cheerio selection, split it into an array of Cheerio selections, where each has only one element.

From Cheerio[el, el, el, el]

To [Cheerio[el], Cheerio[el], Cheerio[el], Cheerio[el]]

Parameters

Name Type
cheerioSel Cheerio<AnyNode>

Returns

Cheerio<AnyNode>[]

Defined in

src/dom/domUtils.ts:16


splitPlaywrightSelection

splitPlaywrightSelection<T>(handle): Promise<SmartHandle<T>[]>

Given a Playwright JSHandle that points to an array of Elements, split it into an array of ElementHandles, where each has only one element.

From JSHandle([el, el, el)]

To ElHandle(el), ElHandle(el), ElHandle(el)

Type parameters

Name
T

Parameters

Name Type
handle JSHandle<T[]>

Returns

Promise<SmartHandle<T>[]>

Defined in

src/dom/domUtils.ts:31