npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eryn

v0.3.2

Published

Native template engine

Downloads

4

Readme

About

eryn is a native template engine for NodeJS written in C++17.

It was built with high performance and flexibility in mind, such that it can be used for fast server-side rendering.

Getting started

You can install eryn just like any other npm package.

npm i eryn --save

Note: this package includes a declaration file for TypeScript.

If a prebuild is already available for your platform, you can jump straight to quick examples. If not, see below compiling the package.

The list of prebuilds can be found here.

Documentation

For the complete documentation, check the wiki.

Compiling the Package

You'll need to install a C/C++ compiler, as well as CMake.

The package will be compiled when you install it through npm, if a prebuild is not available. Please note that the devDependencies listed in package.json are required for building the package.

If you're missing either a compiler or CMake, an error will be shown. Make sure you have both, and try again.

For more details, see the wiki.

To manually compile the package, run:

npm run rebuild

...or directly run cmake-js:

npx cmake-js compile

...or globally install cmake-js to be able to run it anywhere:

npm i -g cmake-js

cmake-js compile

Scripts

  • install - installs the package and compiles it if no (pre)build is available
  • rebuild - compiles the package
  • prebuild - generates prebuilds the package (you need to provide your own generator)
  • check - checks if a build or prebuild is available (if not, exits with code 1)

Quick examples

Here's a basic example.

test.js

var path = require("path");
var eryn = require("eryn")();

// Pass the absolute path to the file. Relative paths might not be safe (see the wiki).
var data = eryn.render(path.join(__dirname, "test.eryn"), {
    firstName: "Tyler",
    lastName: "Bounty"
});

test.eryn

Hello, [|context.firstName|] [|context.lastName|]!

This will be rendered as:

Hello, Tyler Bounty!

Here's a more complex example, which shows a glimpse of what eryn can do.

Note: if you don't like the syntax, see below Changing the syntax.

test.js

var path = require("path");
var eryn = require("eryn")();

var data = eryn.render(path.join(__dirname, "test.eryn"), {
    firstName: "Tyler",
    lastName: "Bounty",
    greeting: "Hey there",
    numbers: [10, 20, 30, 40]
});

test.eryn

Welcome, [|context.firstName|] [|context.lastName|]!

[|? context.greeting.length > 5 |]
The greeting has more than 5 characters!
[|end|]

This is a basic loop:
[|@ num : context.numbers|]
Current number: [|num|]
[|end|]

There is also support for components!
[|% comp.eryn : {message: "Hello"} |]
This is some content for the component!
It can use the parent context: [|context.greeting|]
[|end|]

And self-closing components too!
[|% comp2.eryn : {test: "world"} /|]

comp.eryn

This is a component!

It has context which is automatically stringified: [|context|]
...and works as usual: [|context.message|]

And also some content:
[|content|]

comp2.eryn

Hello, [|context.test|]!
This is a self closing component with no content!

The render function will return a Buffer, containing:

Welcome, Tyler Bounty!


The greeting has more than 5 characters!


This is a basic loop:

Current number: 10

Current number: 20

Current number: 30

Current number: 40


There's also support for components!
This is a component!

It has context which is automatically stringified: {"message":"Hello"}
...and works as usual: Hello

And also some content:

This is some content for the component!
It can use the parent context: Hey there


And self-closing components too!
Hello, world!
This is a self closing component with no content!

You can use this buffer however you want (e.g. write it to a file, use it as-is, etc).

Changing the syntax

If you don't like the default syntax, you can change it by calling the setOptions function before rendering the file. Here's an example:

eryn.setOptions({
    templateStart: "{{",
    templateEnd: "}}",

    conditionalStart: "if ",

    loopStart: "for ",
    loopSeparator: " of ",
    
    componentStart: "component ",
    componentSeparator: " with ",
    componentSelf: " self"
});

eryn.render(...);

Note: you can call the setOptions function as many times as you want. Changes will take effect immediately.

The files can now be written using this syntax. Here's how the first file would look:

test.eryn

Welcome, {{context.firstName}} {{context.lastName}}!

{{if context.greeting.length > 5 }}
The greeting has more than 5 characters!
{{end}}

This is a basic loop:
{{for num of context.numbers}}
Current number: {{num}}
{{end}}

There is also support for components!
{{component comp.eryn with {message: "Hello"} }}
This is some content for the component!
It can use the parent context: {{context.greeting}}
{{end}}

And self-closing components too!
{{component comp2.eryn with {test: "world"} self}}

This will give the exact same result.

Note: you have to change the syntax in all files.

Also: change the syntax wisely. Otherwise, you might run into some problems (see here).

Releases

0.3.2 - October 20th, 2022

0.3.1 - October 15th, 2022

0.3.0 - June 14th, 2022

0.2.7 - March 9th, 2021

0.2.6 - December 27th, 2020

0.2.5 - September 6th, 2020

0.2.4 - August 7th, 2020

0.2.3 - August 3rd, 2020

0.2.2 - July 25th, 2020

0.2.1 - July 19th, 2020

0.2.0 - July 3rd, 2020

0.1.0 - May 2nd, 2020

Contributing

See the guidelines here.

License

eryn was created by UnexomWid. It is licensed under the MIT license.

This project uses first-party and third-party dependencies. They are listed below, along with their licenses.

Dependencies

NPM Packages (dev)

First-Party (C/C++)

Third-Party (C/C++)