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

@dcmox/stencil-js

v1.0.8

Published

Just another template engine written in TypeScript. Mustache compatible!

Downloads

29

Readme

stencil-js

stencil-js is a templating engine that is fast with low overhead. It is compatible with Mustache templates and includes a few core features that differ from it.

Features

  • Create or use filters on your template variables for simple string manipulation such as:

    • {{paragraph|excerpt}} - (excerpt) Trims down the paragraph to a max of 255 characters and adds ...
    • {{urls|linkify}} - (linkify) Converts URLs in plain text into clickable HTML links
    • {{name|ucwords}} - (ucwords) Uppercases the first letter of any word (delimited by a space).
    • {{key|lower}} - (lower) Converts key to lowercase.
    • {{highlight|upper}} - (upper) Converts the highlight variable to uppercase.
    • {{html|stripTags}} - (stripTags) Removes all HTML from the variable
  • Automatic conversion of special characters to HTML entities to help prevent security vulnerabilities

  • Fast and under 200 lines of code for the core module

  • Supports partial templates using {{> partialTemplate}} syntax

  • Should be fully compatible with Mustache templates. If you know Mustache, you already know 90% of stencil-js.

  • Support for helpers with parameters. Great for conditional logic.

  • Built from scratch with no dependencies

  • We encourage contribution and suggestions to help improve the templating engine!

Sample Usage

TypeScript

const Stencil = require('@dcmox/stencil-js')
const options = {
	newLineToBr: true,
}
const template = `Hello world, my name is {{name}}!`
const view = {
	firstName: 'John',
	lastName: 'Doe',
	name: function() {
		return `${this.firstName} ${this.lastName}`
	},
}
console.time('Render time')
const rendered = Stencil.render(template, view)
console.timeEnd('Render time')
console.log(rendered) // outputs Hello world, my name is John Doe!
const options = {
	newLineToBr: true,
}
const template = `<a href="/home" {{{isActive home}}}>Home</a>`
const view = {
	firstName: 'John',
	lastName: 'Doe',
	path: 'home',
	isActive: function(path: string) {
		return path === this.path ? 'class="active"' : ''
	},
}
console.time('Render time')
const rendered = Stencil.render(template, view)
console.timeEnd('Render time')
console.log(rendered) // outputs class="active"

HTML

<script>
	var exports = {}
</script>
<script src="stencil-browser.js"></script>
<script>
	const template = `Hello world, my name is {{name}}!`
	const view = {
		firstName: 'John',
		lastName: 'Doe',
		name: function() {
			return `${this.firstName} ${this.lastName}`
		},
	}
	document.getElementById('template').innerHTML = Stencil.render(
		template,
		view,
	)
</script>
<div id="template"></div>

See tests/usage.ts or tests/stencil.test.ts for an example on how to use stencil-js with NodeJS and Typescript.

Available Scripts

In the project directory, you can run:

npm run build

Builds stencil.ts and tests/usage.ts into JS files for usage. usage.ts is a demo of the script being used in Typescript.

npm run test-usage

Runs the sample usage.js file which should output a log in your console.

Learn More

You can learn more about the developer here.