UNPKG

happy-dom-without-node

Version:

Happy DOM is a JavaScript implementation of a web browser without its graphical user interface. It includes many web standards from WHATWG DOM and HTML.

98 lines (87 loc) 2.01 kB
import Element from '../element/Element.js'; import Node from '../node/Node.js'; import * as PropertySymbol from '../../PropertySymbol.js'; import NodeTypeEnum from '../node/NodeTypeEnum.js'; /** * Attribute node interface. * * Reference: https://developer.mozilla.org/en-US/docs/Web/API/Attr. */ export default class Attr extends Node implements Attr { public [PropertySymbol.nodeType] = NodeTypeEnum.attributeNode; public [PropertySymbol.namespaceURI]: string | null = null; public [PropertySymbol.name]: string | null = null; public [PropertySymbol.value]: string | null = null; public [PropertySymbol.specified] = true; public [PropertySymbol.ownerElement]: Element | null = null; /** * Returns specified. * * @returns Specified. */ public get specified(): boolean { return this[PropertySymbol.specified]; } /** * Returns owner element. * * @returns Owner element. */ public get ownerElement(): Element | null { return this[PropertySymbol.ownerElement]; } /** * Returns value. * * @returns Value. */ public get value(): string { return this[PropertySymbol.value]; } /** * Sets value. * * @param value Value. */ public set value(value: string) { this[PropertySymbol.value] = value; } /** * Returns name. * * @returns Name. */ public get name(): string { return this[PropertySymbol.name]; } /** * Returns local name. * * @returns Local name. */ public get localName(): string { return this[PropertySymbol.name] ? this[PropertySymbol.name].split(':').reverse()[0] : null; } /** * Returns prefix. * * @returns Prefix. */ public get prefix(): string { return this[PropertySymbol.name] ? this[PropertySymbol.name].split(':')[0] : null; } /** * @override */ public get textContent(): string { return this[PropertySymbol.value]; } /** * Returns namespace URI. * * @returns Namespace URI. */ public get namespaceURI(): string | null { return this[PropertySymbol.namespaceURI]; } }