classnames
Advanced tools
Comparing version 2.2.1 to 2.2.2
/*! | ||
Copyright (c) 2015 Jed Watson. | ||
Copyright (c) 2016 Jed Watson. | ||
Licensed under the MIT License (MIT), see | ||
@@ -4,0 +4,0 @@ http://jedwatson.github.io/classnames |
{ | ||
"name": "classnames", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "A simple utility for conditionally joining classNames together", | ||
"main": "index.js", | ||
"main": [ | ||
"index.js", | ||
"bind.js", | ||
"dedupe.js" | ||
], | ||
"homepage": "https://github.com/JedWatson/classnames", | ||
@@ -7,0 +11,0 @@ "authors": [ |
/*! | ||
Copyright (c) 2015 Jed Watson. | ||
Copyright (c) 2016 Jed Watson. | ||
Licensed under the MIT License (MIT), see | ||
@@ -4,0 +4,0 @@ http://jedwatson.github.io/classnames |
# Changelog | ||
## v2.2.2 / 2016-01-04 | ||
* Switched from string concatenation to `[].join(' ')` for a slight performance gain in the main function. | ||
## v2.2.1 / 2015-11-26 | ||
@@ -4,0 +8,0 @@ |
12
index.js
/*! | ||
Copyright (c) 2015 Jed Watson. | ||
Copyright (c) 2016 Jed Watson. | ||
Licensed under the MIT License (MIT), see | ||
@@ -14,3 +14,3 @@ http://jedwatson.github.io/classnames | ||
function classNames () { | ||
var classes = ''; | ||
var classes = []; | ||
@@ -24,9 +24,9 @@ for (var i = 0; i < arguments.length; i++) { | ||
if (argType === 'string' || argType === 'number') { | ||
classes += ' ' + arg; | ||
classes.push(arg); | ||
} else if (Array.isArray(arg)) { | ||
classes += ' ' + classNames.apply(null, arg); | ||
classes.push(classNames.apply(null, arg)); | ||
} else if (argType === 'object') { | ||
for (var key in arg) { | ||
if (hasOwn.call(arg, key) && arg[key]) { | ||
classes += ' ' + key; | ||
classes.push(key); | ||
} | ||
@@ -37,3 +37,3 @@ } | ||
return classes.substr(1); | ||
return classes.join(' '); | ||
} | ||
@@ -40,0 +40,0 @@ |
{ | ||
"name": "classnames", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "A simple utility for conditionally joining classNames together", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -41,2 +41,3 @@ Classnames | ||
classNames({ 'foo-bar': true }); // => 'foo-bar' | ||
classNames({ 'foo-bar': false }); // => '' | ||
classNames({ foo: true }, { bar: true }); // => 'foo bar' | ||
@@ -46,3 +47,3 @@ 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' | ||
classNames('foo', { bar: true, duck: false }, 'baz', { quux: true }); // => 'foo bar baz quux' | ||
@@ -60,2 +61,11 @@ // other falsy values are just ignored | ||
### Dynamic class names with ES2015 | ||
If you're in an environment that supports [computed keys](http://www.ecma-international.org/ecma-262/6.0/#sec-object-initializer) (available in ES2015 and Babel) you can use dynamic class names: | ||
```js | ||
let buttonType = 'primary'; | ||
classNames({ [‘btn-${buttonType}’]: true }); | ||
``` | ||
### Usage with React.js | ||
@@ -129,2 +139,4 @@ | ||
_Note that in ES2015 environments, it may be better to use the "dynamic class names" approach documented above._ | ||
```js | ||
@@ -137,3 +149,3 @@ var classNames = require('classnames/bind'); | ||
baz: 'xyz' | ||
} | ||
}; | ||
@@ -165,4 +177,4 @@ var cx = classNames.bind(styles); | ||
return <button className={className}>{text}</button>; | ||
} | ||
} | ||
} | ||
}; | ||
@@ -176,8 +188,8 @@ ``` | ||
`Array.isArray`: see [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray) | ||
for details about unsupported older browsers (e.g. <= IE8) and a simple polyfill. | ||
`Object.keys`: see [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) for details about unsupported older browsers (e.g. <= IE8) and a simple polyfill. This is only used in `dedupe.js`. | ||
`Array.isArray`: see [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray) for details about unsupported older browsers (e.g. <= IE8) and a simple polyfill. | ||
`Object.keys`: see [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) for details about unsupported older browsers (e.g. <= IE8) and a simple polyfill. This is only used in `dedupe.js`. | ||
## License | ||
[MIT](LICENSE) | ||
[MIT](LICENSE). Copyright (c) 2016 Jed Watson. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
189
15971
9
196
1