UNPKG

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