@tusent.io/mallet
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

mallet

import { createView } from "mallet";
import { minify } from "html-minifier";
import escapeHTML from "escape-html";

const html = createView((text) => minify(text, { collapseWhitespace: true }));

html`
    <div>
        <h1>Hello World</h1>
        <p>${"Hello World"}</p>
        <p>${escapeHTML("<p>Hello World</p>")}</p>

        ${() => {
            for (let i = 0; i < 10; i++) {
                // This works!
                html`<p>${i}</p>`;

                // This also works!
                html("<p>" + i + "</p>");
            }
        }}

        ${() => {
            let text = "";
            for (let i = 0; i < 10; i++) {
                text += `<p>${i}</p>`;
            }

            // This works!
            return text;
        }}

        ${() => {
            html`<p>This will not be included.</p>`;

            // Returns are prioritized.
            return "<p>This will be included.</p>";
        }}

        ${html`
            <p>This does NOT work and will cause infinite recursion!</p>
        `}
    </div>
`;

console.log(html.toString());

Readme

Keywords

none

Package Sidebar

Install

npm i @tusent.io/mallet

Weekly Downloads

1

Version

1.2.2

License

none

Unpacked Size

3.08 kB

Total Files

4

Last publish

Collaborators

  • keve1227
  • pappkasse