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

class-glue

v1.13.1

Published

Dynamic class name generation made easy with a lightweight utility to simplify styling in React, React Native, and more. No fuss, just class names! πŸ’…βœ¨

Downloads

621

Readme

class-glue πŸ’«

class-glue is a lightweight utility library for dynamically generating class names in JavaScript applications. It provides a simple and intuitive way to conditionally apply class names based on variables or conditions, making it easier to manage styles and classNames in React, React Native, and other JavaScript projects. With class-glue, you can efficiently construct classNames without repetitive ternary expressions or complex logic, improving code readability and maintainability.

Features ✨

  • πŸ’‘ Supports dynamic class name generation based on conditions.
  • πŸ”„ Compatible with React, React Native, Vue.js, Angular, and other JavaScript frameworks.
  • πŸ›  Lightweight and easy to use, with no external dependencies.
  • πŸ” TypeScript support for type safety and IntelliSense.
  • 🧩 Modular and extensible design, allowing customization and integration with existing projects.
  • πŸš€ Optimized performance for minimal impact on application speed and efficiency.
  • πŸ“š Comprehensive documentation with usage examples and API reference.
  • πŸ›‘οΈ Robust testing suite with unit tests and integration tests for reliable codebase.
  • 🌐 Cross-platform compatibility, ensuring consistent behavior across different environments.

Usage

class-glue provides a main function and multiple utility functions, each available in different formats:

  • CommonJS: dist/[utility].js
  • ES Module: dist/esm/[utility].js
  • UMD: dist/umd/[utility].js (minified version: dist/umd/[utility].min.js)

Where [utility] can be:

  • index (main export)
  • join-strings
  • keys-to-strings
  • merge-module-strings
  • merge-styles

For direct browser usage via CDN:

<!-- Main library -->
<script src="https://unpkg.com/class-glue"></script>

<!-- Individual utilities -->
<script src="https://unpkg.com/class-glue/dist/umd/join-strings.min.js"></script>
<script src="https://unpkg.com/class-glue/dist/umd/keys-to-strings.min.js"></script>
<script src="https://unpkg.com/class-glue/dist/umd/merge-module-strings.min.js"></script>
<script src="https://unpkg.com/class-glue/dist/umd/merge-styles.min.js"></script>

When using UMD builds in a browser, the main function and utilities are available under the following names:

  • classG (main export)
  • classGJoinStrings
  • classGKeysToStrings
  • classGMergeModuleStrings
  • classGMergeStyles

Example:

const classNames = classG('foo', { bar: true, baz: false });
console.log(classNames); // "foo bar"

const joinedClasses = classGJoinStrings('foo', 'bar', 'baz');
console.log(joinedClasses); // "foo bar baz"

Tree-Shaking

class-glue is designed to be fully tree-shakeable. When using a modern bundler like webpack, Rollup, or Parcel with ES modules, only the functions you actually use will be included in your final bundle. This means you can safely import from 'class-glue' without worrying about bringing in unnecessary code:

import { joinStrings, keysToStrings } from 'class-glue';

// Only the joinStrings and keysToStrings functions will be included in your bundle

For even more granular control, you can import specific functions directly:

import joinStrings from 'class-glue/join-strings';
import keysToStrings from 'class-glue/keys-to-strings';

// This ensures only the specific functions are imported

Sponsor