classnames
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -7,7 +7,7 @@ function classNames() { | ||
var arg = args[i]; | ||
if (arg == null) { | ||
if (!arg) { | ||
continue; | ||
} | ||
if ('string' === typeof arg) { | ||
if ('string' === typeof arg || 'number' === typeof arg) { | ||
classes.push(arg); | ||
@@ -26,2 +26,3 @@ } else if ('object' === typeof arg) { | ||
module.exports = classNames; | ||
// safely export classNames in case the script is included directly on a page | ||
try { module.exports = classNames; } catch(e) {}; |
{ | ||
"name": "classnames", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "A simple utility for conditionally joining classNames together", | ||
@@ -16,2 +16,3 @@ "main": "index.js", | ||
"keywords": [ | ||
"react", | ||
"css", | ||
@@ -18,0 +19,0 @@ "classes", |
@@ -12,20 +12,20 @@ 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. | ||
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. | ||
```js | ||
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' | ||
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' | ||
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' | ||
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' | ||
classNames.apply(null, array); // => 'foo bar' | ||
``` |
@@ -16,4 +16,4 @@ var assert = require("assert"); | ||
it('joins arrays of class names and ignore non-string values', function() { | ||
assert.equal(classNames('a', 0, null, undefined, true, 1, 'b'), 'a b'); | ||
it('joins arrays of class names and ignore falsy values', function() { | ||
assert.equal(classNames('a', 0, null, undefined, true, 1, 'b'), 'a 1 b'); | ||
}); | ||
@@ -25,2 +25,6 @@ | ||
it('should be trimmed', function() { | ||
assert.equal(classNames('', 'b', {}, ''), 'b'); | ||
}); | ||
it('returns an empty string for an empty configuration', function() { | ||
@@ -27,0 +31,0 @@ assert.equal(classNames({}), ''); |
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
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
5267
8
82