UNPKG

uhtml

Version:
23 lines (18 loc) • 656 B
import { TEXT_NODE } from 'domconstants/constants'; import { TEXT_ELEMENTS } from 'domconstants/re'; import { escape } from 'html-escaper'; import CharacterData from './character-data.js'; import { parentNode, localName, ownerDocument, value } from './symbols.js'; export default class Text extends CharacterData { constructor(data = '', owner = null) { super(TEXT_NODE, '#text', data, owner); } cloneNode() { return new Text(this[value], this[ownerDocument]); } toString() { const { [parentNode]: parent, [value]: data } = this; return parent && TEXT_ELEMENTS.test(parent[localName]) ? data : escape(data); } }