JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 17022929
  • Score
    100M100P100Q252553F
  • License MIT

A simple utility for conditionally joining classNames together

Package Exports

  • classnames

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (classnames) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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, {baz: null}, ''); // => 'bar'

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