@minihtm/node
v1.0.5
Published
Node.js port for MiniHTM
Readme
MiniHTM for JavaScript/TypeScript
MiniHTM (Minimal Hyper-Text Markup) is a multi-language library meant to craft minimal HTML from basic function/method calls. Unlike most "libraries", you call our functions/methods. MiniHTM acts as a library, not a framework. This specific directory is the JavaScript/TypeScript port, which is written in TypeScript, and compiled to JavaScript for usage. All versions come with full type support.
If you are looking for another supported language, see this list.
Documentation
Installation
npm install @minihtm/node # For the losers
npm i @minihtm/node # For the winnersAs the current only maintainer of MiniHTM, I cannot seem to write documentation very well. Instead, I will provide a few examples in JavaScript and ES modules, plus a few tips. Keep in mind this is done with Node.js, but if using Vite, it should work? I don't really know, I tested it all in a simple Node.js module.
Formatting control
To control formatting, MiniHTM provides that option in its configuration. You can define the config like below:
import { MiniHTM } from "@minihtm/node"
MiniHTM.config({ format: true, }) // Formatting enabled
MiniHTM.config({ format: false, }) // Formatting disabled
MiniHTM.config({}) // Formatting enabled (default + required)Keep in mind that calling MiniHTM.config({}) is required, but defaults are available. By default, format is set to true.
Small example
Console logging
import { h1, MiniHTM } from "@minihtm/node"
MiniHTM.config({})
const generated = h1("Hello, world!")
console.log(generated)File writing
import fs from "fs"
import { h1, MiniHTM } from "@minihtm/node"
MiniHTM.config({})
const generated = h1("Hello, world!")
fs.writeFileSync("generated.html", generated)Full example
Console logging
import { body, h1, headSection, html, MiniHTM } from "@minihtm/node"
MiniHTM.config({})
const generated =
html([
headSection("Example"),
body(
h1("Hello, world!"),
),
])
console.log(generated)File writing
import fs from "fs"
import { body, h1, headSection, html, MiniHTM } from "@minihtm/node"
MiniHTM.config({})
const generated =
html([
headSection("Example"),
body(
h1("Hello, world!"),
),
])
fs.writeFileSync("generated.html", generated)