Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

clsx

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Issues
File Explorer

Advanced tools

clsx

A tiny (228B) utility for constructing className strings conditionally.

    1.2.1latest

Version published
Maintainers
1
Weekly downloads
8,433,235
decreased by-13.93%

Weekly downloads

Changelog

Source

v1.2.1

Patches

  • Ensure CommonJS and UMD entrypoints have the named clsx export too

Chores

  • Build CJS & UMD files manually (#50): 3712966, 2114f5b

Full Changelog: https://github.com/lukeed/clsx/compare/v1.2.0...v1.2.1

Readme

Source

clsx CI codecov

A tiny (228B) utility for constructing className strings conditionally.
Also serves as a faster & smaller drop-in replacement for the classnames module.

This module is available in three formats:

  • ES Module: dist/clsx.m.js
  • CommonJS: dist/clsx.js
  • UMD: dist/clsx.min.js

Install

$ npm install --save clsx

Usage

import clsx from 'clsx'; // or import { clsx } from 'clsx'; // Strings (variadic) clsx('foo', true && 'bar', 'baz'); //=> 'foo bar baz' // Objects clsx({ foo:true, bar:false, baz:isTrue() }); //=> 'foo baz' // Objects (variadic) clsx({ foo:true }, { bar:false }, null, { '--foobar':'hello' }); //=> 'foo --foobar' // Arrays clsx(['foo', 0, false, 'bar']); //=> 'foo bar' // Arrays (variadic) clsx(['foo'], ['', 0, false, 'bar'], [['baz', [['hello'], 'there']]]); //=> 'foo bar baz hello there' // Kitchen sink (with nesting) clsx('foo', [1 && 'bar', { baz:false, bat:null }, ['hello', ['world']]], 'cya'); //=> 'foo bar hello world cya'

API

clsx(...input)

Returns: String

input

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.

clsx(true, false, '', null, undefined, 0, NaN); //=> ''

Benchmarks

For snapshots of cross-browser results, check out the bench directory~!

Support

All versions of Node.js are supported.

All browsers that support Array.isArray are supported (IE9+).

Note: For IE8 support and older, please install [email protected] and beware of #17.

  • obj-str - A smaller (96B) and similiar utility that only works with Objects.

License

MIT © Luke Edwards

Keywords

FAQs

What is clsx?

A tiny (228B) utility for constructing className strings conditionally.

Is clsx popular?

The npm package clsx receives a total of 6,815,904 weekly downloads. As such, clsx popularity was classified as popular.

Is clsx well maintained?

We found that clsx demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 1 open source maintainer collaborating on the project.

Last updated on 06 Jul 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc