From 2db051ee51213666ddb2045a3c6b0a2e60475798 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 30 Apr 2024 17:25:55 -0300 Subject: html: Attributes.has(attribute, pattern) --- src/util/html.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/util') 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) { -- cgit 1.3.0-6-gf8a5