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

frontend-si

v1.0.1

Published

Fast, lightweight and minimalist frontend framework

Downloads

3

Readme

frontend-si is fast, lightweight and minimalist frontend framework based on model-view-controller design pattern properly separating rendering from the data. Every line in template file will follow the same pattern:

renderer[@->data]

which will execute defined renderer after passing input data to it.

Hello World (with nodejs/express)

  1. Create template file hello.si with following content
html
    head
    body
        div@->message

html, head, body are built-in renderers with no data passed to them. div is a built-in renderer to which we will pass data object called message.

  1. Make sure to import frontend-si module and in your express app file

import { Si } from 'frontend-si';

and add following line to handle request at root:

app.get('/', function(req, res) {
    Si.renderHTML('./hello.si', { message : "Hello World!" }, (html) => {
        res.status(200).send(html);
    });
});
  1. This will return following rendered html file:
<html><head></head><body><div>Hello World!</div></body></html>

Renderers

There are three types of renderers which will be resolved in following order:

  1. Local renderers. Framework will try to resolve local renderers as first. Framework will look into special folder renderers in the root directory and then inside folder with renderer name and then it will look for a special file called render.js for rendering instructions.

    For example renderer with name list-1.0 will be resolved for instructions under: ./renderers/list-1.0/render.js

    Example usage in template file:

    list-1.0@->listData

  2. Remote renderers. If not resolved locally framework will check for https:// in the name of renderer to assume this is remote renderer. Framework will download the content of remote renderer and cache it inside renderer folders giving it a name based on URL. Next time it will be resolved locally. Feel free to change it locally if required if you want to pull remote file again just delete the folder with remote renderer.

    Example usage in template file:

    https://raw.githubusercontent.com/mlsc-apps/si-renderers/master/list-1.0/render.js@->listData

    :warning: WARNING: Make sure to review the renderer first before using in your templates. There is enough dishonest actors to try to make damage and in the end you are executing someone else code.:warning:

  3. Built-in renderers. If not resolved locally and remotely framework will fall back to built-in renderers. This means if you are not happy with default behaviour of built-in renderers write your own local one and this will override the built-in behaviour.

Simple remote renderers

Of course the biggest power of the framework lies in remote renderers since they can be written by experts and shared. There are couple of simplest, ready-to-go remote renderers to experiment with: https://github.com/mlsc-apps/si-renderers.

You would use them by pointing to the raw version of the file for example: https://raw.githubusercontent.com/mlsc-apps/si-renderers/master/table-1.0/render.js@->myOwnTableData

Css

You can pass css information same as any other data. Good practice would be to add css parameter inside data object for all style related information. If you pass a style to render to use make sure to add a css link in the header section of the template where the css class is defined.

Writing your own renderer

  1. Create a folder with renderer name under special folder renderers.
.
|-> renderers
    |-> myFirstRenderer
  1. Create a special file inside renderers folder called render.js
.
|-> renderers
    |-> myFirstRenderer
        |-> render.js
  1. Implement render specification in the file render.js as follows (class name does not matter)
class MyFirstRenderer {
    
    beginRender(data) {
        return '';
    }

    endRender(data) {
        return '';
    }
}

Framework will execute methods beginRender and endRender accordingly. Data required to generate html will be provided in data object.

  1. Once implemented you can use new renderer inside your templates:

    MyFirstRenderer@->data

Example project

There is a working nodejs/express example here: https://github.com/mlsc-apps/frontend-si-example