All files / src/NodeLike/CharacterDataLike AbstractCharacterDataLike.ts

5% Statements 3/60
0% Branches 0/34
0% Functions 0/13
5.17% Lines 3/58
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 1492x         2x                                                                                                                                                                                                                                                                                             2x
import AbstractNodeLike              from '../AbstractNodeLike';
import ICharacterDataLike            from './ICharacterDataLike';
import IDocumentLike                 from '../ParentNodeLike/DocumentLike/IDocumentLike';
import IElementLike                  from '../ParentNodeLike/ElementLike/IElementLike';
import INonDocumentTypeChildNodeLike from '../INonDocumentTypeChildNodeLike';
import MChildNodeLike                from '../MChildNodeLike';
import TConstructor                  from '../../TypeAliases/TConstructor';
abstract class AbstractCharacterDataLike extends MChildNodeLike(<TConstructor<AbstractNodeLike>>AbstractNodeLike) implements ICharacterDataLike {
  abstract data:                            string;
  abstract textContent:                     string;
  abstract readonly length:                 number;
  protected __ownerDocument:                IDocumentLike;
  abstract readonly ownerDocument:          IDocumentLike;
  abstract readonly parentNode:             IElementLike | null;
  abstract readonly parentElement:          IElementLike | null;
  abstract readonly previousSibling:        INonDocumentTypeChildNodeLike | null;
  abstract readonly nextSibling:            INonDocumentTypeChildNodeLike | null;
  abstract readonly previousElementSibling: IElementLike | null;
  abstract readonly nextElementSibling:     IElementLike | null;
  
  abstract readonly childNodes:             Array<INonDocumentTypeChildNodeLike>;
 
  protected __data:                         string = '';
  protected __parentNode:                   IElementLike | null = null;
  protected __previousSibling:              INonDocumentTypeChildNodeLike | null = null;
  protected __nextSibling:                  INonDocumentTypeChildNodeLike | null = null;
  
  abstract cloneNode(deep: boolean):        ICharacterDataLike;
 
  constructor(data: string, document: IDocumentLike) {
    super();
 
    this.__data = data;
    this.__ownerDocument = document;
  }
  
  appendData(data: string): string {
    this.data += data;
    return this.data;
  }
 
  deleteData(offset: number, length: number): string {
    if (offset < 0 || offset % 1 !== 0) {
      throw new Error('The offset argument was invalid.');
    }
 
    if (length < 0 || length % 1 !== 0) {
      throw new Error('The length argument was invalid.');
    } else if (length === 0) {
      return this.data;
    }
 
    const before = this.data.slice(0, offset);
    const after = this.data.slice(offset + length, this.length);
    this.data = before + after;
    return this.data;
  }
 
  insertData(offset: number, data: string): string {
      if (offset < 0 || offset % 1 !== 0) {
        throw new Error('The offset argument was invalid.');
      }
 
      if (data.length === 0) {
        return this.data;
      }
 
      const before = this.data.slice(0, offset);
      const after = this.data.slice(offset, this.length);
      this.data = before + data + after;
      return this.data;
  }
  
  replaceData(offset: number, length: number, data: string): string {
      if (offset < 0 || offset % 1 !== 0) {
        throw new Error('The offset argument was invalid.');
      }
      
      if (length < 0 || length % 1 !== 0) {
        throw new Error('The length argument was invalid.');
      }
 
      if (data.length === 0) {
        return this.data;
      }
 
      const before = this.data.slice(0, offset);
      const after = this.data.slice(offset + length, this.length);
      this.data = before + data + after;
      return this.data;
  }
 
  substringData(offset: number, length: number) {
      if (offset < 0 || offset % 1 !== 0) {
        throw new Error('The offset argument was invalid.');
      }
 
      if (length < 0 || length % 1 !== 0) {
        throw new Error('The length argument was invalid.');
      }
 
      return this.data.slice(offset, length);
  }
 
  appendChild(node: INonDocumentTypeChildNodeLike): INonDocumentTypeChildNodeLike {
    /* Get rid of VS not-used error. */node;
    throw new Error('Text nodes do not support appending children.');
  }
 
  removeChild(node: INonDocumentTypeChildNodeLike): INonDocumentTypeChildNodeLike {
    /* Get rid of VS not-used error. */node;
    throw new Error('Text nodes do not support removing children.');
  }
 
  insertBefore(
    newNode: INonDocumentTypeChildNodeLike,
    referenceNode: INonDocumentTypeChildNodeLike): INonDocumentTypeChildNodeLike
  {
    /* Get rid of VS not-used error. */newNode;referenceNode;
    throw new Error('Character data nodes cannot have child nodes, and as ' +
                    'such insertions cannot be performed on them.');
  }
 
  replaceChild(
    oldNode: INonDocumentTypeChildNodeLike,
    newNode: INonDocumentTypeChildNodeLike): INonDocumentTypeChildNodeLike
  {
    /* Get rid of VS not-used error. */oldNode;newNode;
    throw new Error('Character data nodes cannot have child nodes, and as ' +
                    'such replacements cannot be performed on a child of ' +
                    'theirs.');
  }
  
  normalize(): void {
    return;
  }
 
  __setParentNode(parent: IElementLike): IElementLike {
    super.__setParentNode(parent);
    return parent;
  }
 
  __setPreviousSibling(previousSibling: INonDocumentTypeChildNodeLike): INonDocumentTypeChildNodeLike {
    super.__setPreviousSibling(previousSibling);
    return previousSibling;
  }
}
 
export default AbstractCharacterDataLike;