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

ij2tpl

v0.1.3

Published

A Mustache-like Template Engine written in TypeScript(<= 4kB after uglifying).

Downloads

4

Readme

IJ2TPL.js

A Mustache-like Template Engine written in TypeScript(<= 4kB after uglifying).

Faster than Mustache.js(at least not slower)!

English | 中文

Supported

  • ES5(>=IE8)

Usage

// Import ij2tpl.js, for example nodejs:
const IJ2TPL = require('./dist/ij2tpl.min');

// Parse a template source
let renderer = IJ2TPL.parse('Hello, {name}!');

// Then let's render it!
renderer.render({name: 'IJ2TPL'}); // -> "Hello, IJ2TPL!"

Comments

{- A comment }
{-- A comment too }
{-- Yet another comment --}

{-- Error! }--}

If Section

{?valid}
	Only render when it is valid
{/valid}

Not Section

{!valid}
	Only render when it is invalid
{/valid}

Raw Formatter

{-- name = '<b>urain39</b>' --}
Hello {#name}

If-Else Section

{?valid}
	Only render when it is valid
{*valid}
	Oops, something's wrong?
{/valid}

Function type(Lambda)

function toHumanReadableSize(size) {
	var i = 0,
	dataUnits = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB', 'BiB', 'NiB', 'DiB'];

	while (size >= 1024)
		i++, size /= 1024;

	return String(size.toFixed(2)) + dataUnits[i];
}

/* You can think it is a property getter, same as other formatters */
function humanReadableSize(context) {
	var downloadedSize = context.resolve(['downloadedSize', null, null]);
	return toHumanReadableSize(downloadedSize);
}
Downloaded {humanReadableSize}

Line Begin Mark(Dedent)

{-- Our `tokenize` implementation allows you to use a
	empty comment at the end of indentation to indicate
	you want to strip indentation for a signe-line.

	See https://github.com/urain39/ij2tpl.js/issues/70
	--}

{-- For example: --}
Hello World
	{-}Hello Wolrd

{-- The above two hello-world are same. }

Custom Prefix and Suffix(aka Delimiter or Tags)

IJ2TPL.parse('Hello <%name%>', '<%', '%>');

Partial Template(v0.1.0 added)

{? xxxEnabled }
	{@partial_template}
{/ xxxEnabled }
let renderer = IJ2TPL.parse(source),
	renderer2 = IJ2TPL.parse(source2),
	partialMap = {
		partial_template: renderer2
	};

renderer.render(data, partialMap);

Filters and Actions(v0.1.0 added)

Hello { name | no-f-word }
IJ2TPL.setFilterMap({
	'no-f-word': function(word) {
		return word.replace('fuck', '****');
	}
});

Actions same as filters, but it has no name to look up!

{- Simply -}
{| report}

Differences between Function type and Actions

The Function type will always cache look up results, but Action not.

Complex Section(Nested)

{?valid}
	{-}Your Scores:
	{?scores}
		{-}Score: {.}
	{/scores}
{/valid}

About Debugging

Sorry, i don't consider on it. I have removed location of a token to improve tokenizing speed. But you can also guess what's wrong from the error messages, it will tell you the section name and type.

Not Implemented Yet:

  • ~~Function type(Supported on v0.0.2-dev)~~
  • ~~Sub-template(aka Partial Section)~~
  • ~~Format Pipe(aka Filter)~~

About Readme

Typo wrong / Can't understand? Please help me to improve it! Just open a new issue or PR to my project, i will reply you as possible as i can :)

Last Update: 2020-06-27