@frank-mayer/yahp
TypeScript icon, indicating that this package has built-in type declarations

0.4.1 • Public • Published

yahp

yarn 3

Yet another HTML preprocessor (for Node)

Quickstart Guide

yarn add -D @frank-mayer/yahp
import { yahp } from "@frank-mayer/yahp";
import fs from "fs";

const input: string = fs.readFileSync("./src/index.yahp", "utf8");
const output: string = await yahp(input);
fs.writeFileSync("./dist/index.html", output);

Features

Define

Define block scoped variables.

<define var="foo" value="42">
  <!-- variable foo is available here with the value 42 -->
  <define var="foo" value=' "abc" '>
    <!-- variable foo is available here with the value "abc" -->
  </define>
  <!-- variable foo is available here with the value 42 -->
</define>
<!-- variable foo is not available anymore  -->

Eval

Run inline JavaScript Function. Return value is rendered if not undefined.

<script eval>
  const r = Math.random() * 100;
  return r.toFixed(2);
</script>

Fetch

Fetch content using http-get-request.

Parse response as JSON.

<fetch var="dog" as="json" from="this.dogDataUrl">
  <!-- ... -->
</fetch>

Response as string.

<fetch var="dog" as="text" from="this.dogNameUrl">
  <!-- ... -->
</fetch>

Response as Data URL

<fetch var="dog" as="dataURL" from="this.dogImgUrl">
  <!-- ... -->
</fetch>

For

Iterate using any iterable.

<for var="item" of="[1,2,3]">
  <!-- ... -->
</for>

If

Check if a condition is truthy or not.

Else block is not required.

<if condition="Boolean(Math.round(Math.random()))">
  <!-- truthy -->
</if>
<else>
  <!-- falsy -->
</else>

Import

Import a Module from npm or locally.

<import var="{ Octokit }" from="@octokit/rest">
  <!-- ... -->
</import>

Readme

Keywords

none

Package Sidebar

Install

npm i @frank-mayer/yahp

Weekly Downloads

1

Version

0.4.1

License

MIT

Unpacked Size

20.7 kB

Total Files

25

Last publish

Collaborators

  • frank-mayer