Gathering detailed insights and metrics for classnames-es-ts
Gathering detailed insights and metrics for classnames-es-ts
Gathering detailed insights and metrics for classnames-es-ts
Gathering detailed insights and metrics for classnames-es-ts
@taktikorg/unde-animi-omnis
<p align="center"> <a href="https://www.npmjs.com/package/@taktikorg/unde-animi-omnis"><img src="https://img.shields.io/npm/v/@taktikorg/unde-animi-omnis"></a> <a href=""><img src="https://img.shields.io/github/actions/workflow/status/RemiMyrset/@taktikor
@crabas0npm2/perspiciatis-voluptate-similique
security holding package
@crabas0npm2/culpa-eius-deserunt
security holding package
@crabas0npm2/ipsum-repellat-consequatur
security holding package
A simple javascript utility for conditionally joining classNames together
npm install classnames-es-ts
Typescript
Module System
Node Version
NPM Version
JavaScript (81.92%)
TypeScript (16.81%)
HTML (1.28%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
17,760 Stars
470 Commits
560 Forks
120 Watchers
8 Branches
43 Contributors
Updated on Jul 12, 2025
Latest Version
2.2.7
Package Id
classnames-es-ts@2.2.7
Size
6.50 kB
NPM Version
6.10.3
Node Version
12.10.0
Published on
Feb 23, 2020
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
No dependencies detected.
A simple javascript utility for conditionally joining classNames together.
Install with npm or Bower.
1npm install classnames --save
Use with node.js, browserify or webpack:
1var classNames = require('classnames'); 2classNames('foo', 'bar'); // => 'foo bar'
Alternatively, you can simply include index.js
on your page with a standalone <script>
tag and it will export a global classNames
method, or define the module if you are using RequireJS.
We take the stability and performance of this package seriously, because it is run millions of times a day in browsers all around the world. Updates are thoroughly reviewed for performance impacts before being released, and we have a comprehensive test suite.
Classnames follows the SemVer standard for versioning.
There is also a Changelog.
The classNames
function takes any number of arguments which can be a string or object.
The argument 'foo'
is short for { foo: true }
. If the value of the key is falsy, it won't be included in the output.
1classNames('foo', 'bar'); // => 'foo bar'
2classNames('foo', { bar: true }); // => 'foo bar'
3classNames({ 'foo-bar': true }); // => 'foo-bar'
4classNames({ 'foo-bar': false }); // => ''
5classNames({ foo: true }, { bar: true }); // => 'foo bar'
6classNames({ foo: true, bar: true }); // => 'foo bar'
7
8// lots of arguments of various types
9classNames('foo', { bar: true, duck: false }, 'baz', { quux: true }); // => 'foo bar baz quux'
10
11// other falsy values are just ignored
12classNames(null, false, 'bar', undefined, 0, 1, { baz: null }, ''); // => 'bar 1'
Arrays will be recursively flattened as per the rules above:
1var arr = ['b', { c: true, d: false }]; 2classNames('a', arr); // => 'a b c'
If you're in an environment that supports computed keys (available in ES2015 and Babel) you can use dynamic class names:
1let buttonType = 'primary'; 2classNames({ [`btn-${buttonType}`]: true });
This package is the official replacement for classSet
, which was originally shipped in the React.js Addons bundle.
One of its primary use cases is to make dynamic and conditional className props simpler to work with (especially more so than conditional string manipulation). So where you may have the following code to generate a className
prop for a <button>
in React:
1var Button = React.createClass({ 2 // ... 3 render () { 4 var btnClass = 'btn'; 5 if (this.state.isPressed) btnClass += ' btn-pressed'; 6 else if (this.state.isHovered) btnClass += ' btn-over'; 7 return <button className={btnClass}>{this.props.label}</button>; 8 } 9});
You can express the conditional classes more simply as an object:
1var classNames = require('classnames');
2
3var Button = React.createClass({
4 // ...
5 render () {
6 var btnClass = classNames({
7 'btn': true,
8 'btn-pressed': this.state.isPressed,
9 'btn-over': !this.state.isPressed && this.state.isHovered
10 });
11 return <button className={btnClass}>{this.props.label}</button>;
12 }
13});
Because you can mix together object, array and string arguments, supporting optional className props is also simpler as only truthy arguments get included in the result:
1var btnClass = classNames('btn', this.props.className, {
2 'btn-pressed': this.state.isPressed,
3 'btn-over': !this.state.isPressed && this.state.isHovered
4});
dedupe
versionThere is an alternate version of classNames
available which correctly dedupes classes and ensures that falsy classes specified in later arguments are excluded from the result set.
This version is slower (about 5x) so it is offered as an opt-in.
To use the dedupe version with node, browserify or webpack:
1var classNames = require('classnames/dedupe');
2
3classNames('foo', 'foo', 'bar'); // => 'foo bar'
4classNames('foo', { foo: false, bar: true }); // => 'bar'
For standalone (global / AMD) use, include dedupe.js
in a <script>
tag on your page.
bind
version (for css-modules)If you are using css-modules, or a similar approach to abstract class "names" and the real className
values that are actually output to the DOM, you may want to use the bind
variant.
Note that in ES2015 environments, it may be better to use the "dynamic class names" approach documented above.
1var classNames = require('classnames/bind'); 2 3var styles = { 4 foo: 'abc', 5 bar: 'def', 6 baz: 'xyz' 7}; 8 9var cx = classNames.bind(styles); 10 11var className = cx('foo', ['bar'], { baz: true }); // => "abc def xyz"
Real-world example:
1/* components/submit-button.js */ 2import { Component } from 'react'; 3import classNames from 'classnames/bind'; 4import styles from './submit-button.css'; 5 6let cx = classNames.bind(styles); 7 8export default class SubmitButton extends Component { 9 render () { 10 let text = this.props.store.submissionInProgress ? 'Processing...' : 'Submit'; 11 let className = cx({ 12 base: true, 13 inProgress: this.props.store.submissionInProgress, 14 error: this.props.store.errorOccurred, 15 disabled: this.props.form.valid, 16 }); 17 return <button className={className}>{text}</button>; 18 } 19}; 20
classNames >=2.0.0
Array.isArray
: see MDN for details about unsupported older browsers (e.g. <= IE8) and a simple polyfill.
Object.keys
: see MDN for details about unsupported older browsers (e.g. <= IE8) and a simple polyfill. This is only used in dedupe.js
.
MIT. Copyright (c) 2016 Jed Watson.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
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