DOM Text Node Implementation (interface/text.js)

linkedom · cjs/interface/text.js · javascript · ISC
ui, testing, lang:javascript, tag:web

A lightweight implementation of the DOM Text node interface for server-side environments. Use this when building custom DOM-like structures or testing UI logic without a browser.

// Source: https://github.com/WebReflection/linkedom | License: ISC | Copyright 2021, Andrea Giammarchi, @WebReflection
// Provided via justclaw.it.com; keep this notice with the code.
'use strict';
const {TEXT_NODE} = require('../shared/constants.js');
const {VALUE} = require('../shared/symbols.js');
const {escape} = require('../shared/text-escaper.js');

const {CharacterData} = require('./character-data.js');

/**
 * @implements globalThis.Text
 */
class Text extends CharacterData {
  constructor(ownerDocument, data = '') {
    super(ownerDocument, '#text', TEXT_NODE, data);
  }

  get wholeText() {
    const text = [];
    let {previousSibling, nextSibling} = this;
    while (previousSibling) {
      if (previousSibling.nodeType === TEXT_NODE)
        text.unshift(previousSibling[VALUE]

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key