spacengine

Fast and simple embedded JavaScript template engine.

Usage no npm install needed!

<script type="module">
  import spacengine from 'https://cdn.skypack.dev/spacengine';
</script>

README

Downloads Total

spacengine

Fast and simple embedded JavaScript template engine.

Better than many template engines!

🌟 Features

  • 📦 0 dependencies
  • 🔧 ExpressJS support out-of-the-box
  • 🔨 Loops
  • 🔧 Custom delimeters
  • 📝 Easy template syntax
  • 🔨 Partials
  • 🔨 Server and browser support
  • 🚀 Pretty fast

✨ Installation

npm install spacengine

⚡️ Benchmark

Fastest is spe! | Name | Result | |-|-| | Spe | 5,047 ops/sec | | doT | 2,763 ops/sec | | Eta | 1,734 ops/sec | | Ejs | 1,375 ops/sec | | Pug/Jade | 119 ops/sec | | Handlebars | 555 ops/sec |

📘 Examples

Simple Template

const spe = require("spacengine");

const html = `<p><|= test |></p>`;
console.log(spe.render(html, {
  test: "hello!"
}));

ExpressJS Simple Template

const spe = require("spacengine");

app.engine("spe", spe.renderFile); // or app.engine("html", spe.renderFile);

// Config
app.set("async", false);

Async

const html = `<p><|= await testAsync() |></p>`;
console.log(spe.render(html, {
  testAsync: async () => "asd"
}, {
  async: true
}));

Conditionals

<| if (1 === 1) { |>
  Display this
<| } else { |>
  Display this instead
<| } |>

Loops

<| for (let i = 0; i < 10; i++>) { |>
  <a><|= i |></a>
<| } |>

Partials

<|- include("./filename") |>
<|- include("./filename", { data: "hello!" }) |>

⚙️ Options

tags

spe.render(html, {}, {
  tags: {
    open: "<%",
    close: "%>"
  }
});

prefixes

spe.render(html, {}, {
  prefixes: {
    interpolate: "_", // <|_
    raw: "~" // <|~
  }
});

async

(async () => {
  await spe.render(html, {}, {
    async: true // Converts the render function to an async function and allows the use of await.
  });
})();

noWith

let html = `<p><|= sd.test |></p>`; // If noWith was wrong, it would render without error when writed "test" not "sd.test".
spe.render(html, {
  test: "hello!"
}, {
  noWith: true
}); // <p>hello!</p>

🖍 Sytnax Support

Visual Studio Code: Spacengine Language Support