diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-04-30 17:25:55 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-05-01 20:22:37 -0300 |
commit | 2db051ee51213666ddb2045a3c6b0a2e60475798 (patch) | |
tree | e9eddd12b0f81a41bc64d858067ec3c52001a7dd /src | |
parent | f6a103f52abc42eaeba29b7bbfcd9c622f043154 (diff) |
html: Attributes.has(attribute, pattern)
Diffstat (limited to 'src')
-rw-r--r-- | src/util/html.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/util/html.js b/src/util/html.js index 0f190e25..9e07f9ba 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -1101,8 +1101,17 @@ export class Attributes { return this.#attributes[attribute]; } - has(attribute) { - return attribute in this.#attributes; + has(attribute, pattern) { + if (typeof pattern === 'undefined') { + return attribute in this.#attributes; + } else if (this.has(attribute)) { + const value = this.get(attribute); + if (Array.isArray(value)) { + return value.includes(pattern); + } else { + return value === pattern; + } + } } remove(attribute) { |