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

migasc-template

v0.1.3

Published

Simple and fast templating engine.

Downloads

1

Readme

MigascTemplate

Simple and fast templating engine.

For familiarity Mustache open/close syntax is used by default.

Resources

Quickstart

1. Install

npm install migasc-template

2. Import

import MigascTemplate from 'migasc-template';

Or

const MigascTemplate = require('migasc-template');

3. Create Instance

const mt = new MigascTemplate(
  // MigascTemplate Options
  { doAllowWhitespace: true },
  // MigascTemplate Dictionary
  {
    adjective: 'mysterious',
    animal: 'Cats',
    author: 'Sir Walter Scott',
  }
);

4. Compile Templates

Given:

const template =
  '{{ animal }} are a {{ adjective }} kind of folk - {{ author }}';

Use the global dictionary.

mt.compile(template);
// -> Cats are a mysterious kind of folk - Sir Walter Scott

Use a local dictionary.

mt.compile(template, {
  adjective: 'special',
  animal: 'Kevins',
  author: 'Michael Scott',
});
// -> Kevins are a special kind of folk - Michael Scott

Use a precompiled template.

// Precompile the template
mt.setTemplate(template);

mt.template();
// -> Cats are a mysterious kind of folk - Sir Walter Scott

Default Options

| Option | Type | Default | | :------------------ | :-------- | ------------: | | dict404 | string | '' | | doAllowEscapeChar | boolean | false | | doAllowWhitespace | boolean | false | | maxChars | number | 64 | | maxWhitespace | number | 64 | | tags.close | string | }} | | tags.open | string | {{ | | validChars | string | a-zA-Z0-9_- |

Example

const mt = new MigascTemplate();

mt.compile('{{animal}} are a {{adjective}} kind of folk - {{author}}', {
  adjective: 'mysterious',
  animal: 'Cats',
  author: 'Sir Walter Scott',
});
// -> Cats are a mysterious kind of folk - Sir Walter Scott

Usage Caution

The default templating language uses Mustache open/close syntax {{variableName}} without any whitespace. MigascTemplate relies on accurate user input as it does not throw template syntax errors. Therefore, it is recommended that templates are written using Mustache/Handlebars syntax highlighting extensions or the Handlebars file extension (.hbs) for syntax feedback.

Generating lists is common usage when using EJS and Handlebars and although this is not the intent of MigascTemplate, it can be achieved via IIFEs.

// Note: This is not efficient code, it's purpose is to showcase
mt.compile('<ul>{{list}}</ul>', {
  list: new Array(20)
    .fill(0)
    .map(() => `<li>${Math.random()}</li>`)
    .join(''),
});

Benchmarks

Benchmark results are produced from the benchmark script.

| Test | Operations per Second | Relative Margin of Error | Samples | | ---------------------------------------------------- | --------------------: | -----------------------: | ------: | | [char 45] EJS.render | 56,117 | ±0.20% | 87 | | [char 45] EJS.compile | 57,228 | ±0.19% | 98 | | [char 45] EJS.compile (precompiled) | 475,339 | ±0.25% | 94 | | [char 45] Handlebars.compile | 7,717 | ±0.31% | 94 | | [char 45] Handlebars.compile (precompiled) | 224,557 | ±0.23% | 94 | | [char 45] MigascTemplate.compile | 517,494 | ±0.27% | 96 | | [char 45] MigascTemplate.template (precompiled) | 1,003,012 | ±0.22% | 94 | | [char 380] EJS.render | 37,654 | ±0.38% | 99 | | [char 380] EJS.compile | 38,099 | ±0.17% | 96 | | [char 380] EJS.compile (precompiled) | 356,497 | ±0.24% | 95 | | [char 380] Handlebars.compile | 7,097 | ±0.37% | 91 | | [char 380] Handlebars.compile (precompiled) | 231,864 | ±0.17% | 92 | | [char 380] MigascTemplate.compile | 474,601 | ±0.22% | 98 | | [char 380] MigascTemplate.template (precompiled) | 1,017,288 | ±0.29% | 96 | | [char 38022] EJS.render | 1,597 | ±0.20% | 98 | | [char 38022] EJS.compile | 1,600 | ±0.13% | 96 | | [char 38022] EJS.compile (precompiled) | 11,765 | ±0.27% | 96 | | [char 38022] Handlebars.compile | 231 | ±0.62% | 83 | | [char 38022] Handlebars.compile (precompiled) | 60,799 | ±0.96% | 94 | | [char 38022] MigascTemplate.compile | 19,123 | ±0.14% | 96 | | [char 38022] MigascTemplate.template (precompiled) | 215,903 | ±0.20% | 96 |

License

MigascTemplate is released under the MIT license.