Skip to content

Type Editor


Type Editor / @type-editor/dom-util / is-equivalent-position / isEquivalentPosition

Function: isEquivalentPosition()

ts
function isEquivalentPosition(node, off, targetNode, targetOff): boolean;

Defined in: is-equivalent-position.ts:39

Checks if two DOM positions are equivalent.

Scans forward and backward through DOM positions to determine if two positions refer to the same location in the document. This is useful for handling cases like a position after a text node vs. at the end of that text node.

Parameters

ParameterTypeDescription
nodeNodeThe starting DOM node
offnumberThe offset within the starting node
targetNodeNodeThe target DOM node to compare against
targetOffnumberThe offset within the target node

Returns

boolean

True if the positions are equivalent, false otherwise

Example

typescript
const textNode = document.createTextNode("Hello");
const parent = textNode.parentNode;
// Position after text node vs. at end of text node
const equivalent = isEquivalentPosition(parent, 1, textNode, 5);