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

htx

v1.0.1

Published

html transformation syntax

Downloads

6

Readme

HTX

Allows coding HTML transformation via a CSS-like declarative Object

Directives (akin to sheets)

Array of objects or just one object, keys are CSS selectors

{
	h3: e=>a.length + " animals total",
  
   	li: e=>a.map((e,i)=>({
			innerHTML:	e.name.big(), 
			className: "text-danger",
			title: 	"#"+(i+1)
		})),
		
  	'li big': e=>({ 
			className: Math.random
		}) 
}

Directive Keys (akin to selectors)

"li:nth-child(2)"

CSS selectors for the rules

Directive Values (akin to rules)

A collection of key:value pairs, or a string of content, an array of new clone's content/props, or a function that returns one of those values.

Rule Functions

h3: e=> data.animals.length + " animals total", // returns a string to set content

Functions simply return one of the value types below in a late-run fashion.

Rule String

"h3.status": "Ready", // a string sets content

Strings simply define the content of any element(s) the key matches.

Rule Arrays

option: ["M", "T", "W", "R", "F"], // populate select with days

Arrays clone the matched element(s) and append one for each element of the array. If the array is an Array of Strings, the clone's content will be set by the string. If it's an Array of Objects, the rule objects procedure is applied to each clone.

Rule Objects

Rule objects define one or more transformations on the same matched selector elements. Like rule key selectors, rule object property keys point to specific properties or attributes, with a couple enhancements as well. Like rule values, the type of the rule object property value determines its effect on the match element(s).

Rule Object Keys (akin to property)

Name a property of the element, with two special additions: a + postfix will cause the value to be appended (as a string or added as a number on content/attribs), while a @ prefix will set an attribute with the property. Using both (@attribute+) appends an attribute with the value.

Rule Object Values (akin to value)

Must be a Function, Number, String, or Boolean. Objects will be assessed using .toString().

Function Rule Object Values

Defines events for keys like onclick and provides lambda for non-events. Use functions for events as properties, not as attributes. If you want to bind event attributes, use a string because functions are treated as lambda when attributes (@) are detected.

{//	key		value	
	"@title":	x=> "Element #"+index,
	onclick: function(e){ alert("Clicks work!"); },
}

Array Rule Object Values

Define arguments to pass to an element method, and are only valid in that context.

"scrollIntoView":	[true, true]

String/Number Rule Object Values

Set or append properties and attributes.

{//	key		value	
	"@title":	"Sets title attribute to this text",
	className:	"class tokens go here",
	"value+":	" appends to value property",
	"selectedIndex+": 1 // move to next option in a select
}

Boolean Rule Object Values

Controls boolean properties and attribs. In attribute mode, it will remove an attrib if false and set the attrib to "" if true. For properties, it will simple set the property to the value.

{//	key		value	
	"@disabled":	true, // sets disabled=""
	"@readonly":	false, // removes the readonly attrib
	hidden:	true // hides the element using the hidden DOM4 property
}