Skip to content

eta-dev/eta

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

eta (Ξ·)

Documentation - Chat - RunKit Demo - Playground

GitHub package.json version (master) Travis All Contributors Coveralls Donate

Summary

Eta is a lightweight and blazing fast embedded JS templating engine that works inside Node, Deno, and the browser. Created by the developers of Squirrelly, it's written in TypeScript and emphasizes phenomenal performance, configurability, and low bundle size.

🌟 Features

  • πŸ“¦ 0 dependencies
  • πŸ’‘ 2.3KB minzipped; size restricted to <3KB forever with size-limit
  • ⚑️ Written in TypeScript
  • ✨ Deno support (+ Node and browser)
  • πŸš€ Super Fast
  • πŸ”§ Configurable
    • Plugins, custom delimiters, caching
  • πŸ”¨ Powerful
    • Precompilation, partials, async
    • Layout support!
  • πŸ”₯ Reliable
    • Better quotes/comments support
      • ex. <%= someval + "string %>" %> compiles correctly, while it fails with doT or EJS
    • Great error reporting
  • ⚑️ Exports ES Modules as well as UMD
  • πŸ“ Easy template syntax

Where did Eta's name come from?

"Eta" means tiny in Esperanto. Plus, it can be used as an acronym for all sorts of cool phrases: "ECMAScript Template Awesomeness", "Embedded Templating Alternative", etc....

Additionally, Eta is a letter of the Greek alphabet (it stands for all sorts of cool things in various mathematical fields, including efficiency) and is three letters long (perfect for a file extension).

Integrations

Visual Studio Code

@shadowtime2000 created eta-vscode.

ESLint

eslint-plugin-eta was created to provide an ESLint processor so you can lint your Eta templates.

Webpack

Currently there is no official Webpack integration but @clshortfuse shared the loader he uses:

{
  loader: 'html-loader',
  options: {
    preprocessor(content, loaderContext) {
      return eta.render(content, {}, { filename: loaderContext.resourcePath });
    },
  },
}
Node-RED

To operate with Eta templates in Node-RED: @ralphwetzel/node-red-contrib-eta

image

πŸ“œ Docs

We know nobody reads through the long and boring documentation in the ReadMe anyway, so head over to the documentation website:

πŸ“ https://eta.js.org

πŸ““ Examples

Simple Template

import * as Eta from "eta";
var myTemplate = "<p>My favorite kind of cake is: <%= it.favoriteCake %></p>";

Eta.render(myTemplate, { favoriteCake: "Chocolate!" });
// Returns: '<p>My favorite kind of cake is: Chocolate!</p>'

Conditionals

<% if(it.somevalue === 1) { %>
Display this
<% } else { %>
Display this instead
<% } %>

Loops

<ul>
<% it.users.forEach(function(user){ %>
<li><%= user.name %></li>
<% }) %>
</ul>

Partials

<%~ include('mypartial') %>
<%~ includeFile('./footer') %>
<%~ include('users', {users: it.users}) %>

βœ”οΈ Tests

Tests can be run with npm test. Multiple tests check that parsing, rendering, and compiling return expected results, formatting follows guidelines, and code coverage is at the expected level.

Resources

To be added

Projects using eta

  • Docusaurus v2: open-source documentation framework that uses Eta to generate a SSR build
  • swagger-typescript-api: Open source typescript api codegenerator from Swagger. Uses Eta as codegenerator by templates
  • html-bundler-webpack-plugin: Webpack plugin make easily to bundle HTML pages from templates, source styles and scripts
  • SmartDeno: SmartDeno is an easy to setup web template using Deno & Oak
  • Add yours!

Contributors

Made with ❀ by @nebrelbug and all these wonderful contributors (emoji key):

Ben Gubler
Ben Gubler

πŸ’» πŸ’¬ πŸ“– ⚠️
Clite Tailor
Clite Tailor

πŸ€” πŸ’»
Ioan CHIRIAC
Ioan CHIRIAC

πŸ’» πŸ€”
Craig Morten
Craig Morten

πŸ’»
Rajan Tiwari
Rajan Tiwari

πŸ’‘
shadowtime2000
shadowtime2000

πŸ’» πŸ€” ⚠️
Hamza Hamidi
Hamza Hamidi

πŸ“–
Calum Knott
Calum Knott

πŸ€”
nhaef
nhaef

πŸ’»
GΓΌn
GΓΌn

πŸ’»

This project follows the all-contributors specification. Contributions of any kind are welcome!

Credits

  • Async support and file handling were added based on code from EJS, which is licensed under the Apache-2.0 license. Code was modified and refactored to some extent.
  • Syntax and some parts of compilation are heavily based off EJS, Nunjucks, and doT.