Gathering detailed insights and metrics for clsx
Gathering detailed insights and metrics for clsx
Gathering detailed insights and metrics for clsx
Gathering detailed insights and metrics for clsx
babel-plugin-optimize-clsx
Babel plugin to optimize the use of clsx, classnames, and all libraries with a compatible API
preact-auto-clsx
主要解决再vite和webpack中className省略clsx,可以像Vue一样去编写样式
tw-clsx
tailwindcss clsx
babel-plugin-clsx
Add `clsx()` automatically to `className` in `React` and support `Typescript`.
A tiny (239B) utility for constructing `className` strings conditionally.
npm install clsx
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.7
Supply Chain
94.9
Quality
75.8
Maintenance
100
Vulnerability
100
License
JavaScript (97.5%)
TypeScript (2.5%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
9,096 Stars
82 Commits
157 Forks
17 Watchers
1 Branches
15 Contributors
Updated on Jun 02, 2025
Minified
Minified + Gzipped
Latest Version
2.1.1
Package Id
clsx@2.1.1
Unpacked Size
8.35 kB
Size
3.84 kB
File Count
10
NPM Version
10.2.3
Node Version
20.10.0
Published on
Apr 23, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A tiny (239B) utility for constructing
className
strings conditionally.
Also serves as a faster & smaller drop-in replacement for theclassnames
module.
This module is available in three formats:
dist/clsx.mjs
dist/clsx.js
dist/clsx.min.js
$ npm install --save clsx
1import clsx from 'clsx'; 2// or 3import { clsx } from 'clsx'; 4 5// Strings (variadic) 6clsx('foo', true && 'bar', 'baz'); 7//=> 'foo bar baz' 8 9// Objects 10clsx({ foo:true, bar:false, baz:isTrue() }); 11//=> 'foo baz' 12 13// Objects (variadic) 14clsx({ foo:true }, { bar:false }, null, { '--foobar':'hello' }); 15//=> 'foo --foobar' 16 17// Arrays 18clsx(['foo', 0, false, 'bar']); 19//=> 'foo bar' 20 21// Arrays (variadic) 22clsx(['foo'], ['', 0, false, 'bar'], [['baz', [['hello'], 'there']]]); 23//=> 'foo bar baz hello there' 24 25// Kitchen sink (with nesting) 26clsx('foo', [1 && 'bar', { baz:false, bat:null }, ['hello', ['world']]], 'cya'); 27//=> 'foo bar hello world cya'
Returns: String
Type: Mixed
The clsx
function can take any number of arguments, each of which can be an Object, Array, Boolean, or String.
Important: Any falsey values are discarded!
Standalone Boolean values are discarded as well.
1clsx(true, false, '', null, undefined, 0, NaN); 2//=> ''
There are multiple "versions" of clsx
available, which allows you to bring only the functionality you need!
clsx
Size (gzip): 239 bytes
Availability: CommonJS, ES Module, UMD
The default clsx
module; see API for info.
1import { clsx } from 'clsx'; 2// or 3import clsx from 'clsx';
clsx/lite
Size (gzip): 140 bytes
Availability: CommonJS, ES Module
CAUTION: Accepts ONLY string arguments!
Ideal for applications that only use the string-builder pattern.
Any non-string arguments are ignored!
1import { clsx } from 'clsx/lite'; 2// or 3import clsx from 'clsx/lite'; 4 5// string 6clsx('hello', true && 'foo', false && 'bar'); 7// => "hello foo" 8 9// NOTE: Any non-string input(s) ignored 10clsx({ foo: true }); 11//=> ""
For snapshots of cross-browser results, check out the bench
directory~!
All versions of Node.js are supported.
All browsers that support Array.isArray
are supported (IE9+).
Note: For IE8 support and older, please install
clsx@1.0.x
and beware of #17.
Here some additional (optional) steps to enable classes autocompletion using clsx
with Tailwind CSS.
Install the "Tailwind CSS IntelliSense" Visual Studio Code extension
Add the following to your settings.json
:
1 { 2 "tailwindCSS.experimental.classRegex": [ 3 ["clsx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"] 4 ] 5 }
You may find the clsx/lite
module useful within Tailwind contexts. This is especially true if/when your application only composes classes in this pattern:
1clsx('text-base', props.active && 'text-primary', props.className);
MIT © Luke Edwards
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 7/30 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-05-26
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More