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

nano-ejs

v1.2.2

Published

A simple Embedded JavaScript compiler to JavaScript

Downloads

11

Readme

Gitter NPM version Build status Test coverage Dependency Status License Downloads

nano-ejs

A very small, simple and fast EJS compiler.

Usage

> var Ejs = require('nano-ejs');
> console.log(Ejs.compile('test <?=one?>', 'one')('ola'));
test ola
> _

EJS syntax

JS expressions embedding <?=JS_EXPRESSION?>

<!DOCTYPE>
<html><head><title><?=PAGE_TITLE?></title></head><body></body></html>

JS statements embedding <? JS_STATEMENTS ?>

<!DOCTYPE>
<html><head><title><?=PAGE_TITLE?></title></head><body><?
  if (V1) {
    ?>V1<?
  } else {
    ?>V2<?
  }
?></body></html>

JS global calls embedding

The same as <?=global.function()?>, where 'global' can be redefined by EJS object option 'global_id'.

This construction useful then you pass a some object to EJS function like...

var Ejs = require('nano-ejs'),
    nc = require('nano-color');

var css_helpers = {
	hsv2hrgb: function (h,s,v) {
		return nc.rgb2hex(nc.hsv2rgb(h,s,v));
	}
};

var css_text = '\
.error   { color: <?.hsv2hrgb(0, 1, 1)?>; }\n\
.warning { color: <?.hsv2hrgb(120, 1, 1)?>; }\n\
';

var ejs_fn = Ejs.compile(css_text, 'css_helpers', { global_id: 'css_helpers' });
console.log(ejs_fn(css_helpers));

console output:

.error   { color: #FF0000; }
.warning { color: #00FF00; }

API

Ejs.compile(text[, args[, options]])

  • text String EJS text
  • args String compiled function arguments list (for new Function (args, body))
  • options Object
    • open_str String open embedded JS code symbols sequence (the default value is '<?')
    • close_str String clode embedded JS code symbols sequence (the default value is '?>')
    • global_id String identifier of global object (like global or window) (the default value is 'global')

class: Ejs

new Ejs(options)

  • options Object
    • open_str String open embedded JS code symbols sequence (the default value is '<?')
    • close_str String clode embedded JS code symbols sequence (the default value is '?>')
    • global_id String identifier of global object (like global or window) (the default value is 'global')

EJS parser context.

ejs.is_ejs(text)

return Boolean

Check the text for EJS injections. Returns true for EJS texts.

ejs.push_ejs(text)

  • text String EJS text

Parse EJS text and append to the final JS code.

ejs.push_js(text)

  • text String JS text

Parse JS with texts injections (?>test<?) and append to the final JS code.

ejs.compile(args)

  • args String compiled function arguments list (for ```new Function (args, body)``)

Returns compiled JS function of EJS source.

ejs.listing()

Returns JavaScript code translated from EJS.

> console.log(new (require('nano-ejs'))().push_ejs('text<?=5?>--').push_code().listing());
"use strict";
var $ = "";
$+='text'+(5)+'--';
> _