Home Reference Source

Function

Static Public Summary
public

Creates a style tag if one was not created before and adds the supplied styleDef to it.

public

addClass(elem: SomeElement, clazz: string)

Adds a CSS classname to the supplied element

public

addOutLinks(toAdd: Array<HTMLAnchorElement|HTMLAreaElement>|NodeList<HTMLAnchorElement|HTMLAreaElement>)

Add the array/nodelist of A or Anchor tags href properties the collected outlinks

public

addOutlink(elemOrString: HTMLAnchorElement | HTMLAreaElement | string)

Add the URL or href value of the supplied argument

public

anySelectorExists(selectors: Array<string>, cntx: SomeElement): {idx: number, success: boolean}

Determines if the element the supplied selector selects exists.

public

attr(elem: SomeElement, attr: string): *

Retrieves the value of an elements attribute if it exists

public

attrEq(elem: SomeElement, attr: string, shouldEq: *): boolean

Tests to determine if the value of elements attribute equals the supplied value using loose equality

public

Initiates an pywb/webrecorder auto-fetch of content

public

autobind(clazz: *)

Automatically binds the non-inherited functions of the supplied class to itself.

public

Navigate the browser back 1 entry in the history stack.

public

Returns the value window.location.href

public

Creates and returns a function wrapping the provided post step function will call the supplied function and return the expected output.

public

Attempts to convert the supplied string into camel case

public

Attempts to convert the supplied camel case string into dash delimited string

public

Attempts to convert the supplied camel case string into an underscore delimited string

public

canAccessIf(iframe: HTMLIFrameElement): boolean

Determines if the supplied iframe is accessible from this origin.

public

Determines if we can scroll down any more

public

Determines if we can scroll up any more

public

Attempts to capitalize the supplied string

public

Chains firstChildElementOf on the supplied element n times

public

Chains lastChildElementOf n times starting with the supplied element

public

Chains nthChildElementOf for each nth child element in nths

public

Chains nthChildElemOf for each nth child in nths

public

chainQs(startingSelectFrom: SomeElement | Document, startingSelector: string, selectors: ...string): SomeElement

Consecutively calls querySelector(selector) on the element returned by the previous invocation

public

* childElementIterator(parentElement: SomeElement): IterableIterator<SomeElement>

Returns an iterator over the supplied parent element's child elements that ends once the current child has no next element sibling.

If the parent element is null/undefined then the returned iterator yields nothing.

public

* childNodeIterator(parentElement: SomeElement): IterableIterator<Node>

Returns an iterator over the supplied parent element's child nodes that ends once the current child has no next sibling.

If the parent element is null/undefined then the returned iterator yields nothing.

public

Calls the click function on the supplied element if non-null/defined.

public

async clickAndWaitFor(elem: Element | Node | HTMLElement, predicate: function(): boolean, options: WaitForOptions): Promise<{predicate: boolean, maxExceeded: boolean, clicked: boolean}>

Clicks the supplied element and then waits for the supplied predicate function to return true

public

async clickAndWaitForHistoryChange(elemToBeClicked: Element | HTMLElement, waitOpts: WaitForOptions): Promise<{oldlocation: ?string, historyChanged: boolean, clicked: boolean, newLocation: ?string, ok: boolean}>

Clicks the supplied element and waits for browser history to change (the URL is updated by JavaScript modifying the current history stack)

public

clickInContext(elem: SomeElement, cntx: Window): boolean

Calls the click function on the supplied element if non-null/defined that exists in the JS context of the supplied window (cntx).

public

async clickInContextWithDelay(elem: HTMLElement | Element, cntx: Window, delayTime: number): Promise<boolean>

Calls the click method of the supplied element that exists in the JS context of the supplied window object (cntx) and waits the specified delayTime after clicking IFF the supplied element was non-null/undefined.

public

async clickWithDelay(elem: SomeElement, delayTime: number): Promise<boolean>

Calls the click method of the supplied element and waits the specified delayTime after clicking IFF the supplied element was non-null/undefined.

public

Attempts to collapse all extra white space into a single white space character

public

collectOutlinksFrom(queryFrom: Element | Document)

Collects outlinks form the supplied element

public

Collects the outlinks from the document

public

compose(funcs: function(...args: *): *): function(...args: *): *

Composes multiple functions from right to left into a single function.

public

composeAsync(funcs: function(...args: *): Promise<*>): function(...args: *): Promise<*>

Composes multiple async or Promise returning functions from right to left into a single function.

public

composeAsyncIterators(funcs: function(...args: *): AsyncIterator<*>): function(...args: *): AsyncIterator<*>

Composes multiple AsyncIterator returning functions from right to left into a single function.

public

composeIterators(funcs: function(...args: *): Iterator<*>): function(...args: *): Iterator<*>

Composes multiple Iterator returning functions from right to left into a single function.

public

Creates and returns a new mouse event configured using the supplied options

public

createScrollAmount(desiredTimesToScroll: number): {timesToScroll: number, scrollUpDownAmount: number, scrollLeftRightAmount: number}

Creates and returns an object that calculates the scroll amount, up/down or left/right, based on dividing the scroll width/height by the supplied desired times to completely scroll the page, defaults to 10.

public

createScroller(timesToScroll: number): Scroller

Creates and returns an object for scrolling the page up/down and left/right.

public

createState(wait: boolean, msg: *, state: *): BehaviorState

Returns a behavior state object with the supplied wait and msg values.

public

delay(delayTime: number): Promise<void>

Returns a Promise that resolves after waiting the amount of time specified by delayTime.

public

async * disconnectingWalk(walkState: DisconnectingWalkState): AsyncIterableIterator<*>

Yields the child elements of the found parent element.

public

docBaseURIEndsWith(shouldEndWith: string, cntxDoc: Document): boolean

Returns T/F indicating if the documents baseURI ends with the supplied string

public

docBaseURIEquals(shouldEqual: string, cntxDoc: Document): boolean

Returns T/F indicating if the documents baseURI equals the supplied string

public

documentScrollPosition(doc: Document): {scrollTop: number, scrollLeft: number}

Returns the scrollTop and scrollLeft values of the supplied document if one was supplied other wise the values are from the current document

public

Returns a promise that resolves once document.readyState === 'complete'

public

The default post step function used for all behaviors that do not provide one.

public

elemDataValue(elem: HTMLElement | SVGElement, dataKey: string): string

Returns the value of the elements data attribute if it exists If the element is null/undefined or does not have data attributes null is returned.

public

elemDataValueEqs(elem: HTMLElement | SVGElement, dataKey: *, dataValue: *): boolean

Returns T/F indicating if the element has data attribute equal to the supplied value

public

Returns T/F indicating if the supplied element has children.

public

Returns T/F indicating if the supplied element has an sibling element

public

Determines if the supplied elements bounding client rect's x,y,width,height,top,left properties all equal zero. Note this function returns true if the element is null/undefined;

public

Returns the supplied elements innerText

public

elemInnerTextEqs(elem: SomeElement, shouldEqual: string, trim: boolean): boolean

Returns T/F if the supplied elements innerText equals the supplied string case sensitive

public

Returns T/F if the supplied elements innerText equals the supplied string case in-sensitive

public

elemInnerTextEqsOneOf(elem: SomeElement, shouldEquals: ...string): boolean

Returns T/F if the supplied elements innerText equals one of the supplied string case sensitive

public

Returns T/F if the supplied elements innerText matches the supplied regex

public

Returns T/F indicating if the element matches the supplied selector

public

Returns true if the supplied elements offsetTop === 0

public

Returns the textContent of the supplied element

public

elementTextContains(elem: SomeElement, needle: string, caseInsensitive: boolean): boolean

Returns T/F indicating if the supplied element's textContents contains the supplied string

public

Returns T/F indicating if the supplied element's textContent ends with the supplied string

public

elementTextEqs(elem: SomeElement, shouldEqual: string, caseInsensitive: boolean): boolean

Returns T/F indicating if the supplied element's textContents equals the supplied string

public

Returns T/F indicating if the supplied element's textContent starts with the supplied string

public

Returns T/F indicating if the supplied element' textContent starts and ends with the supplied start and end strings

public

Returns T/F indicating if the elements name (localName) is equal to the supplied name

public

extractProps(object: Object, props: ...string): Object

Returns a new object with the properties of the object on the new object

public

filteredQs(selector: string, filterFn: function(elem: SomeElement): boolean, context: SomeElement | Document): SomeElement

Utility function for (document||element).querySelector(selector)

public

Calls the play function on all audio and video elements found in the document.

public

findChildWithKey(reactInstance: Object, key: string): Object

Walks the children of a react component to find the one that has the supplied key

public

Applies the supplied predicate to every child element of the supplied parent element and returns the element that the predicate returns true for otherwise returns null.

public

findReduxStore(startingComponent: Object): Object

Attempts the find the redux store from the supplied component

public

findTag(xpg: function(query: string, node: ?Node): Node[], tag: string, predicate: function(elem: SomeElement): boolean, cntx: Document | SomeElement): SomeElement

Attempts to find a tag using the supplied function that accepts an xpath query and an optional starting element and returns the element the supplied predicate function returns a truthy value for

public

fireEventOn(elem: Element, event: Event)

Fires the supplied event on the supplied element

public

Creates mouse events and fires them in order configured using the supplied options

public

Returns the first child element of the supplied elements parent element.

public

Returns the supplied elements first element child.

public

Returns the first child element of the element matching the supplied selector

public

Returns the supplied elements next element sibling

public

Returns the supplied elements next element sibling and removes the supplied element

public

getElementClientPageCenter(element: SomeElement, options: {floor: boolean}): {clientY: number, clientX: number, pageY: number, pageX: number}

Get the center of the passed DOM element

public

getElementClientPagePosition(element: SomeElement, options: Object): {clientY: number, clientX: number, pageY: number, pageX: number}

Get the position of the passed DOM element

public

getElementPositionWidthHeight(element: Element, doc: Document): {y: number, pageY: number, x: number, pageX: number, w: number, h: number}

Helper function to get the actual x and y position, page x and y position (scroll) and the height, width of a given element

public

Returns the next element sibling of the parent element of the supplied element

public

getInternalRootOnElem(elem: HTMLElement | Element | Node): Object

Returns the internal root object added by react on the supplied element.

public

Returns the Nth parent element of the supplied element (indexing assumes start is 1)

public

getReactRootContainer(elem: HTMLElement | Element | Node): Object

Returns the root container object added by react

public

getReactRootHostElem(alternativeId: string): HTMLElement

Returns the root host element of an react application (id = react-root)

public

getViaPath(obj: *, pathItems: *): *

Retrieves the property of an object, or item in array at index, based on the supplied path.

public

globalWithPropsExist(global: string, props: ...string): boolean

Returns T/F if an global property (on window) exists and has all properties.

public

hasAnyClass(elem: SomeElement, classes: ...string): boolean

Tests to see if the supplied element has any of the supplied css classes

public

Tests to see if the supplied element has a css class

public

hasClasses(elem: SomeElement, classes: ...string): boolean

Tests to see if the supplied element has the supplied css classes

public

id(eid: string, context: SomeElement | Document): SomeElement

Utility function for document.getElementById(id)

public

idExists(eid: string, cntx: Document): boolean

Determines if the element the supplied id identifies exists

public

Performs the setup required for integration with Webrecorders automation system Adds as propeties to the supplied window object

  • $WBBehaviorStepIter$: the supplied behaviorStepIterator
  • $WBBehaviorRunner$: the instance of the class that wraps the behaviors actions
  • $WRIteratorHandler$: a function that initiates a behaviors action
public

innerTextOfSelected(selector: string, cntx: SomeElement | Document): string

Returns the inner text of the element the supplied selectors matches

public

Returns T/F indicating if the supplied string is only alpha characters

public

Returns T/F indicating if the supplied string is only alpha numeric characters

public

Returns T/F indicating if the supplied element has not CSS classes

public

Returns T/F indicating if the supplied element is visible.

public

Returns T/F indicating if the supplied string is truly an empty string

public

isFunction(obj: *): boolean

Returns T/F indicating if the supplied arument is a function

public

isGenerator(obj: *): boolean

Returns T/F indicating if the supplied object is a generator or async generator

public

Returns T/F indicating if the supplied string is only lowercase alpha characters

public

Returns T/F indicating if the supplied string only contains numeric characters

public

isPromise(obj: *): boolean

Returns T/F indicating if the supplied object is a Promise or Promise like

public

Returns T/F indicating if the supplied string is only uppercase alpha characters

public

Returns the last child element of the supplied element

public

Returns the last child element of the element the selector selects

public

Determines if window.location.href contains the supplied value as a substring.

public

locationEquals(someLocation: string): boolean

Determines the strict equality of the string to the value of window.location.href

public

async * mapAsyncIterator(iterator: AsyncIterableIterator<*>, mapper: function(arg: *): *): AsyncIterableIterator<*>

Like map for arrays but over async-iterators

public

Marks the supplied element as visited by adding the marker to its classList.

public

maybePolyfillXPG(cliXPG: function(...args: *): Array<SomeElement>): function(...args: *): Array<SomeElement>

Ensures that if the value of the chrome console utility $x is not the actual utility (jquery is on the page) the returned function behaves exactly like it.

public

maybeRemoveElem(selector: string, context: SomeElement | Document): boolean

Removes the element selected by the supplied querySelector, if it exits, returning true to indicate the element was removed and false otherwise

public

maybeRemoveElemById(eid: string, context: SomeElement | Document): boolean

Removes the element with the supplied id, if it exits, returning true to indicate the element was removed and false otherwise

public

async * noExceptGeneratorWrap(generator: AsyncIterableIterator<*>|IterableIterator<*>, returnLast: boolean): AsyncIterableIterator<*>

Wraps the supplied generator in a try catch and re-yields its values generator.

public

async noExceptPlayMediaElement(mediaElement: HTMLMediaElement, playThrough: boolean): Promise<boolean>

Calls the play function of the supplied element catching the exception thrown if any was thrown.

public

Returns T/F indicating if the nodes name (nodeName) is equal to the supplied name

public

noop()

This function is a no op

public

nthChildElementOf(elem: SomeElement | Document, nth: number): SomeElement

Returns the Nth child element of the supplied element (indexing assumes start is 1)

public

nthChildNodeOf(elem: SomeElement | Document, nth: number): SomeElement

Returns the Nth child node of the supplied element (indexing assumes start is 1)

public

Returns the nth previous sibling of the supplied element if it is not null/undefined or the supplied element is not null/undefined

public

Returns the number of child elements the supplied element has if it is not null/undefined otherwise -1

public

objectHasProps(obj: Object, props: ...string): boolean

Returns T/F if the supplied object has all of the supplied properties.

public

objectInstanceOf(obj: Object, shouldBeInstanceOfThis: Object): boolean

Returns T/F indicating if the supplied object is an instance of some class.

public

partial(fn: function, a1: *, a2: *, a3: *, a4: *, a5: *, aN: ...*): function(...args: *): *

Creates and returns a partially applied function with args being applied left to right

public

partialRight(fn: function, a1: *, a2: *, a3: *, a4: *, a5: *, aN: ...*): function(...args: *): *

Creates and returns a partially applied function with args being applied right to left

public

promiseResolveReject(): {resolve: function, reject: function, promise: Promise<*>}

Creates a Promise that is resolvable externally returning an object that exposes the promise itself and the resolve and reject functions passed as arguments to the executor function

public

qs(selector: string, context: SomeElement | Document): SomeElement

Utility function for (document||element).querySelector(selector)

public

qsOneOf(options: {selectors: Array<string>, context: *}): SomeElement

Returns the results of querySelector using one of the supplied selectors one if one of the selectors yields results otherwise null/undefined

public

qsa(selector: string, context: SomeElement | Document): NodeList<SomeElement>

Utility function for document.querySelectorAll(selector)

public

qsaOneOf(options: {selectors: Array<string>, context: *}): NodeList<SomeElement>

Returns the results of querySelectorAll using one of the supplied selectors if one of the selectors yields results otherwise null/undefined

public

reactInstanceFromDOMElem(elem: HTMLElement | Element | Node): Object

Returns the react instance object that lives on the live element

public

reactInstancesFromElements(elems: Array<Node|HTMLElement|Element>, selectingFn: function(key: string): boolean): Array<{node: HTMLElement|Element|Node, reactInstance: Object}>

Converts the supplied array of elements into an array of objects each with property node (the live dom element) and reactInstance (the live react component).

public

removeClass(elem: SomeElement, clazz: string)

Removes a CSS classname to the supplied element

public

* repeatedXpathQueryIterator(query: string, cntx: *, generateMoreElements: function(): void): IterableIterator<SomeElement>

Repeatably performs the supplied xpath query yielding the results of the each query.

public

async * repeatedXpathQueryIteratorAsync(query: string, cntx: *, generateMoreElements: function(): *): AsyncIterableIterator<SomeElement>

Repeatably performs the supplied xpath query yielding the results of the each query.

public

Returns a Promise that resolves once the behavior has been un-paused

public

scrollAllIntoViewAndClick(elems: Array<HTMLElement>): number

Scrolls into view and clicks all the elements present in the supplied array.

public

async scrollAllIntoViewAndClickWithDelay(elems: Array<HTMLElement|Element|Node>, delayTime: number): Promise<void>

Scrolls into view and clicks all the elements present in the supplied array waiting for the supplied delay time after each click of an element in the array.

public

scrollDownByElemHeight(elem: Element | HTMLElement | Node): void

Scrolls down by the elements height

public

scrollDownByElemHeightWithDelay(elem: Element | HTMLElement | Node, delayTime: number): Promise<void>

Scrolls down by supplied elements height and then waits for the supplied delay time.

public

scrollIntoView(elem: Element, opts: Object): void

Scrolls the supplied element into view.

public

scrollIntoViewAndClick(elem: HTMLElement | Element): boolean

Scrolls the supplied element into view and clicks it if the element is non-null/undefined

public

scrollIntoViewAndClickWithDelay(elem: HTMLElement | Element, delayTime: number): Promise<boolean>

Scrolls the supplied element into view and clicks it if the element is non-null/undefined and waits for the specified delay time

public

scrollIntoViewAndWaitFor(elem: Element | HTMLElement | Node, predicate: function(): boolean, options: {wait: ?WaitForOptions, scrollBehavior: ?Object}): Promise<{predicate: boolean, maxExceeded: boolean}>

Scrolls the supplied element into view and then waits for the supplied predicate function to return true

public

scrollIntoViewWithDelay(elem: Element | HTMLElement | Node, delayTime: number): Promise<void>

Scrolls the supplied element into view, afterwards waits for the specified delay time

public

scrollToElemOffset(elem: Element | HTMLElement | Node, behavior: string): void

Scrolls the window by the supplied elements offsetTop.

public

scrollToElemOffsetWithDelay(elem: Element | HTMLElement | Node, delayTime: number): Promise<void>

Scrolls the window by the supplied elements offsetTop.

public

Scrolls the window by the supplied x and y amount

public

scrollWindowByWithDelay(x: number, y: number, delayTime: number): Promise<void>

Scrolls the window by the supplied x and y amount

public

Scrolls the window down by the supplied amount

public

scrollWindowDownByWithDelay(amount: number, delayTime: number): Promise<void>

Scrolls the window down by the supplied amount

public

Converts the supplied n number of seconds into milliseconds which is required for setTimeout and setInterval

public

selectAllAndClick(selector: string, context: Element): boolean

Selects all elements that match the supplied selector and clicks them returning T/F indicating if a click happened on any selected element

public

async selectAllAndClickWithDelay(opts: {selector: string, cntx: *, delayTime: *}): boolean

Selects all elements that match the supplied selector and clicks them returning T/F indicating if a click happened on any selected element

public

selectAndPlay(selector: string, cntx: Document | Element): Promise<boolean>

Calls the play method of the element returned by the querySelector

public

selectClickAndWaitFor(selector: string, predicate: function(): boolean, selectFrom: HTMLElement | Document): Promise<{predicate: boolean, maxExceeded: boolean, clicked: boolean}>

Clicks the element returned by calling querySelector using the selector on document or the supplied element (selectFrom) and then waits for the supplied predicate function to return true

public

selectElemAndClick(selector: string, cntx: *): boolean

Clicks the element from executing document.querySelector using the supplied selector

public

Clicks the element from executing document.querySelector using the supplied selector and waiting the specified delay time after clicking

public

selectElemFromAndClick(selectFrom: Element | Node | HTMLElement, selector: string): boolean

Clicks the element from executing querySelector using the supplied selector using the supplied element

public

selectElemFromAndClickWithDelay(selectFrom: Element | Node | HTMLElement, selector: string, delayTime: number): Promise<boolean>

Clicks the element from executing querySelector using the supplied selector from the supplied element and waiting the specified delay time after clicking

public

selectFromAndClickNTimes(selectFrom: Element, selector: string, n: number): number

Clicks the element returned from result of calling querySelector using the supplied selector on the supplied element N number of times.

public

async selectFromAndClickNTimesWithDelay(selectFrom: Element, selector: string, n: number, delayTime: number): Promise<number>

Clicks the element returned from result of calling querySelector using the supplied selector on the supplied element N number of times and waits for delay time afters each click.

public

async selectFromAndClickUntilNullWithDelay(selectFrom: Element, selector: string, options: {delay: number, max: ?number}): Promise<number>

Clicks the element returned from result of calling querySelector using the supplied selector on the supplied element until the results of the evaluting the selector returns null/undefined, waiting for delay time afters each click.

public

selectIdAndPlay(eid: string, cntx: Document): Promise<boolean>

Calls the play method of the element returned by calling document.getElementById

public

Like selectFromAndClickUntilNullWithDelay but will stop selecting and clicking the selected element if the current reference becomes disconnected from the dom or the optional stopPredicate returns true.

public

Like selectFromAndClickUntilNullWithDelay but will stop selecting and clicking the selected element if the current reference becomes disconnected from the dom or the optional stopPredicate returns true.

public

selectedNextElementSibling(selector: string, context: SomeElement | Document): SomeElement

Returns the next element sibling of the supplied selector IFF the selector returns a results and the next element sibling exists otherwise null/undefined

public

selectorExists(selector: string, cntx: Document | SomeElement): boolean

Determines if the element the supplied selector selects exists

public

Sends the supplied array of URLs to the backing pywb/webrecorder auto-fetch worker if it exists

public

setIntervalP(callback: *, timeout: *): number

Polls the supplied function at the timeout rate only if the behavior is not paused

public

setTimeoutP(callback: *, timeout: *): number

Like setTimeout except that the timeout respects the pause state of the behavior

public

Scrolls the window by the supplied x and y amount smoothly

public

Scrolls the window down by the supplied amount smoothly

public

Returns the results of splitting the supplied elements innerText using the supplied splitter

public

Returns the results of splitting the supplied elements textContent using the supplied splitter

public

Returns a behavior state object with the supplied msg indicating the behavior runner should not wait for network idle.

public

Returns a behavior state object with the supplied msg indicating the behavior runner should wait for network idle.

public

async stateWithMsgWaitFromAwaitable(awaitable: Promise<boolean>, msg: *, state: *): Promise<BehaviorState>

Returns a Promise that resolves to an behavior state object with the supplied msg with the wait value being set by the value resolved Promise.

public

Returns a behavior state object with the supplied msg with the wait value being set by the return value of the supplied function.

public

stringBetween(str: string, left: string, right: string): string

Returns the string between the left and right string

public

Returns the substring from the index of the supplied needle

public

Returns the substring from the last index of the supplied needle

public

Attempts to convert the supplied string into title case

public

Attempts to convert the supplied string to boolean (true, yes, on, 1)

public

toFloat(str: string, precision: number): number

Attempts to convert the supplied string to a float

public

toInt(str: string, base: number): number

Attempts to convert the supplied string to a integer

public

async * traverseChildrenOf(parentElement: SomeElement, fn: function(element: SomeElement, additionalArgs: *): *, additionalArgs: *): AsyncIterableIterator<*>

Applies a function to the children of the supplied parent element yielding the return value of the function.

public

async * traverseChildrenOfCustom(opts: TraversalOpts): AsyncIterableIterator<*>

Traverses the children of the supplied element applying the supplied function to each child and yielding the return value of the function.

public

async * traverseChildrenOfLoaderParent(parentElement: SomeElement, fn: function(element: SomeElement, additionalArgs: *): *, additionalArgs: *): AsyncIterableIterator<*>

Applies a function to the children of the supplied parent element yielding the return value of the function.

public

async * traverseChildrenOfLoaderParentGenFn(parentElement: SomeElement, genFn: function(): BoolOrPromiseBool, fn: function(element: SomeElement, additionalArgs: *): *, additionalArgs: *): AsyncIterableIterator<*>

Applies a function to the children of the supplied parent element yielding the return value of the function.

public

async * traverseChildrenOfLoaderParentRemovingPrevious(parentElement: SomeElement, fn: function(element: SomeElement, additionalArgs: *): *, additionalArgs: *): AsyncIterableIterator<*>

Applies a function to the children of the supplied parent element yielding the return value of the function and then removing the previously considered child element from the DOM.

public

async * traverseChildrenOfRemovingPrevious(parentElement: SomeElement, fn: function(element: SomeElement, additionalArgs: *): *, additionalArgs: *): AsyncIterableIterator<*>

Applies a function to the children of the supplied parent element yielding the return value of the function and then removing the previously considered child element from the DOM.

public

uaThinksMediaElementCanPlayAllTheWay(mediaElement: HTMLMediaElement): Promise<void>

Returns a promise that resolves once the canplaythrough or error event is fired from the supplied media element

public

Creates and returns a valid uuid v4

public

Waits for the number children of the supplied parentElement to become greater than the supplied parent elements currentChildCount.

public

Waits for additional child elements to be added to the supplied parentElement using a mutation observer.

public

Calls fromNode.querySelector using the supplied selector.

public

waitForEventTargetToFireEvent(eventTarget: EventTarget, event: string, max: number): Promise<boolean>

Returns a promise that resolves to true once the supplied event is fired from the supplied event target.

public

Waits for the value of window.location.href to differ from the supplied value due to browser history manipulation.

public

Returns a promise that resolves once the supplied predicate function returns a truthy value.

public

Waits for the supplied selector to exist

public

Waits for the supplied element to be removed from the document.

public

async * walkChildrenOfCustom(opts: WalkChildrenOfCustomOpts): AsyncIterableIterator<SomeElement>

Walks the children of the supplied parent element yielding its children.

public

Returns the results of evaluating one of the supplied xpath queries if one of the queries yields results otherwise null/undefined

public

xpathSnapShot(xpathQuery: string, contextElement: SomeElement | Document): XPathResult

Returns the results of evaluating the supplied xpath query using an optional context contextElement, defaults to document, as XPathResult.ORDERED_NODE_SNAPSHOT_TYPE

public

xpathSnapShotArray(xpathQuery: string, contextElement: SomeElement | Document): Array<SomeElement>

Provides the same functionality of the chrome console utility $x but likely less performant

Static Public

public addBehaviorStyle(styleDef: string): Object source

import {addBehaviorStyle} from 'lib/dom.js'

Creates a style tag if one was not created before and adds the supplied styleDef to it. If a style tag was created before this function is a no-op

Params:

NameTypeAttributeDescription
styleDef string

The CSS rules to add

Return:

Object

An object containing the selectors as key value pairs where the keys are the selectors in camelcase and the value is the raw selector

public addClass(elem: SomeElement, clazz: string) source

import {addClass} from 'lib/dom.js'

Adds a CSS classname to the supplied element

Params:

NameTypeAttributeDescription
elem SomeElement
  • nullable: true

The element to add the classname to

clazz string

The classname to be added

import {addOutLinks} from 'lib/outlinkCollector.js'

Add the array/nodelist of A or Anchor tags href properties the collected outlinks

Params:

NameTypeAttributeDescription
toAdd Array<HTMLAnchorElement|HTMLAreaElement>|NodeList<HTMLAnchorElement|HTMLAreaElement>

The elements with href properties that are to be added to the collected outlinks

import {addOutlink} from 'lib/outlinkCollector.js'

Add the URL or href value of the supplied argument

Params:

NameTypeAttributeDescription
elemOrString HTMLAnchorElement | HTMLAreaElement | string

The element with href property or string to add to the collected outlinks

public anySelectorExists(selectors: Array<string>, cntx: SomeElement): {idx: number, success: boolean} source

import {anySelectorExists} from 'lib/dom.js'

Determines if the element the supplied selector selects exists.

If one of the supplied selectors matches an existing element the idx property of the returned object is set to the index of the selector in the array and the success property is set to true.

Otherwise idx = -1 and success = false.

Params:

NameTypeAttributeDescription
selectors Array<string>

The query selectors to use for testing if the elements it selects exist

cntx SomeElement
  • optional

Optional element to use rather than the current JS context's document object

Return:

{idx: number, success: boolean}

The results of the selectors existence check

public attr(elem: SomeElement, attr: string): * source

import {attr} from 'lib/dom.js'

Retrieves the value of an elements attribute if it exists

Params:

NameTypeAttributeDescription
elem SomeElement

The element to retrieve an attribute from

attr string

The name of the attribute to be retrieved

Return:

*

The value of the retrieved attribute if it exists

public attrEq(elem: SomeElement, attr: string, shouldEq: *): boolean source

import {attrEq} from 'lib/dom.js'

Tests to determine if the value of elements attribute equals the supplied value using loose equality

Params:

NameTypeAttributeDescription
elem SomeElement

The element to retrieve an attribute from

attr string

The name of the attribute to be retrieved

shouldEq *

The value the attributes value should equal

Return:

boolean

T/F indicating if the attribute equals. Note false can indicate the attribute does not equal expected or the element was null/undefined

public autoFetchFromDoc() source

import {autoFetchFromDoc} from 'lib/general.js'

Initiates an pywb/webrecorder auto-fetch of content

public autobind(clazz: *) source

import {autobind} from 'lib/general.js'

Automatically binds the non-inherited functions of the supplied class to itself.

Params:

NameTypeAttributeDescription
clazz *

public browserHistoryGoBack() source

import {browserHistoryGoBack} from 'lib/browser.js'

Navigate the browser back 1 entry in the history stack. This may cause navigation.

public browserLocation(): string source

import {browserLocation} from 'lib/browser.js'

Returns the value window.location.href

Return:

string

public buildCustomPostStepFn(customFN: function(rawResults: RawBehaviorStepResults): void): function(state: RawBehaviorStepResults): BehaviorStepResults source

import {buildCustomPostStepFn} from 'lib/postStepFNs.js'

Creates and returns a function wrapping the provided post step function will call the supplied function and return the expected output.

Params:

NameTypeAttributeDescription
customFN function(rawResults: RawBehaviorStepResults): void

public camelCase(str: string): string source

import {camelCase} from 'lib/strings.js'

Attempts to convert the supplied string into camel case

Params:

NameTypeAttributeDescription
str string

Return:

string

public camelCaseToDashDelim(str: string): string source

import {camelCaseToDashDelim} from 'lib/strings.js'

Attempts to convert the supplied camel case string into dash delimited string

Params:

NameTypeAttributeDescription
str string
  • nullable: true

Return:

string (nullable: true)

public camelCaseToUnderscoreDelim(str: string): string source

import {camelCaseToUnderscoreDelim} from 'lib/strings.js'

Attempts to convert the supplied camel case string into an underscore delimited string

Params:

NameTypeAttributeDescription
str string
  • nullable: true

Return:

string (nullable: true)

public canAccessIf(iframe: HTMLIFrameElement): boolean source

import {canAccessIf} from 'lib/dom.js'

Determines if the supplied iframe is accessible from this origin. Test is that access the window object of the iframes contentWindow does not throw an exception and the contentDocument is not falsy.

Params:

NameTypeAttributeDescription
iframe HTMLIFrameElement

The iframe to determine accessibility

Return:

boolean

True if the iframe is accessible and false otherwise

public canScrollDownMore(): boolean source

import {canScrollDownMore} from 'lib/scrolls.js'

Determines if we can scroll down any more

Return:

boolean

T/F indicating if we can scroll down some more

public canScrollUpMore(): boolean source

import {canScrollUpMore} from 'lib/scrolls.js'

Determines if we can scroll up any more

Return:

boolean

T/F indicating if we can scroll up some more

public capitalize(str: string): string source

import {capitalize} from 'lib/strings.js'

Attempts to capitalize the supplied string

Params:

NameTypeAttributeDescription
str string

Return:

string

public chainFistChildElemOf(elem: SomeElement, times: number): SomeElement source

import {chainFistChildElemOf} from 'lib/dom.js'

Chains firstChildElementOf on the supplied element n times

Params:

NameTypeAttributeDescription
elem SomeElement

The starting element

times number

How many times to call firstChildElementOf

Return:

SomeElement (nullable: true)

public chainLastChildElemOf(elem: SomeElement, times: number): SomeElement source

import {chainLastChildElemOf} from 'lib/dom.js'

Chains lastChildElementOf n times starting with the supplied element

Params:

NameTypeAttributeDescription
elem SomeElement

The starting parent element who

times number

How many times should the

Return:

SomeElement (nullable: true)

public chainNthChildElementOf(elem: SomeElement, nths: ...number): SomeElement source

import {chainNthChildElementOf} from 'lib/dom.js'

Chains nthChildElementOf for each nth child element in nths

Params:

NameTypeAttributeDescription
elem SomeElement

The starting parent element

nths ...number

The consecutive nth child node

Return:

SomeElement (nullable: true)

Example:

// child is the parent elements 3rd child element's 4th child element's 5th child element
const child = chainNthChildElementOf(parentElement, 3, 4, 5);

public chainNthChildNodeOf(startingElem: SomeElement, nths: ...number): SomeElement source

import {chainNthChildNodeOf} from 'lib/dom.js'

Chains nthChildElemOf for each nth child in nths

Params:

NameTypeAttributeDescription
startingElem SomeElement

The starting parent element

nths ...number

The consecutive nth child node

Return:

SomeElement (nullable: true)

Example:

// child is the parent elements 3rd child node's 4th child node's 5th child node
const child = chainNthChildNodeOf(parentElement, 3, 4, 5);

public chainQs(startingSelectFrom: SomeElement | Document, startingSelector: string, selectors: ...string): SomeElement source

import {chainQs} from 'lib/dom.js'

Consecutively calls querySelector(selector) on the element returned by the previous invocation

Params:

NameTypeAttributeDescription
startingSelectFrom SomeElement | Document

The first element to perform querySelector(startingSelector) on

startingSelector string

The first selector

selectors ...string

Additional selections

Return:

SomeElement (nullable: true)

Final selected element if it exists

public * childElementIterator(parentElement: SomeElement): IterableIterator<SomeElement> source

import {childElementIterator} from 'lib/dom.js'

Returns an iterator over the supplied parent element's child elements that ends once the current child has no next element sibling.

If the parent element is null/undefined then the returned iterator yields nothing.

Params:

NameTypeAttributeDescription
parentElement SomeElement

The parent element who's child elements will be iterated over

Return:

IterableIterator<SomeElement>

public * childNodeIterator(parentElement: SomeElement): IterableIterator<Node> source

import {childNodeIterator} from 'lib/dom.js'

Returns an iterator over the supplied parent element's child nodes that ends once the current child has no next sibling.

If the parent element is null/undefined then the returned iterator yields nothing.

Params:

NameTypeAttributeDescription
parentElement SomeElement

The parent element who's child nodes will be iterated over

Return:

IterableIterator<Node>

public click(elem: SomeElement): boolean source

import {click} from 'lib/clicks.js'

Calls the click function on the supplied element if non-null/defined. Returns true or false to indicate if the click happened

Params:

NameTypeAttributeDescription
elem SomeElement
  • nullable: true

The element to be clicked

Return:

boolean

T/F to indicate that click happened.

public async clickAndWaitFor(elem: Element | Node | HTMLElement, predicate: function(): boolean, options: WaitForOptions): Promise<{predicate: boolean, maxExceeded: boolean, clicked: boolean}> source

import {clickAndWaitFor} from 'lib/clicks.js'

Clicks the supplied element and then waits for the supplied predicate function to return true

Params:

NameTypeAttributeDescription
elem Element | Node | HTMLElement

the element to be clicked

predicate function(): boolean

function returning true or false indicating the wait condition is satisfied

options WaitForOptions
  • optional
  • nullable: true

Options controlling how the wait will happen

Return:

Promise<{predicate: boolean, maxExceeded: boolean, clicked: boolean}>

A Promise that resolves with an object indicating the results of the operation

public async clickAndWaitForHistoryChange(elemToBeClicked: Element | HTMLElement, waitOpts: WaitForOptions): Promise<{oldlocation: ?string, historyChanged: boolean, clicked: boolean, newLocation: ?string, ok: boolean}> source

import {clickAndWaitForHistoryChange} from 'lib/clicks.js'

Clicks the supplied element and waits for browser history to change (the URL is updated by JavaScript modifying the current history stack)

Params:

NameTypeAttributeDescription
elemToBeClicked Element | HTMLElement

the Element to be click

waitOpts WaitForOptions
  • optional

options controlling the wait

Return:

Promise<{oldlocation: ?string, historyChanged: boolean, clicked: boolean, newLocation: ?string, ok: boolean}>

public clickInContext(elem: SomeElement, cntx: Window): boolean source

import {clickInContext} from 'lib/clicks.js'

Calls the click function on the supplied element if non-null/defined that exists in the JS context of the supplied window (cntx). Returns true or false to indicate if the click happened

Params:

NameTypeAttributeDescription
elem SomeElement

The element to be clicked

cntx Window

The context window

Return:

boolean

T/F to indicate that click happened.

public async clickInContextWithDelay(elem: HTMLElement | Element, cntx: Window, delayTime: number): Promise<boolean> source

import {clickInContextWithDelay} from 'lib/clicks.js'

Calls the click method of the supplied element that exists in the JS context of the supplied window object (cntx) and waits the specified delayTime after clicking IFF the supplied element was non-null/undefined.

Params:

NameTypeAttributeDescription
elem HTMLElement | Element

The element to be clicked

cntx Window

The context window

delayTime number
  • optional
  • default: 1000

How long is the delay after click

Return:

Promise<boolean>

A Promise that resolves to T/F indicating if the click happened

public async clickWithDelay(elem: SomeElement, delayTime: number): Promise<boolean> source

import {clickWithDelay} from 'lib/clicks.js'

Calls the click method of the supplied element and waits the specified delayTime after clicking IFF the supplied element was non-null/undefined.

Params:

NameTypeAttributeDescription
elem SomeElement
  • nullable: true

The element to be clicked

delayTime number
  • optional
  • default: 1000

How long is the delay after click

Return:

Promise<boolean>

A Promise that resolves to T/F indicating if the click happened

public collapseWhitespace(str: string): string source

import {collapseWhitespace} from 'lib/strings.js'

Attempts to collapse all extra white space into a single white space character

Params:

NameTypeAttributeDescription
str string

Return:

string

public collectOutlinksFrom(queryFrom: Element | Document) source

import {collectOutlinksFrom} from 'lib/outlinkCollector.js'

Collects outlinks form the supplied element

Params:

NameTypeAttributeDescription
queryFrom Element | Document

The element to collect outlinks from

public collectOutlinksFromDoc() source

import {collectOutlinksFromDoc} from 'lib/outlinkCollector.js'

Collects the outlinks from the document

public compose(funcs: function(...args: *): *): function(...args: *): * source

import {compose} from 'lib/general.js'

Composes multiple functions from right to left into a single function. The rightmost function can take multiple arguments with the remaining functions taking only a single argument, the return value of the previous invocation.

Params:

NameTypeAttributeDescription
funcs function(...args: *): *

The functions to compose.

Return:

function(...args: *): *

A function obtained by composing the functions from right to left. For example, compose(f, g, h) is identical to doing (...args) => f(g(h(...args))).

public composeAsync(funcs: function(...args: *): Promise<*>): function(...args: *): Promise<*> source

import {composeAsync} from 'lib/general.js'

Composes multiple async or Promise returning functions from right to left into a single function. The rightmost function can take multiple arguments with the remaining functions taking only a single argument, the return value of the previous invocation.

Params:

NameTypeAttributeDescription
funcs function(...args: *): Promise<*>

The functions to compose.

Return:

function(...args: *): Promise<*>

A function obtained by composing the functions from right to left. For example, composeAsync(f, g, h) is identical to doing (...args) => h(...args).then(result => g(result).then(result => f(result)).

public composeAsyncIterators(funcs: function(...args: *): AsyncIterator<*>): function(...args: *): AsyncIterator<*> source

import {composeAsyncIterators} from 'lib/general.js'

Composes multiple AsyncIterator returning functions from right to left into a single function. The rightmost function can take multiple arguments with the remaining functions taking only a single argument, the iterator returned by the previous invocation. The composition of AsyncIterator can thought of as chaining multiple AsyncIterator together, that is to say feeding the yielded results of each iterator from right to left. This can be useful for chaining cascading asynchronous ordered actions.

Params:

NameTypeAttributeDescription
funcs function(...args: *): AsyncIterator<*>

The AsyncIterator returning functions to be composed (chained)

Return:

function(...args: *): AsyncIterator<*>

A function obtained by composing the functions from right to left. See the documentations example for details

Example:

  async function* iter1(iter) {
    console.log('start iter1');
    for await (const value of iter) {
      yield `iter1 got "${value}" from the previous iter`;
    }
    yield 'end iter1';
  }

  async function* iter2(iter) {
    console.log('start iter2');
    for await (const value of iter) {
      yield `iter2 got "${value}" from the previous iter`;
    }
    yield 'end iter2';
  }

  async function* iter3(...args) {
    console.log('start iter3');
    let i = args.length;
    while (i--) {
      yield args[i];
    }
   yield 'end iter3';
 }

 const finalAIter = composeAsyncIterators(iter1, iter2, iter3)(1, 2, 3, 4, 5);

 (async () => {
   for await (const it of finalAIter) {
     console.log(it);
   }
 })();

 // The output is as follows
 // logs "start iter" from iter1
 // logs "start iter2" from iter2
 // logs "start iter3" from iter3
 // logs 'iter1 got "iter2 got "5" from the previous iter" from the previous iter' from the for await of finalAiter
 // logs 'iter1 got "iter2 got "4" from the previous iter" from the previous iter' from the for await of finalAiter
 // logs 'iter1 got "iter2 got "3" from the previous iter" from the previous iter' from the for await of finalAiter
 // logs 'iter1 got "iter2 got "2" from the previous iter" from the previous iter' from the for await of finalAiter
 // logs 'iter1 got "iter2 got "1" from the previous iter" from the previous iter' from the for await of finalAiter
 // logs 'iter1 got "iter2 got "end iter3" from the previous iter" from the previous iter' from the for await of finalAiter
 // logs 'iter1 got "end iter2" from the previous iter' from the for await of finalAiter
 // logs 'end iter1' from the for await of finalAiter

public composeIterators(funcs: function(...args: *): Iterator<*>): function(...args: *): Iterator<*> source

import {composeIterators} from 'lib/general.js'

Composes multiple Iterator returning functions from right to left into a single function. The rightmost function can take multiple arguments with the remaining functions taking only a single argument, the iterator returned by the previous invocation. The composition of iterators can thought of as chaining multiple iterators together, that is to say feeding the yielded results of each iterator from right to left. This can be useful for chaining cascading ordered actions.

Params:

NameTypeAttributeDescription
funcs function(...args: *): Iterator<*>

The Iterator returning functions to be composed (chained)

Return:

function(...args: *): Iterator<*>

A function obtained by composing the functions from right to left. See the documentations example for details

Example:

  function* iter1(iter) {
    console.log('start iter1');
    for (const value of iter) {
      yield `iter1 got "${value}" from the previous iter`;
    }
    yield 'end iter1';
  }

  function* iter2(iter) {
    console.log('start iter2');
    for (const value of iter) {
      yield `iter2 got "${value}" from the previous iter`;
    }
    yield 'end iter2';
  }

  function* iter3(...args) {
    console.log('start iter3');
    let i = args.length;
    while (i--) {
      yield args[i];
    }
   yield 'end iter3';
 }

 const finalIter = composeIterators(iter1, iter2, iter3)(1, 2, 3, 4, 5);

 for (const it of finalIter) {
   console.log(it);
}

 // The output is as follows
 // logs "start iter" from iter1
 // logs "start iter2" from iter2
 // logs "start iter3" from iter3
 // logs 'iter1 got "iter2 got "5" from the previous iter" from the previous iter' from the for of finalIter
 // logs 'iter1 got "iter2 got "4" from the previous iter" from the previous iter' from the for of finalIter
 // logs 'iter1 got "iter2 got "3" from the previous iter" from the previous iter' from the for of finalIter
 // logs 'iter1 got "iter2 got "2" from the previous iter" from the previous iter' from the for of finalIter
 // logs 'iter1 got "iter2 got "1" from the previous iter" from the previous iter' from the for of finalIter
 // logs 'iter1 got "iter2 got "end iter3" from the previous iter" from the previous iter' from the for of finalIter
 // logs 'iter1 got "end iter2" from the previous iter' from the for of finalIter
 // logs 'end iter1' from the for of finalIter

public createMouseEvent(config: CreateMouseEventOptions): MouseEvent source

import {createMouseEvent} from 'lib/events.js'

Creates and returns a new mouse event configured using the supplied options

Params:

NameTypeAttributeDescription
config CreateMouseEventOptions

Return:

MouseEvent

public createScrollAmount(desiredTimesToScroll: number): {timesToScroll: number, scrollUpDownAmount: number, scrollLeftRightAmount: number} source

import {createScrollAmount} from 'lib/scrolls.js'

Creates and returns an object that calculates the scroll amount, up/down or left/right, based on dividing the scroll width/height by the supplied desired times to completely scroll the page, defaults to 10.

The calculation also takes into account the fact that the height or width of the document may change and reacts to those changes such that the returned scroll amount is always proportional to the documents current maximum scroll height or width

Params:

NameTypeAttributeDescription
desiredTimesToScroll number
  • optional
  • default: 10

How many scrolls until the maximum scroll position is reached

Return:

{timesToScroll: number, scrollUpDownAmount: number, scrollLeftRightAmount: number}

public createScroller(timesToScroll: number): Scroller source

import {createScroller} from 'lib/scrolls.js'

Creates and returns an object for scrolling the page up/down and left/right. The number of times a respective scroll has occurred is also tracked.

For additional details see the documentation of createScrollAmount as the amount of scroll applied is determined the object it returns.

Params:

NameTypeAttributeDescription
timesToScroll number
  • optional
  • default: 10

How many scrolls until the maximum scroll position is reached

Return:

Scroller

public createState(wait: boolean, msg: *, state: *): BehaviorState source

import {createState} from 'lib/behaviorState.js'

Returns a behavior state object with the supplied wait and msg values. The value returned should be yield'd to the behavior runner

Params:

NameTypeAttributeDescription
wait boolean
msg *

A message from the behavior representing a description of the action just performed

state *
  • optional

Any additional information about the full state of the behavior

Return:

BehaviorState

public delay(delayTime: number): Promise<void> source

import {delay} from 'lib/delays.js'

Returns a Promise that resolves after waiting the amount of time specified by delayTime.

Params:

NameTypeAttributeDescription
delayTime number
  • optional
  • default: 3000

The length of the delay in milliseconds

Return:

Promise<void>

public async * disconnectingWalk(walkState: DisconnectingWalkState): AsyncIterableIterator<*> source

import {disconnectingWalk} from 'lib/traversals.js'

Yields the child elements of the found parent element. If the parent element becomes removed from the DOM after yielding the current child, the parent element and current child are re-found.

Params:

NameTypeAttributeDescription
walkState DisconnectingWalkState

Return:

AsyncIterableIterator<*>

public docBaseURIEndsWith(shouldEndWith: string, cntxDoc: Document): boolean source

import {docBaseURIEndsWith} from 'lib/dom.js'

Returns T/F indicating if the documents baseURI ends with the supplied string

Params:

NameTypeAttributeDescription
shouldEndWith string

What the documents base URI should end with

cntxDoc Document
  • optional

Optional document object to use rather than defaulting to the current execution contexts document object

Return:

boolean

public docBaseURIEquals(shouldEqual: string, cntxDoc: Document): boolean source

import {docBaseURIEquals} from 'lib/dom.js'

Returns T/F indicating if the documents baseURI equals the supplied string

Params:

NameTypeAttributeDescription
shouldEqual string

What the documents base URI should be equal to

cntxDoc Document
  • optional

Optional document object to use rather than defaulting to the current execution contexts document object

Return:

boolean

public documentScrollPosition(doc: Document): {scrollTop: number, scrollLeft: number} source

import {documentScrollPosition} from 'lib/dom.js'

Returns the scrollTop and scrollLeft values of the supplied document if one was supplied other wise the values are from the current document

Params:

NameTypeAttributeDescription
doc Document
  • optional
  • nullable: true

Return:

{scrollTop: number, scrollLeft: number}

public domCompletePromise(): Promise<void> source

import {domCompletePromise} from 'lib/delays.js'

Returns a promise that resolves once document.readyState === 'complete'

Return:

Promise<void>

public doneOrWait(rawResults: RawBehaviorStepResults): BehaviorStepResults source

import {doneOrWait} from 'lib/postStepFNs.js'

The default post step function used for all behaviors that do not provide one.

Params:

NameTypeAttributeDescription
rawResults RawBehaviorStepResults

public elemDataValue(elem: HTMLElement | SVGElement, dataKey: string): string source

import {elemDataValue} from 'lib/dom.js'

Returns the value of the elements data attribute if it exists If the element is null/undefined or does not have data attributes null is returned.

Params:

NameTypeAttributeDescription
elem HTMLElement | SVGElement

The element that should have the data attribute

dataKey string

The name of the data value to be retrieved

Return:

string (nullable: true)

public elemDataValueEqs(elem: HTMLElement | SVGElement, dataKey: *, dataValue: *): boolean source

import {elemDataValueEqs} from 'lib/dom.js'

Returns T/F indicating if the element has data attribute equal to the supplied value

Params:

NameTypeAttributeDescription
elem HTMLElement | SVGElement

The element that should have the data attribute

dataKey *

The name of the data value to be retrieved

dataValue *

The expected value of the elements data attribute

Return:

boolean

public elemHasChildren(elem: Element): boolean source

import {elemHasChildren} from 'lib/dom.js'

Returns T/F indicating if the supplied element has children. If the supplied element is null/undefined false is returned.

Params:

NameTypeAttributeDescription
elem Element

The element to be checked for children

Return:

boolean

public elemHasSibling(elem: SomeElement): boolean source

import {elemHasSibling} from 'lib/dom.js'

Returns T/F indicating if the supplied element has an sibling element

Params:

NameTypeAttributeDescription
elem SomeElement

Return:

boolean

public elemHasZeroBoundingRect(elem: SomeElement): boolean source

import {elemHasZeroBoundingRect} from 'lib/dom.js'

Determines if the supplied elements bounding client rect's x,y,width,height,top,left properties all equal zero. Note this function returns true if the element is null/undefined;

Params:

NameTypeAttributeDescription
elem SomeElement

The element to be tested

Return:

boolean

T/F indicating if all zero or not.

public elemInnerText(elem: SomeElement, trim: boolean): string source

import {elemInnerText} from 'lib/dom.js'

Returns the supplied elements innerText

Params:

NameTypeAttributeDescription
elem SomeElement
  • nullable: true
trim boolean
  • optional

Should the innerText be trimmed

Return:

string (nullable: true)

public elemInnerTextEqs(elem: SomeElement, shouldEqual: string, trim: boolean): boolean source

import {elemInnerTextEqs} from 'lib/dom.js'

Returns T/F if the supplied elements innerText equals the supplied string case sensitive

Params:

NameTypeAttributeDescription
elem SomeElement
shouldEqual string

The string the elements inner text should equal

trim boolean
  • optional
  • default: false

Should the innerText be trimmed before comparison

Return:

boolean

public elemInnerTextEqsInsensitive(elem: SomeElement, shouldEqual: string, trim: boolean): boolean source

import {elemInnerTextEqsInsensitive} from 'lib/dom.js'

Returns T/F if the supplied elements innerText equals the supplied string case in-sensitive

Params:

NameTypeAttributeDescription
elem SomeElement
shouldEqual string
trim boolean
  • optional
  • default: false

Return:

boolean

public elemInnerTextEqsOneOf(elem: SomeElement, shouldEquals: ...string): boolean source

import {elemInnerTextEqsOneOf} from 'lib/dom.js'

Returns T/F if the supplied elements innerText equals one of the supplied string case sensitive

Params:

NameTypeAttributeDescription
elem SomeElement
shouldEquals ...string

Return:

boolean

public elemInnerTextMatchesRegex(elem: SomeElement, regex: RegExp): boolean source

import {elemInnerTextMatchesRegex} from 'lib/dom.js'

Returns T/F if the supplied elements innerText matches the supplied regex

Params:

NameTypeAttributeDescription
elem SomeElement
regex RegExp

Return:

boolean

public elemMatchesSelector(elem: SomeElement, selector: string): boolean source

import {elemMatchesSelector} from 'lib/dom.js'

Returns T/F indicating if the element matches the supplied selector

Params:

NameTypeAttributeDescription
elem SomeElement
selector string

Return:

boolean

public elemOffsetTopZero(elem: SomeElement): boolean source

import {elemOffsetTopZero} from 'lib/dom.js'

Returns true if the supplied elements offsetTop === 0

Params:

NameTypeAttributeDescription
elem SomeElement

The element to check its offsetTop

Return:

boolean

public elemTextContent(elem: SomeElement): string source

import {elemTextContent} from 'lib/dom.js'

Returns the textContent of the supplied element

Params:

NameTypeAttributeDescription
elem SomeElement

Return:

string (nullable: true)

public elementTextContains(elem: SomeElement, needle: string, caseInsensitive: boolean): boolean source

import {elementTextContains} from 'lib/dom.js'

Returns T/F indicating if the supplied element's textContents contains the supplied string

Params:

NameTypeAttributeDescription
elem SomeElement
needle string

The string that the elements textContents should contain

caseInsensitive boolean
  • optional

Should the compairison be case insensitive

Return:

boolean

public elementTextEndsWith(elem: SomeElement, end: string): boolean source

import {elementTextEndsWith} from 'lib/dom.js'

Returns T/F indicating if the supplied element's textContent ends with the supplied string

Params:

NameTypeAttributeDescription
elem SomeElement
end string

The string the element's textContent should end with

Return:

boolean

public elementTextEqs(elem: SomeElement, shouldEqual: string, caseInsensitive: boolean): boolean source

import {elementTextEqs} from 'lib/dom.js'

Returns T/F indicating if the supplied element's textContents equals the supplied string

Params:

NameTypeAttributeDescription
elem SomeElement
shouldEqual string

The string that the elements textContents should be equal to

caseInsensitive boolean
  • optional

Should the compairison be case insensitive

Return:

boolean

public elementTextStartsWith(elem: SomeElement, start: string): boolean source

import {elementTextStartsWith} from 'lib/dom.js'

Returns T/F indicating if the supplied element's textContent starts with the supplied string

Params:

NameTypeAttributeDescription
elem SomeElement
start string

The string the element's textContent should start with

Return:

boolean

public elementTextStartsWithAndEndsWith(elem: SomeElement, start: string, end: string): boolean source

import {elementTextStartsWithAndEndsWith} from 'lib/dom.js'

Returns T/F indicating if the supplied element' textContent starts and ends with the supplied start and end strings

Params:

NameTypeAttributeDescription
elem SomeElement
start string

The string the element's textContent should start with

end string

The string the element's textContent should end with

Return:

boolean

public elementsNameEquals(elem: SomeElement, name: string): boolean source

import {elementsNameEquals} from 'lib/dom.js'

Returns T/F indicating if the elements name (localName) is equal to the supplied name

Params:

NameTypeAttributeDescription
elem SomeElement

The element to check if its name equals the supplied name

name string

The name of the desired element

Return:

boolean

public extractProps(object: Object, props: ...string): Object source

import {extractProps} from 'lib/general.js'

Returns a new object with the properties of the object on the new object

Params:

NameTypeAttributeDescription
object Object
  • nullable: true

The object to extract properties from

props ...string

The property names to be extracted

Return:

Object (nullable: true)

The new object if the original object was not null

public filteredQs(selector: string, filterFn: function(elem: SomeElement): boolean, context: SomeElement | Document): SomeElement source

import {filteredQs} from 'lib/dom.js'

Utility function for (document||element).querySelector(selector)

Params:

NameTypeAttributeDescription
selector string

the selector to be use

filterFn function(elem: SomeElement): boolean
context SomeElement | Document
  • optional

element to use rather than document for the querySelector call

Return:

SomeElement (nullable: true)

public async findAllMediaElementsAndPlay(cntx: Document | Element): Promise<boolean> source

import {findAllMediaElementsAndPlay} from 'lib/media.js'

Calls the play function on all audio and video elements found in the document. If context is supplied, the selection of audio and video elements is done from the supplied context.

Params:

NameTypeAttributeDescription
cntx Document | Element
  • optional

Optional element to use rather than the current JS context's document object

Return:

Promise<boolean>

public findChildWithKey(reactInstance: Object, key: string): Object source

import {findChildWithKey} from 'lib/reactUtils.js'

Walks the children of a react component to find the one that has the supplied key

Params:

NameTypeAttributeDescription
reactInstance Object

The react instance who's children are to be descended looking for the one with key

key string

The key of the child to retrieve

Return:

Object (nullable: true)

The found child if found

public findDirectChildElement(parentElement: SomeElement, predicate: function(elem: SomeElement): boolean): SomeElement source

import {findDirectChildElement} from 'lib/dom.js'

Applies the supplied predicate to every child element of the supplied parent element and returns the element that the predicate returns true for otherwise returns null.

If the parent element is null then null is returned.

Params:

NameTypeAttributeDescription
parentElement SomeElement

The parent element who's child element will be searched

predicate function(elem: SomeElement): boolean

The predicate function used to select a child

Return:

SomeElement (nullable: true)

public findReduxStore(startingComponent: Object): Object source

import {findReduxStore} from 'lib/reactUtils.js'

Attempts the find the redux store from the supplied component

Params:

NameTypeAttributeDescription
startingComponent Object

Return:

Object (nullable: true)

public findTag(xpg: function(query: string, node: ?Node): Node[], tag: string, predicate: function(elem: SomeElement): boolean, cntx: Document | SomeElement): SomeElement source

import {findTag} from 'lib/dom.js'

Attempts to find a tag using the supplied function that accepts an xpath query and an optional starting element and returns the element the supplied predicate function returns a truthy value for

Params:

NameTypeAttributeDescription
xpg function(query: string, node: ?Node): Node[]

xpath execution function

tag string

The tag to be found

predicate function(elem: SomeElement): boolean

Element selecting predicate function

cntx Document | SomeElement
  • optional

Optional starting element, defaults to document

Return:

SomeElement

The desired element if it was found

public fireEventOn(elem: Element, event: Event) source

import {fireEventOn} from 'lib/events.js'

Fires the supplied event on the supplied element

Params:

NameTypeAttributeDescription
elem Element

The element to have an event fired on

event Event

The event to be fired

public fireMouseEventsOnElement(config: FireMouseEventsOnOptions) source

import {fireMouseEventsOnElement} from 'lib/events.js'

Creates mouse events and fires them in order configured using the supplied options

Params:

NameTypeAttributeDescription
config FireMouseEventsOnOptions

public firstChildElemOfParent(elem: SomeElement): SomeElement source

import {firstChildElemOfParent} from 'lib/dom.js'

Returns the first child element of the supplied elements parent element. If the supplied element or the elements parent is null/undefined null is returned

Params:

NameTypeAttributeDescription
elem SomeElement
  • nullable: true

The element who's parents first child is desired

Return:

SomeElement (nullable: true)

public firstChildElementOf(elem: SomeElement): SomeElement source

import {firstChildElementOf} from 'lib/dom.js'

Returns the supplied elements first element child. If the element is null null is returned

Params:

NameTypeAttributeDescription
elem SomeElement
  • nullable: true

The element who's first child is desired

Return:

SomeElement (nullable: true)

public firstChildElementOfSelector(selector: string, cntx: Document | SomeElement): SomeElement source

import {firstChildElementOfSelector} from 'lib/dom.js'

Returns the first child element of the element matching the supplied selector

Params:

NameTypeAttributeDescription
selector string

The selector to match the parent element of the desired child

cntx Document | SomeElement
  • optional

Optional starting element, defaults to document

Return:

SomeElement (nullable: true)

public getElemSibling(elem: SomeElement): SomeElement source

import {getElemSibling} from 'lib/dom.js'

Returns the supplied elements next element sibling

Params:

NameTypeAttributeDescription
elem SomeElement

The element to receive its sibling

Return:

SomeElement (nullable: true)

The elements sibling if it exists

public getElemSiblingAndRemoveElem(elem: SomeElement): SomeElement source

import {getElemSiblingAndRemoveElem} from 'lib/dom.js'

Returns the supplied elements next element sibling and removes the supplied element

Params:

NameTypeAttributeDescription
elem SomeElement

The element to receive its sibling

Return:

SomeElement (nullable: true)

The elements sibling if it exists

public getElementClientPageCenter(element: SomeElement, options: {floor: boolean}): {clientY: number, clientX: number, pageY: number, pageX: number} source

import {getElementClientPageCenter} from 'lib/dom.js'

Get the center of the passed DOM element

Params:

NameTypeAttributeDescription
element SomeElement
options {floor: boolean}
  • optional

Return:

{clientY: number, clientX: number, pageY: number, pageX: number} (nullable: true)

public getElementClientPagePosition(element: SomeElement, options: Object): {clientY: number, clientX: number, pageY: number, pageX: number} source

import {getElementClientPagePosition} from 'lib/dom.js'

Get the position of the passed DOM element

Params:

NameTypeAttributeDescription
element SomeElement
options Object

Return:

{clientY: number, clientX: number, pageY: number, pageX: number}

public getElementPositionWidthHeight(element: Element, doc: Document): {y: number, pageY: number, x: number, pageX: number, w: number, h: number} source

import {getElementPositionWidthHeight} from 'lib/dom.js'

Helper function to get the actual x and y position, page x and y position (scroll) and the height, width of a given element

Params:

NameTypeAttributeDescription
element Element
doc Document
  • optional

Return:

{y: number, pageY: number, x: number, pageX: number, w: number, h: number} (nullable: true)

public getElemsParentsSibling(elem: SomeElement): SomeElement source

import {getElemsParentsSibling} from 'lib/dom.js'

Returns the next element sibling of the parent element of the supplied element

Params:

NameTypeAttributeDescription
elem SomeElement

The element to receive its sibling

Return:

SomeElement (nullable: true)

The elements sibling if it exists

public getInternalRootOnElem(elem: HTMLElement | Element | Node): Object source

import {getInternalRootOnElem} from 'lib/reactUtils.js'

Returns the internal root object added by react on the supplied element. Property _internalRoot

Params:

NameTypeAttributeDescription
elem HTMLElement | Element | Node

Return:

Object

public getNthParentElement(elem: SomeElement, nth: number): SomeElement source

import {getNthParentElement} from 'lib/dom.js'

Returns the Nth parent element of the supplied element (indexing assumes start is 1)

Params:

NameTypeAttributeDescription
elem SomeElement

The element to retrieve the nth parent element of

nth number

The number of the nth parent

Return:

SomeElement (nullable: true)

The nth parent element if it exists

public getReactRootContainer(elem: HTMLElement | Element | Node): Object source

import {getReactRootContainer} from 'lib/reactUtils.js'

Returns the root container object added by react

Params:

NameTypeAttributeDescription
elem HTMLElement | Element | Node

Return:

Object (nullable: true)

public getReactRootHostElem(alternativeId: string): HTMLElement source

import {getReactRootHostElem} from 'lib/reactUtils.js'

Returns the root host element of an react application (id = react-root)

Params:

NameTypeAttributeDescription
alternativeId string
  • optional

An alternative id to use rather than the default

Return:

HTMLElement (nullable: true)

public getViaPath(obj: *, pathItems: *): * source

import {getViaPath} from 'lib/general.js'

Retrieves the property of an object, or item in array at index, based on the supplied path.

Params:

NameTypeAttributeDescription
obj *

An object

pathItems *

Return:

*

Example:

  const obj = { a: { b: { c: [1, 2, 3] } } }
  const two = getViaPath(obj, 'a', 'b', 'c', 1); // two == 2

public globalWithPropsExist(global: string, props: ...string): boolean source

import {globalWithPropsExist} from 'lib/general.js'

Returns T/F if an global property (on window) exists and has all properties. The existence check is obj[prop] != null

Params:

NameTypeAttributeDescription
global string

The name of the global

props ...string

The property names

Return:

boolean

public hasAnyClass(elem: SomeElement, classes: ...string): boolean source

import {hasAnyClass} from 'lib/dom.js'

Tests to see if the supplied element has any of the supplied css classes

Params:

NameTypeAttributeDescription
elem SomeElement
  • nullable: true

The element to be tested if it has any of the classes

classes ...string

The classes the element can have

Return:

boolean

T/F indicating if the element has any of the classes

public hasClass(elem: SomeElement, clazz: string): boolean source

import {hasClass} from 'lib/dom.js'

Tests to see if the supplied element has a css class

Params:

NameTypeAttributeDescription
elem SomeElement
  • nullable: true

The element to be tested if it has the class

clazz string

The classname

Return:

boolean

T/F indicating if the element has the class

public hasClasses(elem: SomeElement, classes: ...string): boolean source

import {hasClasses} from 'lib/dom.js'

Tests to see if the supplied element has the supplied css classes

Params:

NameTypeAttributeDescription
elem SomeElement
  • nullable: true

The element to be tested if it has the classes

classes ...string

The classes the element must have

Return:

boolean

T/F indicating if the element has the classes

public id(eid: string, context: SomeElement | Document): SomeElement source

import {id} from 'lib/dom.js'

Utility function for document.getElementById(id)

Params:

NameTypeAttributeDescription
eid string

The id of the element to get

context SomeElement | Document
  • optional

Optional document element to use rather than the current JS context's

Return:

SomeElement (nullable: true)

public idExists(eid: string, cntx: Document): boolean source

import {idExists} from 'lib/dom.js'

Determines if the element the supplied id identifies exists

Params:

NameTypeAttributeDescription
eid string

The id of the element

cntx Document
  • optional

Optional document object to use rather than the current JS context's document object

Return:

boolean

True if the element exists, false otherwise

public initRunnableBehavior(init: BehaviorRunnerInitOpts): BehaviorRunner source

import {initRunnableBehavior} from 'lib/behaviorRunner.js'

Performs the setup required for integration with Webrecorders automation system Adds as propeties to the supplied window object

  • $WBBehaviorStepIter$: the supplied behaviorStepIterator
  • $WBBehaviorRunner$: the instance of the class that wraps the behaviors actions
  • $WRIteratorHandler$: a function that initiates a behaviors action

Params:

NameTypeAttributeDescription
init BehaviorRunnerInitOpts

Object used to initialize the behavior for running

Return:

BehaviorRunner

public innerTextOfSelected(selector: string, cntx: SomeElement | Document): string source

import {innerTextOfSelected} from 'lib/dom.js'

Returns the inner text of the element the supplied selectors matches

Params:

NameTypeAttributeDescription
selector string

the selector to be use

cntx SomeElement | Document
  • optional

element to use rather than document for the querySelector call

Return:

string (nullable: true)

public isAlpha(str: string): boolean source

import {isAlpha} from 'lib/strings.js'

Returns T/F indicating if the supplied string is only alpha characters

Params:

NameTypeAttributeDescription
str string
  • nullable: true

Return:

boolean

public isAlphaNumeric(str: string): boolean source

import {isAlphaNumeric} from 'lib/strings.js'

Returns T/F indicating if the supplied string is only alpha numeric characters

Params:

NameTypeAttributeDescription
str string
  • nullable: true

Return:

boolean

public isClasslessElem(elem: SomeElement): boolean source

import {isClasslessElem} from 'lib/dom.js'

Returns T/F indicating if the supplied element has not CSS classes

Params:

NameTypeAttributeDescription
elem SomeElement

Return:

boolean

public isElemVisible(elem: SomeElement): boolean source

import {isElemVisible} from 'lib/dom.js'

Returns T/F indicating if the supplied element is visible.

If the supplied element is falsy the return value is false.

The test checks the computed style of the supplied element to determine if it's css display property is not null and the visibility of the element is visible.

Params:

NameTypeAttributeDescription
elem SomeElement

Return:

boolean

public isEmptyString(str: string): boolean source

import {isEmptyString} from 'lib/strings.js'

Returns T/F indicating if the supplied string is truly an empty string

Params:

NameTypeAttributeDescription
str string
  • nullable: true

Return:

boolean

public isFunction(obj: *): boolean source

import {isFunction} from 'lib/general.js'

Returns T/F indicating if the supplied arument is a function

Params:

NameTypeAttributeDescription
obj *

Return:

boolean

public isGenerator(obj: *): boolean source

import {isGenerator} from 'lib/general.js'

Returns T/F indicating if the supplied object is a generator or async generator

Params:

NameTypeAttributeDescription
obj *

Return:

boolean

public isLower(str: string): boolean source

import {isLower} from 'lib/strings.js'

Returns T/F indicating if the supplied string is only lowercase alpha characters

Params:

NameTypeAttributeDescription
str string

Return:

boolean

public isNumeric(str: string): boolean source

import {isNumeric} from 'lib/strings.js'

Returns T/F indicating if the supplied string only contains numeric characters

Params:

NameTypeAttributeDescription
str string
  • nullable: true

Return:

boolean

public isPromise(obj: *): boolean source

import {isPromise} from 'lib/general.js'

Returns T/F indicating if the supplied object is a Promise or Promise like

Params:

NameTypeAttributeDescription
obj *

Return:

boolean

public isUpper(str: string): boolean source

import {isUpper} from 'lib/strings.js'

Returns T/F indicating if the supplied string is only uppercase alpha characters

Params:

NameTypeAttributeDescription
str string
  • nullable: true

Return:

boolean

public lastChildElementOf(elem: SomeElement): SomeElement source

import {lastChildElementOf} from 'lib/dom.js'

Returns the last child element of the supplied element

Params:

NameTypeAttributeDescription
elem SomeElement
  • nullable: true

The element who's last child element is desired

Return:

SomeElement (nullable: true)

public lastChildElementOfSelector(selector: string, cntx: Document | SomeElement): SomeElement source

import {lastChildElementOfSelector} from 'lib/dom.js'

Returns the last child element of the element the selector selects

Params:

NameTypeAttributeDescription
selector string

The selector to be used to select the element who's last child element is desired

cntx Document | SomeElement
  • optional

Optional starting element, defaults to document

Return:

SomeElement (nullable: true)

public locationContains(something: string): boolean source

import {locationContains} from 'lib/browser.js'

Determines if window.location.href contains the supplied value as a substring.

Params:

NameTypeAttributeDescription
something string

The value to determine if it is a substring of window.location.href

Return:

boolean

public locationEquals(someLocation: string): boolean source

import {locationEquals} from 'lib/browser.js'

Determines the strict equality of the string to the value of window.location.href

Params:

NameTypeAttributeDescription
someLocation string

The expect location.href value

Return:

boolean

public async * mapAsyncIterator(iterator: AsyncIterableIterator<*>, mapper: function(arg: *): *): AsyncIterableIterator<*> source

import {mapAsyncIterator} from 'lib/general.js'

Like map for arrays but over async-iterators

Params:

NameTypeAttributeDescription
iterator AsyncIterableIterator<*>

The iterator to have a mapping function applied over

mapper function(arg: *): *

The mapping function

Return:

AsyncIterableIterator<*>

public markElemAsVisited(elem: SomeElement, marker: string) source

import {markElemAsVisited} from 'lib/dom.js'

Marks the supplied element as visited by adding the marker to its classList.

Params:

NameTypeAttributeDescription
elem SomeElement

The element to mark as visited

marker string
  • optional
  • default: 'wrvistited'

Optional marker to use defaults to wrvistited

public maybePolyfillXPG(cliXPG: function(...args: *): Array<SomeElement>): function(...args: *): Array<SomeElement> source

import {maybePolyfillXPG} from 'lib/dom.js'

Ensures that if the value of the chrome console utility $x is not the actual utility (jquery is on the page) the returned function behaves exactly like it.

Params:

NameTypeAttributeDescription
cliXPG function(...args: *): Array<SomeElement>

Return:

function(...args: *): Array<SomeElement>

public maybeRemoveElem(selector: string, context: SomeElement | Document): boolean source

import {maybeRemoveElem} from 'lib/dom.js'

Removes the element selected by the supplied querySelector, if it exits, returning true to indicate the element was removed and false otherwise

Params:

NameTypeAttributeDescription
selector string

the selector to be use

context SomeElement | Document
  • optional

element to use rather than document for the querySelector call

Return:

boolean

public maybeRemoveElemById(eid: string, context: SomeElement | Document): boolean source

import {maybeRemoveElemById} from 'lib/dom.js'

Removes the element with the supplied id, if it exits, returning true to indicate the element was removed and false otherwise

Params:

NameTypeAttributeDescription
eid string

The id of the element to remove

context SomeElement | Document
  • optional

Optional document element to use rather than the current JS context's

Return:

boolean

public async * noExceptGeneratorWrap(generator: AsyncIterableIterator<*>|IterableIterator<*>, returnLast: boolean): AsyncIterableIterator<*> source

import {noExceptGeneratorWrap} from 'lib/general.js'

Wraps the supplied generator in a try catch and re-yields its values generator. If the wrapped generator throws an exception the wrapping generator ends.

Params:

NameTypeAttributeDescription
generator AsyncIterableIterator<*>|IterableIterator<*>

The generator to be wrapped

returnLast boolean
  • optional

Should the last value of the supplied generator be returned

Return:

AsyncIterableIterator<*>

public async noExceptPlayMediaElement(mediaElement: HTMLMediaElement, playThrough: boolean): Promise<boolean> source

import {noExceptPlayMediaElement} from 'lib/media.js'

Calls the play function of the supplied element catching the exception thrown if any was thrown. Returns true indicating call to play was successful otherwise false

Params:

NameTypeAttributeDescription
mediaElement HTMLMediaElement
playThrough boolean
  • optional

Return:

Promise<boolean>

Returns false if an exception occurred or true if playing was successful

public nodesNameEquals(node: SomeElement, name: string): boolean source

import {nodesNameEquals} from 'lib/dom.js'

Returns T/F indicating if the nodes name (nodeName) is equal to the supplied name

Params:

NameTypeAttributeDescription
node SomeElement

The node to check if its name equals the supplied name

name string

The name of the desired Node

Return:

boolean

public noop() source

import {noop} from 'lib/general.js'

This function is a no op

public nthChildElementOf(elem: SomeElement | Document, nth: number): SomeElement source

import {nthChildElementOf} from 'lib/dom.js'

Returns the Nth child element of the supplied element (indexing assumes start is 1)

Params:

NameTypeAttributeDescription
elem SomeElement | Document

The element to retrieve the nth child element of

nth number

The number of the nth child element

Return:

SomeElement (nullable: true)

The nth child if it exists

public nthChildNodeOf(elem: SomeElement | Document, nth: number): SomeElement source

import {nthChildNodeOf} from 'lib/dom.js'

Returns the Nth child node of the supplied element (indexing assumes start is 1)

Params:

NameTypeAttributeDescription
elem SomeElement | Document

The element to retrieve the nth child of

nth number

The number of the nth child

Return:

SomeElement (nullable: true)

The nth child if it exists

public nthPreviousSibling(elem: SomeElement, nth: number): SomeElement source

import {nthPreviousSibling} from 'lib/dom.js'

Returns the nth previous sibling of the supplied element if it is not null/undefined or the supplied element is not null/undefined

Params:

NameTypeAttributeDescription
elem SomeElement
  • nullable: true

The element who's nth previous sibling is desired

nth number

The nth previous sibling

Return:

SomeElement

public numElemChildren(elem: SomeElement): number source

import {numElemChildren} from 'lib/dom.js'

Returns the number of child elements the supplied element has if it is not null/undefined otherwise -1

Params:

NameTypeAttributeDescription
elem SomeElement

The element who's child element count is deired

Return:

number

public objectHasProps(obj: Object, props: ...string): boolean source

import {objectHasProps} from 'lib/general.js'

Returns T/F if the supplied object has all of the supplied properties. The existence check is obj[prop] != null

Params:

NameTypeAttributeDescription
obj Object

The object to be tested

props ...string

The property names

Return:

boolean

public objectInstanceOf(obj: Object, shouldBeInstanceOfThis: Object): boolean source

import {objectInstanceOf} from 'lib/general.js'

Returns T/F indicating if the supplied object is an instance of some class. If the object to be tested is falsy false is returned otherwise the results of the instanceof check.

Params:

NameTypeAttributeDescription
obj Object

The object to be tested

shouldBeInstanceOfThis Object

The class the obj should be an instance of

Return:

boolean

public partial(fn: function, a1: *, a2: *, a3: *, a4: *, a5: *, aN: ...*): function(...args: *): * source

import {partial} from 'lib/general.js'

Creates and returns a partially applied function with args being applied left to right

Params:

NameTypeAttributeDescription
fn function

The function to partially apply arguments to

a1 *
  • optional

1st arg

a2 *
  • optional

2nd arg

a3 *
  • optional

3rd arg

a4 *
  • optional

4th arg

a5 *
  • optional

5th arg

aN ...*
  • optional

The remaining arguments to be partially applied

Return:

function(...args: *): *

Returns the new partially applied function

public partialRight(fn: function, a1: *, a2: *, a3: *, a4: *, a5: *, aN: ...*): function(...args: *): * source

import {partialRight} from 'lib/general.js'

Creates and returns a partially applied function with args being applied right to left

Params:

NameTypeAttributeDescription
fn function

The function to partially apply arguments to

a1 *
  • optional

1st nth arg

a2 *
  • optional

2nd nth arg

a3 *
  • optional

3rd nth arg

a4 *
  • optional

4th nth arg

a5 *
  • optional

5th nth arg

aN ...*
  • optional

The remaining arguments to be partially applied

Return:

function(...args: *): *

Returns the new partially applied function

public promiseResolveReject(): {resolve: function, reject: function, promise: Promise<*>} source

import {promiseResolveReject} from 'lib/general.js'

Creates a Promise that is resolvable externally returning an object that exposes the promise itself and the resolve and reject functions passed as arguments to the executor function

Return:

{resolve: function, reject: function, promise: Promise<*>}

public qs(selector: string, context: SomeElement | Document): SomeElement source

import {qs} from 'lib/dom.js'

Utility function for (document||element).querySelector(selector)

Params:

NameTypeAttributeDescription
selector string

the selector to be use

context SomeElement | Document
  • optional

element to use rather than document for the querySelector call

Return:

SomeElement (nullable: true)

public qsOneOf(options: {selectors: Array<string>, context: *}): SomeElement source

import {qsOneOf} from 'lib/dom.js'

Returns the results of querySelector using one of the supplied selectors one if one of the selectors yields results otherwise null/undefined

Params:

NameTypeAttributeDescription
options {selectors: Array<string>, context: *}

Return:

SomeElement (nullable: true)

public qsa(selector: string, context: SomeElement | Document): NodeList<SomeElement> source

import {qsa} from 'lib/dom.js'

Utility function for document.querySelectorAll(selector)

Params:

NameTypeAttributeDescription
selector string

the selector to be use

context SomeElement | Document
  • optional

element to use rather than document for the querySelector call

public qsaOneOf(options: {selectors: Array<string>, context: *}): NodeList<SomeElement> source

import {qsaOneOf} from 'lib/dom.js'

Returns the results of querySelectorAll using one of the supplied selectors if one of the selectors yields results otherwise null/undefined

Params:

NameTypeAttributeDescription
options {selectors: Array<string>, context: *}

Optional document object to use rather than defaulting to the current execution contexts document object

Return:

NodeList<SomeElement> (nullable: true)

public reactInstanceFromDOMElem(elem: HTMLElement | Element | Node): Object source

import {reactInstanceFromDOMElem} from 'lib/reactUtils.js'

Returns the react instance object that lives on the live element

Params:

NameTypeAttributeDescription
elem HTMLElement | Element | Node

The element to have its react instance extracted from

Return:

Object (nullable: true)

public reactInstancesFromElements(elems: Array<Node|HTMLElement|Element>, selectingFn: function(key: string): boolean): Array<{node: HTMLElement|Element|Node, reactInstance: Object}> source

import {reactInstancesFromElements} from 'lib/reactUtils.js'

Converts the supplied array of elements into an array of objects each with property node (the live dom element) and reactInstance (the live react component). An optional selection function can be supplied that receives the rendered components key and returns T/F to indicate if the component and element is to be selected

Params:

NameTypeAttributeDescription
elems Array<Node|HTMLElement|Element>

The array of elements to get their react instances

selectingFn function(key: string): boolean
  • optional

Optional selection function that takes a components key and returns T/F indicating if the component is selected

Return:

Array<{node: HTMLElement|Element|Node, reactInstance: Object}>

public removeClass(elem: SomeElement, clazz: string) source

import {removeClass} from 'lib/dom.js'

Removes a CSS classname to the supplied element

Params:

NameTypeAttributeDescription
elem SomeElement
  • nullable: true

The element to remove the classname to

clazz string

The classname to be removed

public * repeatedXpathQueryIterator(query: string, cntx: *, generateMoreElements: function(): void): IterableIterator<SomeElement> source

import {repeatedXpathQueryIterator} from 'lib/dom.js'

Repeatably performs the supplied xpath query yielding the results of the each query. If an empty result set is encountered and generateMoreElements function was supplied it is called and the query repeated. If the second query try yields another empty set the iterator ends

Params:

NameTypeAttributeDescription
query string

The xpath query to be repeated until it returns no more elements

cntx *
  • optional

Optional element to execute the xpath query from (defaults to document)

generateMoreElements function(): void
  • optional

Optional function used to generate more elements that may match the supplied xpath

Return:

IterableIterator<SomeElement>

public async * repeatedXpathQueryIteratorAsync(query: string, cntx: *, generateMoreElements: function(): *): AsyncIterableIterator<SomeElement> source

import {repeatedXpathQueryIteratorAsync} from 'lib/dom.js'

Repeatably performs the supplied xpath query yielding the results of the each query. If an empty result set is encountered and generateMoreElements function was supplied it is called and the query repeated. If the second query try yields another empty set the iterator ends

Params:

NameTypeAttributeDescription
query string

The xpath query to be repeated until it returns no more elements

cntx *
  • optional

Optional element to execute the xpath query from (defaults to document)

generateMoreElements function(): *
  • optional

Optional function used to generate more elements that may match the supplied xpath

Return:

AsyncIterableIterator<SomeElement>

public resolveWhenBehaviorUnPaused(): Promise<any> source

import {resolveWhenBehaviorUnPaused} from 'lib/delays.js'

Returns a Promise that resolves once the behavior has been un-paused

Return:

Promise<any>

public scrollAllIntoViewAndClick(elems: Array<HTMLElement>): number source

import {scrollAllIntoViewAndClick} from 'lib/clicks.js'

Scrolls into view and clicks all the elements present in the supplied array.

Params:

NameTypeAttributeDescription
elems Array<HTMLElement>

The array of elements to be scrolled into view and clicked

Return:

number

The number of elements clicked out of the supplied array of elements

public async scrollAllIntoViewAndClickWithDelay(elems: Array<HTMLElement|Element|Node>, delayTime: number): Promise<void> source

import {scrollAllIntoViewAndClickWithDelay} from 'lib/clicks.js'

Scrolls into view and clicks all the elements present in the supplied array waiting for the supplied delay time after each click of an element in the array.

Params:

NameTypeAttributeDescription
elems Array<HTMLElement|Element|Node>

The array of elements to be scrolled into view and clicked

delayTime number
  • optional
  • default: 1000

How long is the delay after click

Return:

Promise<void>

public scrollDownByElemHeight(elem: Element | HTMLElement | Node): void source

import {scrollDownByElemHeight} from 'lib/scrolls.js'

Scrolls down by the elements height

Params:

NameTypeAttributeDescription
elem Element | HTMLElement | Node

The element who's height to scroll down by

Return:

void

public scrollDownByElemHeightWithDelay(elem: Element | HTMLElement | Node, delayTime: number): Promise<void> source

import {scrollDownByElemHeightWithDelay} from 'lib/scrolls.js'

Scrolls down by supplied elements height and then waits for the supplied delay time.

Params:

NameTypeAttributeDescription
elem Element | HTMLElement | Node

The element to be

delayTime number
  • optional
  • default: 1000

How long is the delay

Return:

Promise<void>

public scrollIntoView(elem: Element, opts: Object): void source

import {scrollIntoView} from 'lib/scrolls.js'

Scrolls the supplied element into view.

Scroll behavior:

  • behavior: smooth
  • block: center
  • inline: center

Params:

NameTypeAttributeDescription
elem Element

The element to be scrolled into view

opts Object
  • optional

Optional scroll behavior to be used rather than the default

Return:

void

public scrollIntoViewAndClick(elem: HTMLElement | Element): boolean source

import {scrollIntoViewAndClick} from 'lib/clicks.js'

Scrolls the supplied element into view and clicks it if the element is non-null/undefined

Params:

NameTypeAttributeDescription
elem HTMLElement | Element

The element to be scrolled into view and clicked.

Return:

boolean

T/F to indicate that the click happened

public scrollIntoViewAndClickWithDelay(elem: HTMLElement | Element, delayTime: number): Promise<boolean> source

import {scrollIntoViewAndClickWithDelay} from 'lib/clicks.js'

Scrolls the supplied element into view and clicks it if the element is non-null/undefined and waits for the specified delay time

Params:

NameTypeAttributeDescription
elem HTMLElement | Element

The element to be

delayTime number
  • optional
  • default: 1000

How long is the delay

Return:

Promise<boolean>

A Promise that resolves to T/F indicating that the click happened

public scrollIntoViewAndWaitFor(elem: Element | HTMLElement | Node, predicate: function(): boolean, options: {wait: ?WaitForOptions, scrollBehavior: ?Object}): Promise<{predicate: boolean, maxExceeded: boolean}> source

import {scrollIntoViewAndWaitFor} from 'lib/scrolls.js'

Scrolls the supplied element into view and then waits for the supplied predicate function to return true

Scroll behavior:

  • behavior: smooth
  • block: center
  • inline: center

Params:

NameTypeAttributeDescription
elem Element | HTMLElement | Node

The element to be scrolled into view with delay

predicate function(): boolean

Function returning T/F to indicate when the condition waited for has been satisfied

options {wait: ?WaitForOptions, scrollBehavior: ?Object}
  • optional

Options controlling the scroll behavior and how the wait will happen

Return:

Promise<{predicate: boolean, maxExceeded: boolean}>

public scrollIntoViewWithDelay(elem: Element | HTMLElement | Node, delayTime: number): Promise<void> source

import {scrollIntoViewWithDelay} from 'lib/scrolls.js'

Scrolls the supplied element into view, afterwards waits for the specified delay time

Scroll behavior:

  • behavior: smooth
  • block: center
  • inline: center

Params:

NameTypeAttributeDescription
elem Element | HTMLElement | Node

The element to be scrolled into view with delay

delayTime number
  • optional
  • default: 1000

How long is the delay

Return:

Promise<void>

public scrollToElemOffset(elem: Element | HTMLElement | Node, behavior: string): void source

import {scrollToElemOffset} from 'lib/scrolls.js'

Scrolls the window by the supplied elements offsetTop. If the elements offsetTop is zero then scrollIntoView is used

Params:

NameTypeAttributeDescription
elem Element | HTMLElement | Node

The element who's offsetTop will be used to scroll by

behavior string
  • optional

Options controlling the behavior of window.scrollTo defaults to auto

Return:

void

public scrollToElemOffsetWithDelay(elem: Element | HTMLElement | Node, delayTime: number): Promise<void> source

import {scrollToElemOffsetWithDelay} from 'lib/scrolls.js'

Scrolls the window by the supplied elements offsetTop. If the elements offsetTop is zero then scrollIntoView is used

Params:

NameTypeAttributeDescription
elem Element | HTMLElement | Node

The element who's offsetTop will be used to scroll by

delayTime number
  • optional
  • default: 1000

How long is the delay

Return:

Promise<void>

public scrollWindowBy(x: number, y: number) source

import {scrollWindowBy} from 'lib/scrolls.js'

Scrolls the window by the supplied x and y amount

Params:

NameTypeAttributeDescription
x number

Amount to scroll in the x direction

y number

Amount to scroll in the y direction

public scrollWindowByWithDelay(x: number, y: number, delayTime: number): Promise<void> source

import {scrollWindowByWithDelay} from 'lib/scrolls.js'

Scrolls the window by the supplied x and y amount

Params:

NameTypeAttributeDescription
x number

Amount to scroll in the x direction

y number

Amount to scroll in the y direction

delayTime number
  • optional
  • default: 1500

Return:

Promise<void>

public scrollWindowDownBy(amount: number) source

import {scrollWindowDownBy} from 'lib/scrolls.js'

Scrolls the window down by the supplied amount

Params:

NameTypeAttributeDescription
amount number

Amount to scroll the down by

public scrollWindowDownByWithDelay(amount: number, delayTime: number): Promise<void> source

import {scrollWindowDownByWithDelay} from 'lib/scrolls.js'

Scrolls the window down by the supplied amount

Params:

NameTypeAttributeDescription
amount number

Amount to scroll the down by

delayTime number
  • optional
  • default: 1500

Return:

Promise<void>

public secondsToDelayAmount(n: number): number source

import {secondsToDelayAmount} from 'lib/delays.js'

Converts the supplied n number of seconds into milliseconds which is required for setTimeout and setInterval

Params:

NameTypeAttributeDescription
n number

The number of seconds to be delayed

Return:

number

The delay amount in milliseconds

public selectAllAndClick(selector: string, context: Element): boolean source

import {selectAllAndClick} from 'lib/clicks.js'

Selects all elements that match the supplied selector and clicks them returning T/F indicating if a click happened on any selected element

Params:

NameTypeAttributeDescription
selector string
context Element
  • optional

Return:

boolean

public async selectAllAndClickWithDelay(opts: {selector: string, cntx: *, delayTime: *}): boolean source

import {selectAllAndClickWithDelay} from 'lib/clicks.js'

Selects all elements that match the supplied selector and clicks them returning T/F indicating if a click happened on any selected element

Params:

NameTypeAttributeDescription
opts {selector: string, cntx: *, delayTime: *}

Return:

boolean

public selectAndPlay(selector: string, cntx: Document | Element): Promise<boolean> source

import {selectAndPlay} from 'lib/media.js'

Calls the play method of the element returned by the querySelector

Params:

NameTypeAttributeDescription
selector string

The query selector to select a media element

cntx Document | Element
  • optional

Optional element/Document to use to perform the querySelector call from

Return:

Promise<boolean>

Returns false if an exception occurred or true if playing was successful

public selectClickAndWaitFor(selector: string, predicate: function(): boolean, selectFrom: HTMLElement | Document): Promise<{predicate: boolean, maxExceeded: boolean, clicked: boolean}> source

import {selectClickAndWaitFor} from 'lib/clicks.js'

Clicks the element returned by calling querySelector using the selector on document or the supplied element (selectFrom) and then waits for the supplied predicate function to return true

Params:

NameTypeAttributeDescription
selector string

the css selector to use

predicate function(): boolean

function returning true or false indicating the wait condition is satisfied

selectFrom HTMLElement | Document
  • optional

optional element to use for the querySelector(selector) call

Return:

Promise<{predicate: boolean, maxExceeded: boolean, clicked: boolean}>

A Promise that resolves with an object indicating the results of the operation

public selectElemAndClick(selector: string, cntx: *): boolean source

import {selectElemAndClick} from 'lib/clicks.js'

Clicks the element from executing document.querySelector using the supplied selector

Params:

NameTypeAttributeDescription
selector string

the css selector to use

cntx *
  • optional

element to use rather than document for the querySelector call

Return:

boolean

T/F to indicate that the click happened

public selectElemAndClickWithDelay(selector: string, delayTime: number): Promise<boolean> source

import {selectElemAndClickWithDelay} from 'lib/clicks.js'

Clicks the element from executing document.querySelector using the supplied selector and waiting the specified delay time after clicking

Params:

NameTypeAttributeDescription
selector string

the css selector to use

delayTime number
  • optional
  • default: 1000

How long is the delay

Return:

Promise<boolean>

A Promise that resolves to T/F indicating that the click happened

public selectElemFromAndClick(selectFrom: Element | Node | HTMLElement, selector: string): boolean source

import {selectElemFromAndClick} from 'lib/clicks.js'

Clicks the element from executing querySelector using the supplied selector using the supplied element

Params:

NameTypeAttributeDescription
selectFrom Element | Node | HTMLElement

element to use for the querySelector call

selector string

the css selector to use

Return:

boolean

T/F to indicate that the click happened

public selectElemFromAndClickWithDelay(selectFrom: Element | Node | HTMLElement, selector: string, delayTime: number): Promise<boolean> source

import {selectElemFromAndClickWithDelay} from 'lib/clicks.js'

Clicks the element from executing querySelector using the supplied selector from the supplied element and waiting the specified delay time after clicking

Params:

NameTypeAttributeDescription
selectFrom Element | Node | HTMLElement

element to use for the querySelector call

selector string

the css selector to use

delayTime number
  • optional
  • default: 1000

How long is the delay

Return:

Promise<boolean>

A Promise that resolves to T/F indicating that the click happened

public selectFromAndClickNTimes(selectFrom: Element, selector: string, n: number): number source

import {selectFromAndClickNTimes} from 'lib/clicks.js'

Clicks the element returned from result of calling querySelector using the supplied selector on the supplied element N number of times. Note that the evaluation of the querySelector is done all N times.

Params:

NameTypeAttributeDescription
selectFrom Element

element to use for the querySelector(selector) call

selector string

the css selector to use

n number

How many times to click the element returned by performing selectFrom.querySelector(selector)

Return:

number

How many clicks occurred

public async selectFromAndClickNTimesWithDelay(selectFrom: Element, selector: string, n: number, delayTime: number): Promise<number> source

import {selectFromAndClickNTimesWithDelay} from 'lib/clicks.js'

Clicks the element returned from result of calling querySelector using the supplied selector on the supplied element N number of times and waits for delay time afters each click. Note that the evaluation of the querySelector is done all N times.

Params:

NameTypeAttributeDescription
selectFrom Element

The element to use to call querySelector(selector) on

selector string

the css selector to use

n number

How many times to click the element returned by performing selectFrom.querySelector(selector)

delayTime number
  • optional
  • default: 1000

How long is the delay

Return:

Promise<number>

How many clicks occurred

public async selectFromAndClickUntilNullWithDelay(selectFrom: Element, selector: string, options: {delay: number, max: ?number}): Promise<number> source

import {selectFromAndClickUntilNullWithDelay} from 'lib/clicks.js'

Clicks the element returned from result of calling querySelector using the supplied selector on the supplied element until the results of the evaluting the selector returns null/undefined, waiting for delay time afters each click.

Params:

NameTypeAttributeDescription
selectFrom Element

The element to use to call querySelector(selector) on

selector string

the css selector to use when performing selectFrom.querySelector(selector)

options {delay: number, max: ?number}
  • optional

options about delayTime and safety time

Return:

Promise<number>

How many clicks occurred

public selectIdAndPlay(eid: string, cntx: Document): Promise<boolean> source

import {selectIdAndPlay} from 'lib/media.js'

Calls the play method of the element returned by calling document.getElementById

Params:

NameTypeAttributeDescription
eid string

The id of the media element

cntx Document
  • optional

Optional document object to use

Return:

Promise<boolean>

Returns false if an exception occurred or true if playing was successful

public selectScrollIntoViewAndClickSelectedWhileConnected(selector: string, options: SelectScrollIntoViewClickUntilNullOptions): void source

import {selectScrollIntoViewAndClickSelectedWhileConnected} from 'lib/clicks.js'

Like selectFromAndClickUntilNullWithDelay but will stop selecting and clicking the selected element if the current reference becomes disconnected from the dom or the optional stopPredicate returns true. There is no dealy for delay you want selectScrollIntoViewAndClickWithDelayWhileSelectedConnected

Params:

NameTypeAttributeDescription
selector string

The selector to be used to select the element

options SelectScrollIntoViewClickUntilNullOptions

Return:

void

public async selectScrollIntoViewAndClickWithDelayWhileSelectedConnected(selector: string, options: SelectScrollIntoViewClickUntilNullOptions): Promise<void> source

import {selectScrollIntoViewAndClickWithDelayWhileSelectedConnected} from 'lib/clicks.js'

Like selectFromAndClickUntilNullWithDelay but will stop selecting and clicking the selected element if the current reference becomes disconnected from the dom or the optional stopPredicate returns true.

Params:

NameTypeAttributeDescription
selector string

The selector to be used to select the element

options SelectScrollIntoViewClickUntilNullOptions
  • optional

Additional configuration options

Return:

Promise<void>

public selectedNextElementSibling(selector: string, context: SomeElement | Document): SomeElement source

import {selectedNextElementSibling} from 'lib/dom.js'

Returns the next element sibling of the supplied selector IFF the selector returns a results and the next element sibling exists otherwise null/undefined

Params:

NameTypeAttributeDescription
selector string

The selector for the element who's next sibling is to be returned

context SomeElement | Document
  • optional

element to use rather than document for the querySelector call

Return:

SomeElement (nullable: true)

public selectorExists(selector: string, cntx: Document | SomeElement): boolean source

import {selectorExists} from 'lib/dom.js'

Determines if the element the supplied selector selects exists

Params:

NameTypeAttributeDescription
selector string

The querySelector to use for testing if the element it selects exists

cntx Document | SomeElement
  • optional

Optional element to use rather than the current JS context's document object

Return:

boolean

True if the element exists, false otherwise

public sendAutoFetchWorkerURLs(urls: Array<string>) source

import {sendAutoFetchWorkerURLs} from 'lib/general.js'

Sends the supplied array of URLs to the backing pywb/webrecorder auto-fetch worker if it exists

Params:

NameTypeAttributeDescription
urls Array<string>

public setIntervalP(callback: *, timeout: *): number source

import {setIntervalP} from 'lib/delays.js'

Polls the supplied function at the timeout rate only if the behavior is not paused

Params:

NameTypeAttributeDescription
callback *
timeout *

Return:

number

The id of the interval

public setTimeoutP(callback: *, timeout: *): number source

import {setTimeoutP} from 'lib/delays.js'

Like setTimeout except that the timeout respects the pause state of the behavior

Params:

NameTypeAttributeDescription
callback *
timeout *

Return:

number

The id of the timeout

public smoothScrollWindowBy(x: number, y: number) source

import {smoothScrollWindowBy} from 'lib/scrolls.js'

Scrolls the window by the supplied x and y amount smoothly

Params:

NameTypeAttributeDescription
x number

Amount to scroll in the x direction

y number

Amount to scroll in the y direction

public smoothScrollWindowDownBy(amount: number) source

import {smoothScrollWindowDownBy} from 'lib/scrolls.js'

Scrolls the window down by the supplied amount smoothly

Params:

NameTypeAttributeDescription
amount number

Amount to scroll the down by

public splitElemInnerText(elem: SomeElement, splitter: string | RegExp): Array<string> source

import {splitElemInnerText} from 'lib/dom.js'

Returns the results of splitting the supplied elements innerText using the supplied splitter

Params:

NameTypeAttributeDescription
elem SomeElement
splitter string | RegExp

Return:

Array<string> (nullable: true)

public splitElemTextContents(elem: SomeElement, splitter: string | RegExp): Array<string> source

import {splitElemTextContents} from 'lib/dom.js'

Returns the results of splitting the supplied elements textContent using the supplied splitter

Params:

NameTypeAttributeDescription
elem SomeElement
splitter string | RegExp

Return:

Array<string> (nullable: true)

public stateWithMsgNoWait(msg: string, state: *): BehaviorState source

import {stateWithMsgNoWait} from 'lib/behaviorState.js'

Returns a behavior state object with the supplied msg indicating the behavior runner should not wait for network idle. The value returned should be yield'd to the behavior runner

Params:

NameTypeAttributeDescription
msg string

A message from the behavior representing a description of the action just performed

state *
  • optional

Any additional information about the full state of the behavior

Return:

BehaviorState

public stateWithMsgWait(msg: string, state: *): BehaviorState source

import {stateWithMsgWait} from 'lib/behaviorState.js'

Returns a behavior state object with the supplied msg indicating the behavior runner should wait for network idle. The value returned should be yield'd to the behavior runner

Params:

NameTypeAttributeDescription
msg string

A message from the behavior representing a description of the action just performed

state *
  • optional

Any additional information about the full state of the behavior

Return:

BehaviorState

public async stateWithMsgWaitFromAwaitable(awaitable: Promise<boolean>, msg: *, state: *): Promise<BehaviorState> source

import {stateWithMsgWaitFromAwaitable} from 'lib/behaviorState.js'

Returns a Promise that resolves to an behavior state object with the supplied msg with the wait value being set by the value resolved Promise. The value returned should be yield'd to the behavior runner

Params:

NameTypeAttributeDescription
awaitable Promise<boolean>
msg *

A message from the behavior representing a description of the action just performed

state *
  • optional

Any additional information about the full state of the behavior

public stateWithMsgWaitFromFn(fn: function(): boolean, msg: *, state: *): BehaviorState source

import {stateWithMsgWaitFromFn} from 'lib/behaviorState.js'

Returns a behavior state object with the supplied msg with the wait value being set by the return value of the supplied function. The value returned should be yield'd to the behavior runner

Params:

NameTypeAttributeDescription
fn function(): boolean
msg *

A message from the behavior representing a description of the action just performed

state *
  • optional

Any additional information about the full state of the behavior

Return:

BehaviorState

public stringBetween(str: string, left: string, right: string): string source

import {stringBetween} from 'lib/strings.js'

Returns the string between the left and right string

Params:

NameTypeAttributeDescription
str string
left string
right string

Return:

string

public substringFromIndexOf(str: string, needle: string, opts: SubstringArgs): string source

import {substringFromIndexOf} from 'lib/strings.js'

Returns the substring from the index of the supplied needle

Params:

NameTypeAttributeDescription
str string
needle string

The substring to be searched for

opts SubstringArgs
  • optional

Return:

string

public substringFromLastIndexOf(str: string, needle: string, opts: SubstringArgs): string source

import {substringFromLastIndexOf} from 'lib/strings.js'

Returns the substring from the last index of the supplied needle

Params:

NameTypeAttributeDescription
str string
needle string

The substring to be searched for

opts SubstringArgs
  • optional

Return:

string

public titleCase(str: string): string source

import {titleCase} from 'lib/strings.js'

Attempts to convert the supplied string into title case

Params:

NameTypeAttributeDescription
str string
  • nullable: true

Return:

string (nullable: true)

public toBoolean(str: string | boolean | number): boolean source

import {toBoolean} from 'lib/strings.js'

Attempts to convert the supplied string to boolean (true, yes, on, 1)

Params:

NameTypeAttributeDescription
str string | boolean | number

Return:

boolean

public toFloat(str: string, precision: number): number source

import {toFloat} from 'lib/strings.js'

Attempts to convert the supplied string to a float

Params:

NameTypeAttributeDescription
str string
precision number
  • optional

Return:

number

public toInt(str: string, base: number): number source

import {toInt} from 'lib/strings.js'

Attempts to convert the supplied string to a integer

Params:

NameTypeAttributeDescription
str string
base number
  • optional
  • default: 10

Return:

number

public async * traverseChildrenOf(parentElement: SomeElement, fn: function(element: SomeElement, additionalArgs: *): *, additionalArgs: *): AsyncIterableIterator<*> source

import {traverseChildrenOf} from 'lib/traversals.js'

Applies a function to the children of the supplied parent element yielding the return value of the function.

When a child of the parent element does not have a next element sibling the generator ends.

Params:

NameTypeAttributeDescription
parentElement SomeElement

The parent element who's children are to be traversed

fn function(element: SomeElement, additionalArgs: *): *

The function to be applied to each child element

additionalArgs *
  • optional

Any additional arguments to be supplied to the function applied to each child element

Return:

AsyncIterableIterator<*>

public async * traverseChildrenOfCustom(opts: TraversalOpts): AsyncIterableIterator<*> source

import {traverseChildrenOfCustom} from 'lib/traversals.js'

Traverses the children of the supplied element applying the supplied function to each child and yielding the return value of the function.

If the loader option is true or shouldWait and or wait function(s) are supplied then the walk behaves as if the loader was set to true.

When operating in loader mode and a child of the parent element does not have a next element sibling, a wait for additional child elements to be added is done, if no custom wait function was supplied the wait happens for a maximum of 15 seconds. After the wait ends and if the current child element still does not have a next element sibling the generator ends.

When not operating in loader mode and the current child element does not have a next element sibling the traversal ends.

See the documentation for TraversalOpts for the customization options available.

Params:

NameTypeAttributeDescription
opts TraversalOpts

Options for configuring the traversal

Return:

AsyncIterableIterator<*>

public async * traverseChildrenOfLoaderParent(parentElement: SomeElement, fn: function(element: SomeElement, additionalArgs: *): *, additionalArgs: *): AsyncIterableIterator<*> source

import {traverseChildrenOfLoaderParent} from 'lib/traversals.js'

Applies a function to the children of the supplied parent element yielding the return value of the function.

When a child of the parent element does not have a next element sibling a wait for additional child elements to be added is done for a maximum of 15 seconds and if the current child element still does not have a next element sibling the generator ends.

Params:

NameTypeAttributeDescription
parentElement SomeElement

The parent element who's children are to be traversed

fn function(element: SomeElement, additionalArgs: *): *

The function to be applied to each child element

additionalArgs *
  • optional

Any additional arguments to be supplied to the function applied to each child element

Return:

AsyncIterableIterator<*>

public async * traverseChildrenOfLoaderParentGenFn(parentElement: SomeElement, genFn: function(): BoolOrPromiseBool, fn: function(element: SomeElement, additionalArgs: *): *, additionalArgs: *): AsyncIterableIterator<*> source

import {traverseChildrenOfLoaderParentGenFn} from 'lib/traversals.js'

Applies a function to the children of the supplied parent element yielding the return value of the function.

When a child of the parent element does not have a next element sibling, the supplied genFun is called and a wait for additional child elements to be added is done for a maximum of 15 seconds. After the wait ends and if the current child element still does not have a next element sibling the generator ends.

Params:

NameTypeAttributeDescription
parentElement SomeElement

The parent element who's children are to be traversed

genFn function(): BoolOrPromiseBool

Function used to generator more elements returning T/F indicating if a wait should be done

fn function(element: SomeElement, additionalArgs: *): *

The function to be applied to each child element

additionalArgs *
  • optional

Any additional arguments to be supplied to the function applied to each child element

Return:

AsyncIterableIterator<*>

public async * traverseChildrenOfLoaderParentRemovingPrevious(parentElement: SomeElement, fn: function(element: SomeElement, additionalArgs: *): *, additionalArgs: *): AsyncIterableIterator<*> source

import {traverseChildrenOfLoaderParentRemovingPrevious} from 'lib/traversals.js'

Applies a function to the children of the supplied parent element yielding the return value of the function and then removing the previously considered child element from the DOM.

When a child of the parent element does not have a next element sibling a wait for additional child elements to be added is done for a maximum of 15 seconds and if the current child element still does not have a next element sibling the generator ends.

Params:

NameTypeAttributeDescription
parentElement SomeElement

The parent element who's children are to be traversed

fn function(element: SomeElement, additionalArgs: *): *

The function to be applied to each child element

additionalArgs *
  • optional

Any additional arguments to be supplied to the function applied to each child element

Return:

AsyncIterableIterator<*>

public async * traverseChildrenOfRemovingPrevious(parentElement: SomeElement, fn: function(element: SomeElement, additionalArgs: *): *, additionalArgs: *): AsyncIterableIterator<*> source

import {traverseChildrenOfRemovingPrevious} from 'lib/traversals.js'

Applies a function to the children of the supplied parent element yielding the return value of the function and then removing the previously considered child element from the DOM.

When a child of the parent element does not have a next element sibling the generator ends.

Params:

NameTypeAttributeDescription
parentElement SomeElement

The parent element who's children are to be traversed

fn function(element: SomeElement, additionalArgs: *): *

The function to be applied to each child element

additionalArgs *
  • optional

Any additional arguments to be supplied to the function applied to each child element

Return:

AsyncIterableIterator<*>

public uaThinksMediaElementCanPlayAllTheWay(mediaElement: HTMLMediaElement): Promise<void> source

import {uaThinksMediaElementCanPlayAllTheWay} from 'lib/media.js'

Returns a promise that resolves once the canplaythrough or error event is fired from the supplied media element

Params:

NameTypeAttributeDescription
mediaElement HTMLMediaElement

Return:

Promise<void>

public uuidv4(): string source

import {uuidv4} from 'lib/general.js'

Creates and returns a valid uuid v4

Return:

string

public waitForAdditionalElemChildren(parentElement: SomeElement, options: WaitForOptions): Promise<WaitResult> source

import {waitForAdditionalElemChildren} from 'lib/delays.js'

Waits for the number children of the supplied parentElement to become greater than the supplied parent elements currentChildCount.

Configuration

If a max is supplied (defaults to 15 seconds) the wait for additional children to be added will not exceed the configured max value unless max = -1, which in this case, the wait is infinite.

When a guard function is supplied it is polled at value of pollRate (defaults to 1 second), if and when it returns true the wait is considered done regardless if the supplied parent element had additional children added to it.

Params:

NameTypeAttributeDescription
parentElement SomeElement

The parent element

options WaitForOptions
  • optional

Options controlling the wait

Return:

Promise<WaitResult>

public waitForAdditionalElemChildrenMO(parentElement: SomeElement, options: GuardedWaitForOptions): Promise<WaitResult> source

import {waitForAdditionalElemChildrenMO} from 'lib/delays.js'

Waits for additional child elements to be added to the supplied parentElement using a mutation observer.

Configuration

If a max is supplied (defaults to 15 seconds) the wait for additional children to be added will not exceed the configured max value unless max = -1, which in this case, the wait is infinite.

When a guard function is supplied it is polled at value of pollRate (defaults to 1 second), if and when it returns true the wait is considered done regardless if the supplied parent element had additional children added to it.

Params:

NameTypeAttributeDescription
parentElement SomeElement

The parent element

options GuardedWaitForOptions
  • optional

Options controlling the wait

Return:

Promise<WaitResult>

public async waitForAndSelectElement(fromNode: SomeElement, selector: string, options: WaitForOptions): PromiseSomeElement> source

import {waitForAndSelectElement} from 'lib/delays.js'

Calls fromNode.querySelector using the supplied selector. If the return value of the first calls is null/undefined then waits for the same call to return a truthy value and then returns the element the selector matches.

Params:

NameTypeAttributeDescription
fromNode SomeElement

The element the to be selected selector from

selector string

The querySelector to use for fromNode.querySelector call.

options WaitForOptions
  • optional
  • nullable: true

Options controlling the wait

public waitForEventTargetToFireEvent(eventTarget: EventTarget, event: string, max: number): Promise<boolean> source

import {waitForEventTargetToFireEvent} from 'lib/events.js'

Returns a promise that resolves to true once the supplied event is fired from the supplied event target. If max is supplied and the event is not fired by max the promise resolves to false.

Params:

NameTypeAttributeDescription
eventTarget EventTarget

The event target that should fire event

event string

The event that should be fired from eventTarget

max number
  • optional

Optional amount of time in milliseconds that defines a maximum time to be waited for event

Return:

Promise<boolean>

public waitForHistoryManipToChangeLocation(previousLocation: string, options: WaitForOptions): Promise<boolean> source

import {waitForHistoryManipToChangeLocation} from 'lib/browser.js'

Waits for the value of window.location.href to differ from the supplied value due to browser history manipulation. If actual navigation causes a change this function is useless. The default poll rate is 1 second and the safety timeout is 5 seconds.

Params:

NameTypeAttributeDescription
previousLocation string

The value of window.location.href prior to the pending or already occurred history manipulation of window.location

options WaitForOptions
  • optional

Optional options for controlling the checks poll rate and the safety timeout length. Supplied values for pollRate and safety in milliseconds.

Return:

Promise<boolean>

Returns false if no change was detected by the timeout length determined by options.safety otherwise true.

public waitForPredicate(predicate: function(): boolean, options: WaitForOptions): Promise<WaitResult> source

import {waitForPredicate} from 'lib/delays.js'

Returns a promise that resolves once the supplied predicate function returns a truthy value.

Params:

NameTypeAttributeDescription
predicate function(): boolean

A predicate function that returns a truthy value to indicate the wait condition was satisfied otherwise a falsy value to indicate wait condition not satisfied

options WaitForOptions
  • optional
  • nullable: true

Options controlling how the wait will happen

Return:

Promise<WaitResult>

public waitForSelector(config: WaitForSelectorOptions): Promise<WaitResult> source

import {waitForSelector} from 'lib/delays.js'

Waits for the supplied selector to exist

Params:

NameTypeAttributeDescription
config WaitForSelectorOptions

Options controlling the wait

Return:

Promise<WaitResult>

public waitUntilElementIsRemovedFromDom(elem: SomeElement, options: WaitForOptions): Promise<WaitResult> source

import {waitUntilElementIsRemovedFromDom} from 'lib/delays.js'

Waits for the supplied element to be removed from the document. The condition, element removed from document, is polled at the configured pollRate (defaults to 1 second) for a maximum of max time (defaults to 15 seconds) unless max = -1 which in this case there is no maximum.

Params:

NameTypeAttributeDescription
elem SomeElement

The element that should be removed

options WaitForOptions
  • optional

Options controlling the wait

Return:

Promise<WaitResult>

public async * walkChildrenOfCustom(opts: WalkChildrenOfCustomOpts): AsyncIterableIterator<SomeElement> source

import {walkChildrenOfCustom} from 'lib/traversals.js'

Walks the children of the supplied parent element yielding its children.

If the loader option is true or shouldWait and or wait function(s) are supplied then the walk behaves as if the loader was set to true.

When operating in loader mode and a child of the parent element does not have a next element sibling, a wait for additional child elements to be added is done, if no custom wait function was supplied the wait happens for a maximum of 15 seconds. After the wait ends and if the current child element still does not have a next element sibling the generator ends.

When not operating in loader mode and the current child element does not have a next element sibling the traversal ends.

See the documentation for WalkChildrenOfCustomOpts for the customization options available

Params:

NameTypeAttributeDescription
opts WalkChildrenOfCustomOpts

Options for configuring the walk

Return:

AsyncIterableIterator<SomeElement>

public xpathOneOf(options: XPathOnOfOpts): Array<SomeElement> source

import {xpathOneOf} from 'lib/dom.js'

Returns the results of evaluating one of the supplied xpath queries if one of the queries yields results otherwise null/undefined

Params:

NameTypeAttributeDescription
options XPathOnOfOpts

Return:

Array<SomeElement> (nullable: true)

public xpathSnapShot(xpathQuery: string, contextElement: SomeElement | Document): XPathResult source

import {xpathSnapShot} from 'lib/dom.js'

Returns the results of evaluating the supplied xpath query using an optional context contextElement, defaults to document, as XPathResult.ORDERED_NODE_SNAPSHOT_TYPE

Params:

NameTypeAttributeDescription
xpathQuery string

The xpath query to be evaluated

contextElement SomeElement | Document
  • optional

Optional element to be used as the context of the evaluation

Return:

XPathResult

The results of the xpath query evaluation

See:

public xpathSnapShotArray(xpathQuery: string, contextElement: SomeElement | Document): Array<SomeElement> source

import {xpathSnapShotArray} from 'lib/dom.js'

Provides the same functionality of the chrome console utility $x but likely less performant

Params:

NameTypeAttributeDescription
xpathQuery string

The xpath query to be evaluated

contextElement SomeElement | Document
  • optional

Optional element to be used as the context of the evaluation

Return:

Array<SomeElement>

The results of the xpath query evaluation

See: