Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

classix

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

classix

The fastest and tiniest utility for conditionally joining classNames.

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.1K
decreased by-4.24%
Maintainers
1
Weekly downloads
 
Created
Source

classix

The fastest and tiniest utility for conditionally joining classNames.

Installation

npm install classix

Usage

Use any amount of string expressions and classix will join them like so:

import cx from "classix";
// or
import { cx } from "classix";

cx("class1", "class2");
// => "class1 class2"

cx("class1 class2", "class3", "class4 class5");
// => "class1 class2 class3 class4 class5"

cx("class1", true && "class2");
// => "class1 class2"

cx(false && "class1", "class2");
// => "class2"

cx(true ? "class1" : "class2");
// => "class1"

cx("class1", false ? "class2" : "class3");
// => "class1 class3"

cx(...["class1", "class2", "class3"]);
// => class1 class2 class3

cx(
  "flex",
  isPrimary ? "bg-primary-100" : "bg-secondary-100",
  isLarge ? "m-4 p-4" : "m-2 py-2"
);
// => "flex bg-primary-100 m-2 p-2" *assuming isPrimary is true and isLarge is false

Comparison

classixclsxclassnames
Size281B330B454B
Ops/s*29M28M7M
StringsYesYesYes
NumbersYesYesYes
BooleansYesYesYes
ArraysYes with spreadingYesYes
ObjectsNo**YesYes

*Operations per second on an AMD Ryzen 5 5600x

**classix aims to provide the fastest and tiniest utility by omitting the object API, which it considers less ergonomic than standard function arguments:

// 🚫
cx({ class1: isPrimary && isLarge, class2: !isPrimary || !isLarge });
// ✅
cx(isPrimary && isLarge ? "class1" : "class2");

Highlights

  • Fastest & tiniest
  • Zero dependencies
  • Fully typed (with TypeScript)
  • Fully tested
  • Follows semantic versioning

Changelog

For a list of changes and releases, see the changelog.

Contributing

Found a bug, have a question or looking to improve classix? Open an issue, start a discussion or submit a PR!

Keywords

FAQs

Package last updated on 20 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc