All files / src/NodeLike/CharacterDataLike/TextLike TextLike.ts

6.82% Statements 3/44
0% Branches 0/12
0% Functions 0/17
6.82% Lines 3/44
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 1202x       2x                                                                                                                                                                                                                                     2x
import AbstractTextLike              from './AbstractTextLike';
import IDocumentLike                 from '../../ParentNodeLike/DocumentLike/IDocumentLike';
import IElementLike                  from '../../ParentNodeLike/ElementLike/IElementLike';
import INonDocumentTypeChildNodeLike from '../../INonDocumentTypeChildNodeLike';
import isIElementLike                from '../../../TypeGuards/isIElementLike';
class TextLike extends AbstractTextLike {
  get data(): string {
    return this.__data;
  }
 
  set data(data: string) {
    this.__data = data;
  }
 
  get textContent(): string {
    return this.__data;
  }
 
  set textContent(textContent: string) {
    this.__data = textContent;
  }
 
  get nodeValue(): string {
    return this.__data;
  }
 
  set nodeValue(value: string) {
    this.__data = value;
  }
 
  get length(): number {
    return this.__data.length;
  }
 
  get ownerDocument(): IDocumentLike {
    return this.__ownerDocument;
  }
 
  get parentElement(): IElementLike | null {
    return this.__parentNode;
  }
 
  get parentNode(): IElementLike | null {
    return this.__parentNode;
  }
 
  get previousSibling(): INonDocumentTypeChildNodeLike | null {
    return this.__previousSibling;
  }
 
  get nextSibling(): INonDocumentTypeChildNodeLike | null {
    return this.__nextSibling;
  }
 
  get previousElementSibling(): IElementLike | null {
    /* An element with no parent cannot have siblings. */
    if (!this.__parentNode) {
      return null;
    }
 
    let node = this.__previousSibling;
    let counter = 0;
    const length = this.__parentNode.childNodes.length;
    while (node) {
      if (counter > length) {
        throw new Error('Possible infinite loop detected. A previousSibling ' +
                        'property may be misset.');
      }
 
      if (isIElementLike(node)) {
        return node;
      }
      
      node = <INonDocumentTypeChildNodeLike>node.previousSibling;
      counter += 1;
    }
 
    return null;
  }
  
  get nextElementSibling(): IElementLike | null {
    /* An element with no parent cannot have siblings. */
    if (!this.__parentNode) {
      return null;
    }
 
    let node = this.nextSibling;
    let counter = 0;
    const length = this.__parentNode.childNodes.length;
    while (node) {
      if (counter > length) {
        throw new Error('Possible infinite loop detected. A nextSibling ' +
                        'property may be misset.');
      }
 
      if (isIElementLike(node)) {
        return node;
      }
      
      node = node.nextSibling;
      counter += 1;
    }
 
    return null;
  }
 
  get childNodes(): Array<any> {
    return [];
  }
  
  get firstChild(): null {
    return null;
  }
 
  get lastChild(): null {
    return null;
  }
}
 
export default TextLike;