js-draw
Version:
Draw pictures using a pen, touchscreen, or mouse! JS-draw is a drawing library for JavaScript and TypeScript.
26 lines (25 loc) • 840 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
/** Returns the first node or element with `textContent` matching `expectedText`. */
const findNodeWithText = (expectedText, parent, options = {}) => {
const { tag } = options;
if (parent.textContent === expectedText) {
const matchesTag = (() => {
// No tag check necessary?
if (!tag)
return true;
return parent instanceof Element && tag.toUpperCase() === parent.tagName;
})();
if (matchesTag) {
return parent;
}
}
for (const child of parent.childNodes) {
const results = findNodeWithText(expectedText, child, options);
if (results) {
return results;
}
}
return null;
};
exports.default = findNodeWithText;
;