8000 GitHub - chenglou/classnames: A simple javascript utility for conditionally joining classNames together
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chenglou/classnames

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Classnames

A simple javascript utility for conditionally joining classNames together.

Install with npm, or download the UMD version (provides window.classnames, or defines the AMD modules 'classnames').

npm install classnames

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.

classNames('foo', 'bar'); // => 'foo bar'
classNames('foo', {bar: true}); // => 'foo bar'
classNames({foo: true}, {bar: true}); // => 'foo bar'
classNames({foo: true, bar: true}); // => 'foo bar'

// lots of arguments of various types
classNames('foo', {bar: true, duck: false}, 'baz', {quux: true}) // => 'foo bar baz quux'

// other falsy values are just ignored
classNames(null, false, 'bar', undefined, 0, 1, {baz: null}, ''); // => 'bar 1'

// if you have an array of these, use apply
var array = ['foo', {bar: true}];
classNames.apply(null, array); // => 'foo bar'

About

A simple javascript utility for conditionally joining classNames together

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%
0