Coder Social home page Coder Social logo

tsukinoko-kun / yahp Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 288 KB

Yet another HTML preprocessor

Home Page: https://www.npmjs.com/package/@frank-mayer/yahp

License: MIT License

TypeScript 98.22% JavaScript 1.78%
html html-preprocessor yet-another fetch loops preprocessor transpiler node

yahp's Introduction

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>

yahp's People

Contributors

tsukinoko-kun avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.