( root: ParentNode, attr: string, value: string, tag?: string, )
| 1 | // ponytail: queries DOM by exact attribute match without interpolating |
| 2 | // the value into a selector string — zero injection surface. |
| 3 | export function queryByAttr( |
| 4 | root: ParentNode, |
| 5 | attr: string, |
| 6 | value: string, |
| 7 | tag?: string, |
| 8 | ): Element | null { |
| 9 | const selector = tag ? `${tag}[${attr}]` : `[${attr}]`; |
| 10 | for (const el of root.querySelectorAll(selector)) { |
| 11 | if (el.getAttribute(attr) === value) return el; |
| 12 | } |
| 13 | return null; |
| 14 | } |
no test coverage detected