GitXplorerGitXplorer
l

hyperstache

public
39 stars
0 forks
20 issues

Commits

List of commits on branch master.
Verified
bcc04436c6e981f7190080e9bc741043d83eff90

Bump @babel/traverse in /packages/babel-plugin-hyperstache (#44)

ddependabot[bot] committed a year ago
Verified
580f543a8fd4e33f837c90d7eda7d7cc59406805

Bump @babel/traverse from 7.9.5 to 7.23.2 (#43)

ddependabot[bot] committed a year ago
Verified
b433e75468d0da30951ccb205b74fddcfcb6f975

Bump debug from 4.1.1 to 4.3.4 in /packages/babel-plugin-hyperstache (#41)

ddependabot[bot] committed a year ago
Verified
35b807607a8b523d6bfeb3677ef3ce1ccee63039

Bump semver from 5.7.1 to 5.7.2 in /packages/babel-plugin-hyperstache (#40)

ddependabot[bot] committed a year ago
Verified
22f3670f9e21c859bce7d06211897e7188f1a59c

Bump word-wrap from 1.2.3 to 1.2.5 (#42)

ddependabot[bot] committed a year ago
Verified
e487e2f7d59c33470f78947f334a50ea16210730

Bump browserify-sign from 4.0.4 to 4.2.2 (#39)

ddependabot[bot] committed a year ago

README

The README file for this repository.

Hyperstache

Build Status Badge size codecov code style: prettier

Logic-less templates to template literals transformer.
Hyperstache includes a full parser and runtime.
It uses no eval and minimal regex for the best performance.
It's largely compatible with Handlebars and Mustache templates.

npm: npm install hyperstache --save
cdn: https://unpkg.com/hyperstache
module: https://unpkg.com/hyperstache?module

Why?

The goal is to make projects invested in Handlebars templates adopt a tagged templates only solution easily or add an additional layer of logic-less templates on top of any tagged template library.

hyperstache by the numbers:

🚙 2.07kB when used directly in the browser

🏍 1.74kB hyperstache/mini version (built-in helpers)

🏎 1.07kB if compiled using babel-plugin-hyperstache

Features

  • [x] variables {{escaped}}, {{{unescaped}}}
  • [x] variables dot notation {{obj.prop}}
  • [x] helpers {{loud lastname}}
  • [x] helpers literal arguments: numbers, strings, true, false, null and undefined
  • [x] basic block helpers {{#bold}}
  • [x] built-in helpers: if, unless, each, with
  • [x] helper hash arguments
  • [x] comments {{!comment}}, {{!-- comment with }} --}}
  • [x] whitespace control {{~ trimStart }}
  • [ ] helper block parameters
  • [ ] subexpressions
  • [ ] partials {{>partial}}

Usage (CodeSandbox)

import { compile } from "hyperstache";

const o = (...args) => args;
const template = compile.bind(o)`
  <p>
    Hello, my name is {{name}}. 
    I am from {{hometown}}. I have {{kids.length}} kids:
  </p>
  <ul>
    {{#each kids}}
      <li>{{name}} is {{age}}</li>
    {{/kids}}
  </ul>
`;

const data = {
  name: "Alan",
  hometown: "Somewhere, TX",
  kids: [{ name: "Jimmy", age: "12" }, { name: "Sally", age: "4" }]
};
console.log(template(data));

/** =>
[
  [
    "<p>↵    Hello, my name is ",
    ". ↵    I am from ",
    ". I have ",
    " kids:↵  </p>↵  <ul>",
    "</ul>"
  ],
  "Alan",
  "Somewhere, TX",
  2,
  [
    ["", "", ""],
    [
      ["<li>", " is ", "</li>"],
      "Jimmy",
      "12"
    ],
    [
      ["<li>", " is ", "</li>"],
      "Sally",
      "4"
    ]
  ]
]
 */

API

compile(statics, ...exprs)

registerHelper(name, fn)

escapeExpression(str)

new SafeString(htmlStr)

Real world (CodeSandbox)

import { html } from "sinuous";
import { compile } from "hyperstache";

const template = compile.bind(html)`
  <p>
    Hello, my name is {{name}}. 
    I am from {{hometown}}. I have {{kids.length}} kids:
  </p>
  <ul>
    {{#each kids}}
      <li>{{name}} is {{age}}</li>
    {{/kids}}
  </ul>
`;

const data = {
  name: "Alan",
  hometown: "Somewhere, TX",
  kids: [{ name: "Jimmy", age: "12" }, { name: "Sally", age: "4" }]
};
const dom = template(data);
document.body.append(dom);