Have ideas to improve npm?Join in the discussion! »

    complate-stream
    TypeScript icon, indicating that this package has built-in type declarations

    0.16.9 • Public • Published

    complate-stream

    complate's core library for rendering HTML

    package version build status Greenkeeper badge

    How It Works

    At the core of complate-stream lies generateHTML, an implementation of the signature expected by JSX (as pioneered by React). When invoked, that function returns an "element generator"; a function serving as placeholder for the HTML element to be generated:

    generateHTML("html", { lang: "en" },
            generateHTML("body", { id: "top" },
                    generateHTML("h1", null, "hello world"),
                    generateHTML("p", null, "lorem ipsum")));

    This indirection is necessary primarily to ensure proper order and nesting, as function arguments are evaluated before the surrounding invocation – otherwise the code above would emit <h1> and <p> before the <body> and <html> elements.

    Thus the example above returns a hierarchy of element generators, encapsulated by a single element generator at the root, which upon invocation writes HTML to the stream object being passed in:

    let element = generateHTML();
    element(stream, …);

    (stream is expected to support the methods #write, #writeln and #flush; see BufferedStream for a sample implementation).

    With our example, this should result in the following string being emitted:

    <html lang="en"><body id="top"><h1>hello world</h1><p>lorem ipsum</p></body></html>

    Keywords

    none

    Install

    npm i complate-stream

    DownloadsWeekly Downloads

    197

    Version

    0.16.9

    License

    Apache-2.0

    Unpacked Size

    33.2 kB

    Total Files

    20

    Last publish

    Collaborators

    • avatar