The fastest and tiniest utility for conditionally joining classNames.

Overview

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

Size comparison chart

Sources: classix, clsx, classnames

Performance comparison chart

Sources: Ran benchmark on an AMD Ryzen 5 5600x.

Compared to other librairies, classix simplifies its API by forbidding object arguments, which it considers less ergonomic than string expressions:

// 🚫
cx({ "class-1": isPrimary && isLarge, "class-2": !isPrimary || !isLarge });
// ✅
cx(isPrimary && isLarge ? "class-1" : "class-2");

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!

You might also like...

The Omnibookmarks browser extension is the fastest way to open bookmarks

The Omnibookmarks browser extension is the fastest way to open bookmarks

★ Omnibookmarks The Omnibookmarks browser extension is the fastest way to open bookmarks. Just type a keyword into the address bar to quickly open or

Aug 20, 2022

The fastest way to get started with a fully-fledged web3 frontend

create-web3-frontend The fastest way to get started with a fully-fledged web3 frontend setup consisting of Next.js, wagmi and Tailwind CSS. npx create

Dec 28, 2022

The fastest growing marketing work management software.

The fastest growing marketing work management software.

Clone of coschedule.com This was our project for Unit-5 Construct week at Masai Shcool. Our target was to complete all main functionality of e-commerc

Jun 20, 2022

The fastest way ⚡️ to create sitemap in your Deno Fresh project 🍋

Fresh SEO 🍋     Quickly creating sitemaps for your Deno Fresh project. Getting Started Run the setup at the root of your project. deno run

Dec 19, 2022

Fastest JavaScript client for MySQL, with Deno FFI.

Fastest JavaScript client for MySQL, with Deno FFI.

mysql-native The fastest [1] JavaScript MySQL client. import { Connection } from "https://deno.land/x/mysql_native/mod.ts"; const conn = new Connectio

Sep 27, 2022

Fastest way to get financial data from Plaid into your Postgres database. Go from zero to live in 5 minutes without a single line of code.

Fastest way to get financial data from Plaid into your Postgres database. Go from zero to live in 5 minutes without a single line of code.

Venice Venice is a the fastest way to get financial data from Plaid into your Postgres database. Zero to production in 5 minutes without a single line

Dec 12, 2022

Password Generator - A fast, simple and powerful open-source utility tool for generating strong, unique and random passwords

A fast, simple and powerful open-source utility tool for generating strong, unique and random passwords. Password Generator is free to use as a secure password generator on any computer, phone, or tablet.

Aug 3, 2022

Utility for generating preview images of StarCraft: Brood War and Remastered maps

bwpreview Utility for generating preview images of StarCraft: Brood War and Remastered maps (.scm and .scx files). All of the actual work of parsing m

Oct 14, 2022

An utility library for Encoding and Compressing whatever you give him into a small string.

🟢 ORBIT ENCODER ⚙️ 🗜️ ORBIT-ENCODER is an utility library for Data Compression and Encoding. It can take whatever object you give him as argument an

Nov 16, 2022
Comments
  • feat: Make classix even faster/smaller

    feat: Make classix even faster/smaller

    For some reason, the current version is actually slower than clsx on my M1 Pro. These changes should save a few bytes and improve performance by a decent margin!

    |M1 Pro| |-| |classnames x 11,202,602 ops/sec ±0.15% (96 runs sampled)| |clsx x 29,227,810 ops/sec ±0.17% (98 runs sampled)| |cx x 31,156,631 ops/sec ±0.14% (100 runs sampled)|

    released 
    opened by Zertz 5
  • docs: Update classix's size in the comparison section

    docs: Update classix's size in the comparison section

    The comparison section mentioned 281B for classix's size, which was true for v1.0.5, but since v1.1.0 (thanks to https://github.com/alexnault/classix/pull/8) the minified + gzipped size is actually 277B.

    Screen Shot 2022-07-20 at 4 55 10 PM released 
    opened by charpeni 1
  • Codemod to convert from `clsx` or `classnames` to `classix`

    Codemod to convert from `clsx` or `classnames` to `classix`

    First, thank you for creating and maintaining this package! It is great.

    For devs currently utilizing clsx or classnames, do you have a suggested way to move from those to classix? Perhaps we could create a codemod to do that for devs looking to migrate. I looked through the readme and discussions and was not able to find best practices to make the switch.

    Thanks!

    opened by charkour 6
Releases(v2.1.17)
Owner
Alex Nault
Software Architect at @apprentx. Dual wielding @nodejs & @reactjs most of the time. Previously @classcraft, @ubisoft
Alex Nault
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A full-stack social media application where users can post and share their coding projects, adding friends, and joining the discussion in threaded comments on project posts.

CodeFlow Description CodeFlow is a social media application where users can post and share their coding projects with others. By logging in or signing

Chris Nohilly 4 Dec 8, 2022
A utility for creating toggleable items with JavaScript. Inspired by bootstrap's toggle utility. Implemented in vanillaJS in a functional style.

LUX TOGGLE Demo: https://jesschampion.github.io/lux-toggle/ A utility for creating toggleable dom elements with JavaScript. Inspired by bootstrap's to

Jess Champion 2 Oct 3, 2020
An animation library, built on the Web Animations API for the smallest filesize and the fastest performance

motion-signals A wrapper over Motion One, An animation library, built on the Web Animations API for the smallest filesize and the fastest performance.

Tanvesh Sarve 48 Dec 27, 2022
Postgres.js - The Fastest full featured PostgreSQL client for Node.js and Deno

?? Fastest full-featured node & deno client ?? ES6 Tagged Template Strings at the core ??‍♀️ Simple surface API ??️ Dynamic query support ?? Chat and

Rasmus Porsager 4.3k Jan 1, 2023
An efficient (and the fastest!) way to search the web privately using Brave Search Engine

Brave Search An efficient (and the fastest) way to search the web privately using Brave Search Engine. Not affiliated with Brave Search. Tested on Chr

Jishan Shaikh 7 Jun 2, 2022
Multi-chain defi crypto sniper written in typescript/javascript. Fastest method of sniping with auto-sell and rug prevention features.

CryptoSniper Community Edition Multi-chain defi crypto sniper written in typescript/javascript. Fastest method of sniping with auto-sell and rug preve

null 18 Nov 3, 2022
The world's fastest game! User gets ten dice. Then rolls and rolls as fast as they can until he gets all their dice on the same number.

tenzies-game The world's fastest game! User gets ten dice. Then rolls and rolls as fast as they can until he gets all their dice on the same number. I

Babur Shah Sayer 6 Nov 26, 2022
CryptoDappy is the fastest way to get started with Flow.

Demo application (testnet) Learning hub (start learning here) What's CryptoDappy? CryptoDappy is the fastest way to get started with blockchain develo

Benjamin Ebner 91 Aug 18, 2022