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

layout-builder

v0.0.3

Published

A javascript library for web app frontend templating

Downloads

4

Readme

hcj.js

A javascript library for web app frontend templating

What's it like

  1. Define Components.
  2. ???
  3. Profit!

Everything is a Component. If you have a thing, chances are it's a Component. And if it's not, it's probably a function that takes Components and returns you a Component.

Components are self-sufficient. They may run arbitrary javascript code each time they are instanced, signing up whatever listeners they want and appending anything anywhere. When a component instance is destroyed, it must leave the page just as it found it. As a component author, it is your responsibility to overcome the urge to remove your neighboring DOM elements from the page.

How it works

A Component is a function that takes an element and appends something to it. When called, a component returns an object with two properties: $el, a JQuery object that is the root of the new component instance, and destroy, a function to completely remove the instance from the DOM.

Besides appending an element to its argument, what can a Component do? Absolutely anything. It can sign up event handlers anywhere on the page, set up periodic server calls, you name it. The destroy function must unhook any of that jazz, as it removes the component instance.

Primitive components are functions for creating DOM nodes, that is tags and text nodes. This library gives you the components a, div, and img, for those elements. It also gives you a function textNode which takes a string and returns a componet. E.g. textNode('Hello World') is a component.

Simple Example

Appends a div containing 'Hello World' to the body, and removes it after 5 seconds.

var $body = $('body');

var hello = append(div, textNode('Hello World'));
var instance = hello($body);

setTimeout(function () {
  instance.destroy();
}, 5000);

How it works, Continued

The meat of the library is (read: will be) found in all of the functions that transform Components. You build complex components by composing functions around simple components. For instance, the append function used in the example above takes two components and returns a new component.

Simple example from recent website

var fixedHeader = function (config, header, body) {
  var headerHeight = config.height + 2 * config.padding + 1;
	return concat([
		all([
			and(function (i) {
				i.$el.css('width', px(window.innerWidth - 2 * config.padding));
			}),
			$css('height', px(config.height)),
			$css('position', 'fixed'),
			$css('top', '0'),
			$css('z-index', '1000'),
			$css('background-color', 'white'),
		])(header(config)),
		$css('margin-top', px(headerHeight))(body),
	]);
};

This fixedHeader function takes three arguments. Its job is to insert the header component into a position:fixed div of a configured height, at the top of the screen; and to insert the page body into a div with top padding to compensate for the fixed header.

Reading from top to bottom: the function expects config to have two properties, and they are both used to compute the height of the header.

The concat function takes an array of components. When instanced, it instances all of the components you passed in, appending them all to its own root element one after another.

The all function takes an array of functions from components to components, and applies them all to a component.

TODO: finish the readme