Skip to content

feat: add hasAttribute() and hasAttributeNS() (fixes #13) - #37

Open
Ultroncn wants to merge 1 commit into
developit:masterfrom
Ultroncn:feat/add-hasattribute-methods
Open

Ultroncn wants to merge 1 commit into
developit:masterfrom
Ultroncn:feat/add-hasattribute-methods

Conversation

@Ultroncn

Copy link
Copy Markdown

Element already had set/get/removeAttribute(NS); the has* pair was the missing piece.

  • hasAttribute(key) delegates to hasAttributeNS(null, key), matching the existing non-NS/NS pattern.
  • hasAttributeNS(ns, name) checks the attributes list with the same case-insensitive createAttributeFilter used by get/set.
  • Existence is checked directly (not via getAttributeNS), so an attribute with an empty-string value still reports true.

Verified locally (before the fix both methods were undefined):

  • missing attribute → false; after setAttribute → true; after removeAttribute → false
  • namespaced attribute found only with the matching namespace; not visible to plain hasAttribute
  • empty-string value still reports true; name matching is case-insensitive like get/set

Tests: added #hasAttribute() (3 tests) and #hasAttributeNS() (1 test) to test/undom.js; full suite 28 passing (24 existing + 4 new), eslint 0 errors. Note: the repo's own npm test uses the old esm loader, which no longer works on Node 24, so the suite was run via @babel/register instead; no test or source changes were needed for that.

Element already had set/get/removeAttribute(NS); the has* pair was the
missing piece. Follows the existing pattern: hasAttribute() delegates
to hasAttributeNS(null, ...), which checks the attributes list with the
same case-insensitive filter used by get/set. Uses an existence check
(rather than getAttributeNS) so attributes with an empty-string value
still report true.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant