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

fastejs

v1.1.4

Published

Faster and better implementation for ejs

Downloads

8

Readme

FastEJS

Faster, better implementation for the known ejs package. It looks like ejs, so syntax highlighting will work. It's about half the the execution time of the original ejs. But it can be faster depending on the template size, and the config.

PLEASE DO NOT USE IN HIGH RISK SYSTEMS (but if you want so, why JS? Anyway, pre-escaping the input data can improve the security).

Requirements

EcmaScript 6 (The new node.js supports it without babel)

Tags

| tag | description | | --- | ----------- | | '<% ' | 'Scriptlet' tag, for control-flow, no output | | '<%' | ‘Whitespace Slurping’ Scriptlet tag, strips all whitespace before it | | '<%=' | Outputs the value into the template (HTML escaped) | | '<%-' | Outputs the unescaped value into the template | | '<%#' | Comment tag, no execution, no output | | '<%%' | Outputs a literal '<%' | | '%%>' | Outputs a literal '%>' | | ' %>' | Plain ending tag | | '%>' | ‘Whitespace Slurping’ ending tag, removes all whitespace after it |

Tuning

You can reach faster execution speed if you turn off features.

const FastEJS = require('fastejs')

delete FastEJS.tags['<% ']
delete FastEJS.tags['<%_']
delete FastEJS.tags['<%-']
delete FastEJS.tags['<%#']
delete FastEJS.tags['<%%']
delete FastEJS.tags['%%>']
delete FastEJS.tags[' %>']
delete FastEJS.tags['_%>']

FastEJS.parse(`<%= "hello world" %>`)

Can I use "include" ?

Of course, the data object can have functions too. It is up to you how you implement your logic. I suggest you to wrap this package inside a custom package you build, like a decorator.

Can I add tags?

Yes you can! FastEJS.tags is an exported object, you can modify it freely. Here it is the default:

const FastEJS = require('fastejs')
FastEJS.tags = {
    "begin": ".replace(/\\n/g, '\\uffff')", // new lines => \uffff  (\uffff is not a used character so it is perfect for this)
    "<%_": ".replace(/(\\s|\\uffff)*<%_/g, '<%')", // <%_ => <%  (removes all whitespace before it and replaces with <% for later use)
    "_%>": ".replace(/_%>(\\s|\\uffff)*/g, '%>')", // _%> => %>  (removes all whitespace after it and replaces with %> for later use)
    "<%=": ".replace(/<%=([^%]+) %>/g, '`; __out += __escapeHTML($1) + `')", // <%=SOME_JS %> escaped output
    "<%-": ".replace(/<%-([^%]+) %>/g, '`; __out += $1 + `')", //  <%-SOME_JS %> non-escaped output
    "<%#": ".replace(/<%#([^%]+) %>/g, '')", //  <%#SOME_JS %> comment
    "<% ": ".replace(/<%(\\s|\\uffff)/g, '`; ')", //  <%  script open tag
    " %>": ".replace(/(\\s|\\uffff)%>/g, '; __out +=`')", // %> script close tag
    "<%%": ".replace(/<%%/g, '<%')", // <%% => <%
    "%%>": ".replace(/%%>/g, '%>')", // %%> => %>
    "end": ".replace(/\\uffff/g, '\\n')" // \uffff => new lines
}

Can I capture variables after execution?

There is an exported settings object :

const FastEJS = require('fastejs')
FastEJS.settings = {
    returns: "__out"
}

So you can change the returns to any other javascript expression like [__out,var1,var2].
The __out variable is a builtin variable for the rendered template.