Socket
Socket
Sign inDemoInstall

jet-engine

Package Overview
Dependencies
331
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jet-engine

Jet engine


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

#jet-engine

More complete documentation to follow.

jet-engine is a template engine with syntax very similar to dustjs-linked in. It was written because we were trying to produce the smallest bundle possible for a recent project. I liked dustjs syntax, compared to other template engines, and thought this would be a fun side project. I'm very pleased with the result. Each function is written in a separate source file, and it is easy to add additional features. In the few cases in which I wanted templates to behave differently than dustjs, I implemented my preferred approach. We also had no requirement for asynchronous template handing, so I left that out.

Usage

If you know dustjs template syntax, you know jet-engine syntax. Here are some some examples.

import { render } from 'jet-engine';

const out = render('Hello, {name}!', { name: 'World' });    // Hello, World!

Nearly all of the familiar keywords are implemented:

{value}
{#section}
{?test}
{!test}         // my preferred negation test
{* comment *}   // my preferred comment
{@eq ...}       // and many other helpers
{>subroutine}   // I prefer this terminology
{<definition}   // ditto
{+block}
{~gt}           // and several other other special characters

Subroutines

Register a subroutine like this

import { render, register } from 'jet-engine';

register('greet', 'Hello, {name}!')
const out = render('{>greet}', { name: 'Jim' });
const out = render('{>greet name='Jim'}'); // or provide data as an attribute

Context

The data context is exactly as you would expect form a sophisticated engine. An initial context is set when the render() function is first invoked. Addition conexts are pushed and popped from context stack by the following commands:

{#names}  // value of "names" is pushed onto the context stack
{>subroutine name="Jim"} // { name: "Jim" } is pushed onto the context stack
{@eq key="size" value=17} // { key: "size", value: 17 } is pushed onto the stack (explained in Helpers section below)

Data references are resolved from the top of the context stack downward, with the following exceptions:

{.} refers to the entire context currently on the top of the stack
{.value} references "value" only if it exists on the top of the stack. Searching will not continue downwards in the stack.

If a reference cannot be found on the context stack, an empty string '' is returned.

provide examples

Document each keyword funciton

Keywords

FAQs

Last updated on 17 Apr 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc