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 🙏

© 2026 – Pkg Stats / Ryan Hefner

stylefill

v1.0.1

Published

Create your own CSS properties with JavaScript

Readme

Stylefill.js

A ‘Stylefill’ is a way to create new CSS properties using JavaScript. Stylefills are similar in concept to a polyfill, but are only focussed on extending CSS in new ways, and Stylefill.js is a library to help make it much easier.

Disclaimer: This is for people who really know JavaScript. This script will not make anything magically work.

This script acts as a bridge between your CSS and your JavaScript, allowing your scripts to read your invented CSS properties and then run whatever function using the assigned selector and property value.

Use cases

  • Create new properties for CSS and use them in your CSS files.
  • Create polyfills for older browsers that do not require much JavaScript knowledge.
  • Detect CSS property support.

Setup

Add stylefill.js to your HTML page, wherever you like. Then, you merely need to initialize stylefill, passing it the new property name and the function you want to run on that property. It’s best to add this at the end of your page, just before the closing body tag.

	<script type="text/javascript">
	
		stylefill.init({
		
			'new-property-name' : function-name
		
		});
	
	</script>
		
</body>
</html>

In your own javascript, you then create a function that will handle this property. Stylefill.js will parse your CSS and return an array of rule object consisting of three variables to your function:

  • Selector - The selector used for the CSS rule.
  • Property - The invented property name you set.
  • Value - The value given for your property.

This allows you, or anyone working on this CSS, to now write your new CSS properties as if they were real.

header h1 {
	new-property-name: value; /* A brand new property! */
	font-size: 3em;
}

From there, the sky is your pie. Use the selector to match elements with whatever method you like – use jQuery if you must. Then run through your matched elements and alter them how you like, based on the values you define for your new rules.

Example

View the demo here

In demo.html you will see an example of how this works. For my example, I have created new property to handle ragged edges in typography. I have named the property rag-adjust, and initialize it with Stylefill at the bottom of the HTML.


	…

	<script src="./js/stylefill.js" type="text/javascript"></script>
	<script src="./js/typography.js" type="text/javascript"></script>
	
	<script type="text/javascript">
	
		stylefill.init({
		
			'rag-adjust' : typo.ragadjust
		
		});
	
	</script>
		
</body>
</html>

I have placed my function in the file typography.js, in which I can build my library of new CSS + JS functions. In the typo.ragadjust function, I use the first few lines to loop through the rules from my CSS find the elements that match the selector I defined there:

for (i in rules) {

	var rule = rules[i],
			eles = document.querySelectorAll(rule.selector),
			

Here, rule.selector comes straight from my CSS, as I wrote it there. Later, I use the values from my CSS (rule.value) to decide how to manipulate the elements:

if (rule.value == 'small-words' || rule.value == 'all') 
	
	// replace small words
	elehtml = elehtml.replace(smallwords, function(contents, p1, p2) {
      return p1 + p2.replace(/\s/g, '&nbsp;');
  });
			

Now, in my CSS, I can write:

p, li, h3, dd {
	max-width: 32em;
	rag-adjust: all; /* My new property */
}

…and it will be handled just as if it was a real CSS property.

Future proofing

Stylefill.js will check to see if a new property is valid before running your script. If something you’ve built eventually finds its way into the spec, the script will only work as a backup polyfill.

Issues

Version 1.2

  • Works with rules in style tags and in linked stylesheets from the same domain. This will fail with rules from a stylesheet on another domain (no cross-domain, basically). Will not read inline styles either.