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

@bajjy/es6templates

v0.0.6

Published

Use simple HTML files and ES6 template strings to build web applications without a ton of dependecies, special files, or preloaders. Power of native browser templating.

Downloads

12

Readme

Constantine Dobrovolskiy bajjy.com

This library was created to show all the power of ES6, which is supported by all modern browsers. No frames are no longer needed. Under 50 lines of code and you get rid of vendorlock, you will not have to pull billions of dependencies, use special type files or preloaders.

Article on my website: es6 templates

nodejs

import templates and run templates

import { Templates } from './modules/class.es6templates';
var tpl = new Templates('/from/html', '/to', '/from/html/includes') //includes is folder with header, footer or other modules
tpl.first()

Use in js

Just add a script to your projecs as a ES6 module

<script src="es6templates.js" type="module"></script>

Dont forget to include it somewhere in your code

import * as templates from '../es6templates.js';

Or You can use any bundler you like. babel, webpack or if you are not a hipster, but true developer — rollup or multihawker.

Using

This lib using basic ES6 templating: var tpl = `this is string ${a + b}`

Simple properties

Which means you can use very same code right in your html file:

<!-- tpl-article.html -->
<article>
    <h2>${newData.title}</h2>
</article>

Now get the file somewhere in your code, library usin fetch method to get file, so templates.include method return Promise:

var myArticle = { title: 'Hellow World!' };
var main = document.querySelector('body');

templates.include('./tpl-article.html', myArticle)
    .then(tpl => main.innerHTML += tpl);

Expressions

Now you can youse any expression inline:

<div class="price">${newData.price * newData.coeff}.00</div>

Functions

But whole power of this approach are in the functions. Here is simple repeat func:

<div>
    ${(() => {
        var list = '';
        newData.map(item => {
            list += `
                <a href="${item.link}" class="title" title="${item.title}">${item.title}</a>
            `
        })
        return list
    })()}
</div>

Client side Middlewares

Now middlewares can be used on client side

import * as templates from 'es6templates.js';

var repl = (te) => {
  te = te.replace('class-to-remove', 'rp');
  return te
};
var test = templates.include('/tpl/list.html', list, repl);

test.then(html => console.log(html))

Server side Middlewares

You can use any middleware fuctions to do even more with templates:

import {default as markdown} from 'markdown-it';

//Define new middleware
templates.middlewares['markdown'] = function(raw) {
    return markdown.render(raw);
};

//fetching tpl
templates.include('./tpl-markdown.html', dataset, 'markdown').then(tpl => {
    console.log(tpl);
    //will output:
    // <p><a href="http://bajjy.com/assets/img/dwnld/package1.zip">download mockup</a></p>
    // <h2><a id="Foreword_1"></a>Foreword</h2>
    // <p>For many years I have been studying and using Photoshop features and tools.</p>
});
<!-- tpl-markdown.html -->
[download mockup](http://bajjy.com/assets/img/dwnld/package1.zip)
## Foreword
For many years I have been studying and using Photoshop features and tools. 

Examples

Look in ./test folder. Thre must be a server for this folder. You can use tiny node server from same folder.

Using of node server

node node-server.js [port]