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 🙏

© 2025 – Pkg Stats / Ryan Hefner

pfft-jss

v1.0.1

Published

pfft-jss is a tiny utility library to help you style your components.

Downloads

5

Readme

pfft-jss

pfft-jss is a tiny utility library for helping you style your components. All the examples below use React, but pfft-jss is not bound to React, and is really all about class strings.

How to use (or not use):

  1. Use regular css with or without a preprocessor to create your style primatives. Use a library like basscss, et. al. that provides these if you like.

  2. Design with your primatives first. Ship it! Avoid premature abstractions. You should always know more tomorrow than today, thus the adage: "premature optimization is the root of all evil".

  3. When you've used the same set of primatives enough together: collect them into a single string variable and use that instead.


const myNewBestStyle = "p1 mb2 fg-primary bg-too-hot-take-it-off";

const OtherComponent = () => (
  <div className={myNewBestStyle}>
    {oh_noes_camel_case}
  </div>
)
  1. Avoid abstracting your components simply to encapsulate styles. Prefer instead to bundle your classes as shown above and export them--at least until your styles are so battle-hardened that you can formailze them with explicit classes.

  2. If you'd like to:

npm install pfft-jss

API

So what is pfft-jss? It's a tiny library that contains a single utility function to help you on your journey:

function css(...any[]): string

It takes any number of arguments, and returns single string of combined classes from the valid string arguments. The classes are deduped while preserving order, and trimmed of extra whitespace.

Here's some examples of how you could use it:


const YourComponent = ({ className, conditionalProp, ...yourProps }) =>
  <DoesntMatter
    className={css('local-class-names here', conditionalProp && 'conditionalStyle', className)}
  />;

// Please don't really use it like below. This is to demonstrate it's behavior.
const staticStyle = css(' you-smell     like you-smell this-code', false, "      ", { foo: "bar" }, null, 'you-smell');
staticStyle === 'like this-code you-smell';

The utility is super simple. So simple in fact that it's included below. Install the package, or copy and paste the code:


export default function css(...args) {
  const classSet = Object.create(null);
  // iterate over arguments in reverse so we can use the order of insertion preservation
  // properties of the classSet object for deduping classes
  let i = args.length;
  while (i--) {
    const arg = args[i];
    // skip non-string arguments
    if (typeof arg !== "string") continue;
    // split arg into individual classes and eliminate empty strings
    const classes = arg.split(/\s/).filter(Boolean);
    // ignore whitespace-only string args
    if (!classes.length) continue;
    // add each class to the set (eliminates duplicate classes while preserving order)
    let c = classes.length;
    while (c--) classSet[classes[c]] = true;
  }
  // combine classes into single string (reversing keys to keep correct order of application of unique classes)
  return Object.keys(classSet).reverse().join(' ');
}

How to Contribute

Open an issue in github, or a pull request. Reach out and poke someone. Let's make it happen. Bloat not welcome.

License

ISC