2.0.0 • Published 3 years ago

domliner v2.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
3 years ago

DOMLiner

A helper to construct DOM in fewer script lines.

A sample is available here.

Installable via npm install domliner.

Use

import { element } from "../lib/domliner.js";

document.body.appendChild(
  element("div", { class: "foo" }, [
    // "this" has a special meaning, it receives a callback where the argument is the element object being created
    element(
      "div",
      { this: (l) => l.addEventListener("click", (ev) => alert("clicked")) },
      [element("img", { src: "image.png" }), element("span", null, "a text")]
    ),
  ])
);

const existingElement = document.createElement("div");
element(existingElement, { class: "bar" }, [
  element("i", null, "you can also manipulate existing element"),
]);

API

interface DOMDecorations {
  [key: string]: any;
}
declare class DOMLiner {
  document: Document;
  constructor(document: Document);
  element(
    tag: string | Element,
    decorations?: DOMDecorations,
    children?: (string | Node)[]
  ): Element;
  element(
    tag: string | Element,
    decorations?: DOMDecorations,
    textContent?: string
  ): Element;
  static element(
    tag: string | Element,
    decorations?: DOMDecorations,
    children?: (string | Node)[]
  ): Element;
  static element(
    tag: string | Element,
    decorations?: DOMDecorations,
    textContent?: string
  ): Element;
}
2.0.0

3 years ago

1.2.9

6 years ago

1.2.8

6 years ago

1.2.7

7 years ago

1.2.6

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago