domapi.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. export function createTextNode(text: string): Text {
  2. return document.createTextNode(text);
  3. }
  4. export function createComment(text: string): Comment {
  5. return document.createComment(text);
  6. }
  7. export function insertBefore(
  8. parentNode: Node,
  9. newNode: Node,
  10. referenceNode: Node | null
  11. ): void {
  12. parentNode.insertBefore(newNode, referenceNode);
  13. }
  14. export function removeChild(node: Node, child: Node): void {
  15. node.removeChild(child);
  16. }
  17. export function appendChild(node: Node, child: Node): void {
  18. node.appendChild(child);
  19. }
  20. export function parentNode(node: Node): Node | null {
  21. return node.parentNode;
  22. }
  23. export function nextSibling(node: Node): Node | null {
  24. return node.nextSibling;
  25. }
  26. export function tagName(elm: Element): string {
  27. return elm.tagName;
  28. }
  29. export function setTextContent(node: Node, text: string | null): void {
  30. node.textContent = text;
  31. }
  32. export function getTextContent(node: Node): string | null {
  33. return node.textContent;
  34. }
  35. export function isElement(node: Node): node is Element {
  36. return node.nodeType === 1;
  37. }
  38. export function isText(node: Node): node is Text {
  39. return node.nodeType === 3;
  40. }
  41. export function isComment(node: Node): node is Comment {
  42. return node.nodeType === 8;
  43. }