1 | Classnames
|
2 | ===========
|
3 |
|
4 | [![Version](http://img.shields.io/npm/v/classnames.svg)](https://www.npmjs.org/package/classnames)
|
5 |
|
6 | A simple javascript utility for conditionally joining classNames together.
|
7 |
|
8 | Install with npm or Bower.
|
9 |
|
10 | ```sh
|
11 | npm install classnames
|
12 | ```
|
13 |
|
14 | The `classNames` function takes any number of arguments which can be a string or object.
|
15 | The argument `'foo'` is short for `{foo: true}`. If the value of the key is falsy, it won't be included in the output.
|
16 |
|
17 | ```js
|
18 | classNames('foo', 'bar'); // => 'foo bar'
|
19 | classNames('foo', { bar: true }); // => 'foo bar'
|
20 | classNames({ foo: true }, { bar: true }); // => 'foo bar'
|
21 | classNames({ foo: true, bar: true }); // => 'foo bar'
|
22 |
|
23 | // lots of arguments of various types
|
24 | classNames('foo', { bar: true, duck: false }, 'baz', { quux: true }) // => 'foo bar baz quux'
|
25 |
|
26 | // other falsy values are just ignored
|
27 | classNames(null, false, 'bar', undefined, 0, 1, { baz: null }, ''); // => 'bar 1'
|
28 | ```
|
29 |
|
30 | Arrays will be recursively flattened as per the rules above:
|
31 |
|
32 | ```js
|
33 | var arr = ['b', { c: true, d: false }];
|
34 | classNames('a', arr); // => 'a b c'
|
35 | ```
|
36 |
|
37 | ## License
|
38 |
|
39 | (The MIT License)
|
40 |
|
41 | Copyright (c) 2015 Jed Watson
|
42 |
|
43 | Permission is hereby granted, free of charge, to any person obtaining
|
44 | a copy of this software and associated documentation files (the
|
45 | 'Software'), to deal in the Software without restriction, including
|
46 | without limitation the rights to use, copy, modify, merge, publish,
|
47 | distribute, sublicense, and/or sell copies of the Software, and to
|
48 | permit persons to whom the Software is furnished to do so, subject to
|
49 | the following conditions:
|
50 |
|
51 | The above copyright notice and this permission notice shall be
|
52 | included in all copies or substantial portions of the Software.
|
53 |
|
54 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
55 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
56 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
57 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
58 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
59 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
60 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|