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

class-parser

v1.0.0

Published

An easy way to styling inline dynamically

Readme

Class Parser

An easy way to styling inline dynamically.

Installation

Installing class-parser with npm.

npm install class-parser

Usage

Getting the module

First of all, you need to import the parse function from the module.

// Using require
var parse = require("class-parser");

// or using import
import parse from "class-parser";

Parsing variables

Use the parse function to convert variables into a single string.

Any of the basic variables are allowed to be used such as booleans, strings, numbers, objects and arrays so you can combine them as you need it.

Let's see an example:

var myStyle = {
    visible: true,
    active: false
};

var myClass = parse("button", myStyle);
// expected string: "button visible"

There's no limit in the arguments the function can receive

Strings and Numbers

Both strings and numbers don't need to be wrapped neither in an object nor an array, but you can do it if needed.

Les't see some examples:

parse("This", "will", "work");
// expected string: "This will work"

parse(["This", "will"], { text1: "work", text2: "too" });
// expected string: "This will work too"

parse({ one: 1, two: 2, zero: 0 }, [-1, 3, 4]);
// expected string: "1 2 3 4"

Notice: The key names on the object are ignored and only uses de value when parsing if the value is a string or a number, otherwise the key will be used.

Booleans

The proper way to use booleans is wrapped inside an object instead as a single parameter.

So, this won't work:

// wrong way
var active = true;
var myClass = parse("button", active);

The correct way is:

// correct way
var active = true;
var myClass = parse("button", { active });

Arrays

There's two kinds of arrays, the anonymous, which is created out of a variable or an object (as we saw before) and the named, the last ones has a different behaviour.

Even if the array has multiples values, it just create a single string when it's parsed, but, the key is if one or more of those values are falsy the string will be empty.

Also, it must be wrapped in an object.

Let's see how it works:

var will = [true, true, true];
var fail = [true, false];
var work = [1, 2, 3];

var myClass = parse("This", { will, fail, work });
// expected string: "This will work"

Falsy: A value considered "false", for example: 0, null, "" or NaN. More info here.

It works with mixed arrays to:

// This is an example of a form with a button
// which is enabled when all the fields are filled.
var name = "John";
var lastName = "Doe";
var age = 24;

var btnClass = parse("button", { active: [name, lastName, age] });
// expected string: "button active"

A React.js example

This is a simple example of how to use the class-parser in a react component:

import parse from "class-parser";

const Button = ({ active }) => {
    return (
        <button className={ parse("button", { active }) }>
            Click me!
        </button>
    );
};

License

MIT