diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/html.js | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/util/html.js b/src/util/html.js index c5aa0569..cb4a84e8 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -150,15 +150,14 @@ export class Tag { #setAttributeFlag(attribute, value) { if (value) { - return this.attributes[attribute] = true; + this.attributes.set(attribute, true); } else { - delete this.attributes[attribute]; - return false; + this.attributes.remove(attribute); } } #getAttributeFlag(attribute) { - return !!this.attributes[attribute]; + return !!this.attributes.get(attribute); } #setAttributeString(attribute, value) { @@ -166,15 +165,15 @@ export class Tag { // distinctly from null/undefined. if (value === undefined || value === null) { - delete this.attributes[value]; + this.attributes.remove(attribute); return undefined; } else { - this.attributes[value] = String(value); + this.attributes.set(attribute, String(value)); } } #getAttributeString(attribute) { - const value = this.attributes[attribute]; + const value = this.attributes.get(attribute); if (value === undefined || value === null) { return undefined; @@ -295,6 +294,23 @@ export class Attributes { return this.#attributes; } + set(attribute, value) { + if (value === null || value === undefined) { + this.remove(attribute); + } else { + this.#attributes[attribute] = value; + } + return value; + } + + get(attribute) { + return this.#attributes[attribute]; + } + + remove(attribute) { + return delete this.#attributes[attribute]; + } + toString() { return Object.entries(this.attributes) .map(([key, val]) => { |