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

jbcn

v1.1.0

Published

A lightweight module for working with dynamic class names.

Downloads

2

Readme

JBCN

A lightweight module for working with class names.

JBCN provides a really friendly interface for working with dynamic and complex class names.

  • Supports BEM

Installation

You can install JBCN using npm

npm install jbcn

or yarn

yarn add jbcn

Examples

Basic example

The idea is to pass a decriptive object into the JBCN function. After that it will filter those class names based on their valies. It the class name value is falsy it's going to ignore it, otherwise the class name will be included.

// Import jbcn module
const jbcn = require("jbcn");

// Create a variable for the output
const classNames = jbcn({
    tiny: true,
    expand: false,

    btn: {
        alpha: true,
        beta: true,
        gamma: false
    }
});

// Output: "tiny btn btn--alpha btn--beta"
console.log(classNames);

Using with React

You can use JBCN with React to create customizable components.

In this example we create a dynamic component which takes a couple of predefined class names as prop as well as extra class names. Any extra class name will be added if it's being passed as a prop. That makes our component way poweful.

App.jsx

import React from "react";
import "styles.css";
import jbcn from "jbcn";



// Let's define our Button component!
const Button = ({ primary, outline, underline, onClick, children, ...extraClassNames }) => {
    const classNames = jbcn({ ...extraClassNames, btn: { primary, outline, underline } });
    return (
        <button onClick={onClick} className={}>
            {children}
        </button>
    );
};



/*
  Here we create a button with passed props "primary", "outline", "center" "mb-5" and "onClick".
  
  However as you can see "center" (for centring our button) and "mb-5" (for adding `margin-bottom: 5px`).
  Those are the two extra class names that are not part of the button's defined class names.
  In this case out button is going to add them without any problem, with the help of JBCN.
*/

const App = () => <Button primary outline center mb-5 onClick={console.log}>Click me</Button>

styles.css

... 

/* Button specific styles */
.btn { ... }
.btn--primary { ... }
.btn--outline { ... }
.btn--underline { ... }


/* General styles that can be applied not only to buttons */
.mb-4 { ... }
.center { ... }

...

License

JBCN is licensed under the MIT license.