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

yust

v0.0.1

Published

A node.js template engine derived dust.

Downloads

7

Readme

Yust

ON DESIGNING, DO NOT USE IN PRODUCTION.

A node.js template engine inspired by dust but much simpler redesigned.

Usage

Node.js

$ npm install --save yust

Browser

<script scr="dist/yust.js"></script>

Syntax

Principle

  • Directive of template start with a signle bracket { and should be end with }.
  • Directive has 2 types: Variable and Command.
  • Command could contains multiple directives and text blocks.
  • Command should be ended with close directive {/} or self-ending {.../}. Except negation command {^}.
  • Negation command {^} should be used inside of other commands, could not be singly used.

Variable

{{expression | filter:arguments}}

Use double brackets to output variables. In brackets it could be most JavaScript valid expression (except | operator as a pipe). After an common expression, you could use pipe sign | to do more process with filter functions.

Example:

{{ variable }}
{{ nested.element }}
{{ array[index] }}
{{ object[key] }}

{{ ok ? 1 : 0 }}
{{ ok || 'none' }}
{{ index * (x + 3) }}

{{ variable | escapeHTML }}
{{ today | date:'Y-m-d' }}
{{ group | max }}

HTML Encoding

By default, yust will not encode HTML special characters, unless using triple brackets.

Example:

{{{content}}}

Condition

{?expression}condition 1{^expression2}condition2{^}else{/}

Use question sign ? to indicate that it is a condition command.

Negation command {^} could be used in condition command.

Example:

{? a > b }
true
{^}
false
{/}

Loop

{#list:item@index}{{index}}:{{item}}{^}none{/}

Use hash sign # to indicate that it is a loop command.

list is the list variable could be an array or an object.

item is the item entity while index (optional) is the index key of item in list.

Negation command {^} could be used in loop command when no item.

Example:

{#list:item}
<ul>
	<li>{{item}}</li>
</ul>
{^}
<p>no item in list</p>
{/}

{#list:item@index}
	{?isFirst(index)}
	<h1>{{index}}: {{item}}</h1>
	{^}
	<p>{{index}}: {{item}}</p>
	{/}
{/}

Include

{>another.tpl}

Use greater sign > to include another template content by name. The association of name to content will be handle by specific engine. Such as in node.js, it could be dealing as file name (with path). And in browser environment, the same full path file name could be used as template name by preprocessed.

(Same name strategy below)

Example:

target.tpl:

{#list:item}
{{item}}
{/}

layout.tpl:

<h1>title</h1>
{>target.tpl}
<p>other line</p>

then got as signle target.tpl:

<h1>title</h1>
{#list:item}
{{item}}
{/}
<p>other line</p>

Layout extend

Layout declaration

{@layout.tpl}

Use at sign @ to indicate current template will extend another template content by name.

This command mean to make template could be extended with fixed structure.

If using this command, put it as the first line in the template content.

Block syntax

{+block}anything{/}

Use plus sign + to define a block in extended template. To extend template should declare the parent layout like before. Or it will output just as plain text. The blocks with same name in parent layout would be replace by extended template.

Use colon in one side of block name could reuse parent block content in before(left) or after(right).

Example:

in layout parent.tpl:

<head>
{+head}
<title>{{title}}</title>
{/}
</head>
<body>
{+body}body{/}
</body>

in template:

{@parent.tpl}
{+:head}
<meta charset="utf-8" />
{/}
{+body}
<h1>Hello world</h1>
{/}

then got:

<head>
<title>{{title}}</title>
<meta charset="utf-8" />
</head>
<body>
<h1>Hello world</h1>
</body>

Development

Build

To make a distribution for browser usage:

$ npm run build

then 2 files yust.js & yust.min.js will be present in dist/ folder.