Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

classnames

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

classnames - npm Package Compare versions

Comparing version 2.1.3 to 2.1.4

1

benchmarks/package.json

@@ -13,4 +13,5 @@ {

"devDependencies": {
"benchmark": "^1.0.0",
"classnames": "*"
}
}

78

benchmarks/run.js
var fixtures = [
{
description: "strings",
args: ["one", "two", "three"],
expected: "one two three"
description: 'strings',
args: ['one', 'two', 'three'],
expected: 'one two three'
},
{
description: "object",
description: 'object',
args: [{ one: true, two: true, three: false }],
expected: "one two"
expected: 'one two'
},
{
description: "mix",
args: ["one", { two: true, three: false }, { four: 'four', five: true }, 6, {}],
expected: "one two four five 6"
description: 'strings, object',
args: ['one', 'two', { four: true, three: false }],
expected: 'one two four'
},
{
description: "arrays",
args: [["one", "two"], ["three"], ["four", ["five"]], [{ six: true }, { seven: false }]],
expected: "one two three four five six"
description: 'mix',
args: ['one', { two: true, three: false }, { four: 'four', five: true }, 6, {}],
expected: 'one two four five 6'
},
{
description: 'arrays',
args: [['one', 'two'], ['three'], ['four', ['five']], [{ six: true }, { seven: false }]],
expected: 'one two three four five six'
}
];
var local = require("../");
var dedupe = require("../dedupe");
var local = require('../');
var dedupe = require('../dedupe');
var localPackage = require('../package.json');
try {
var npm = require("classnames");
var npmDedupe = require("classnames/dedupe");
var npm = require('classnames');
var npmDedupe = require('classnames/dedupe');
var npmPackage = require('./node_modules/classnames/package.json');
} catch(e) {
console.log("There was an error loading the benchmark classnames package.\n" +
"Please make sure you have run `npm install` in ./benchmarks\n");
} catch (e) {
console.log('There was an error loading the benchmark classnames package.\n' +
'Please make sure you have run `npm install` in ./benchmarks\n');
process.exit(0);

@@ -39,17 +44,16 @@ }

if (localPackage.version !== npmPackage.version) {
console.log("Your local version (" + localPackage.version + ") does not match the installed version (" + npmPackage.version + ")\n\n" +
"Please run `npm update` in ./benchmarks to ensure you are benchmarking\n" +
"the latest version of this package.\n");
console.log('Your local version (' + localPackage.version + ') does not match the installed version (' + npmPackage.version + ')\n\n' +
'Please run `npm update` in ./benchmarks to ensure you are benchmarking\n' +
'the latest version of this package.\n');
process.exit(0);
}
var assert = require("assert");
var benchmark = require("benchmark");
var assert = require('assert');
var benchmark = require('benchmark');
function sortClasses(str) {
var sorted = str.split(' ').sort();
return sorted.join(' ');
function sortClasses (str) {
return str.split(' ').sort().join(' ');
}
fixtures.forEach(function(f) {
fixtures.forEach(function (f) {
// sort assertions because dedupe returns results in a different order

@@ -63,15 +67,15 @@ assert.equal(sortClasses(local.apply(null, f.args)), sortClasses(f.expected));

suite.add("local#" + f.description, function() {
suite.add('local#' + f.description, function () {
local.apply(null, f.args);
});
suite.add(" npm#" + f.description, function() {
suite.add(' npm#' + f.description, function () {
npm.apply(null, f.args);
});
suite.add("local/dedupe#" + f.description, function() {
suite.add('local/dedupe#' + f.description, function () {
dedupe.apply(null, f.args);
});
suite.add(" npm/dedupe#" + f.description, function() {
suite.add(' npm/dedupe#' + f.description, function () {
npmDedupe.apply(null, f.args);

@@ -81,12 +85,12 @@ });

// after each cycle
suite.on("cycle", function (event) {
console.log("*", String(event.target));
suite.on('cycle', function (event) {
console.log('*', String(event.target));
});
// other handling
suite.on("complete", function() {
console.log("\n> Fastest is" + (" " + this.filter("fastest").pluck("name").join(' | ')).replace(/\s+/, ' ') + '\n');
suite.on('complete', function () {
console.log('\n> Fastest is' + (' ' + this.filter('fastest').pluck('name').join(' | ')).replace(/\s+/, ' ') + '\n');
});
suite.on("error", function(event) {
suite.on('error', function (event) {
throw event.target.error;

@@ -96,2 +100,2 @@ });

suite.run();
})
});
{
"name": "classnames",
"version": "2.1.3",
"version": "2.1.4",
"description": "A simple utility for conditionally joining classNames together",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -16,3 +16,7 @@ # Contributing

A benchmark utilitiy is included so that changes may be tested against the
current published version. To run the benchmarks, `npm install` in the
`./benchmarks` directory then run `npm run benchmarks`.
current published version. To run the benchmarks, `npm install` in the
`./benchmarks` directory then run `npm run benchmarks` in the package root.
Please be aware though that local benchmarks are just a smoke-signal; they will
run in the v8 version that your node/iojs uses, while classNames is _most_
often run across a wide variety of browsers and browser versions.

@@ -6,2 +6,3 @@ /*!

*/
/* global define */

@@ -20,2 +21,4 @@ (function () {

var hasOwn = {}.hasOwnProperty;
function _parseNumber (resultSet, num) {

@@ -27,6 +30,5 @@ resultSet[num] = true;

for (var k in object) {
if (object.hasOwnProperty(k)) {
if (hasOwn.call(object, k)) {
if (object[k]) {
resultSet[k] = true;
} else {

@@ -54,3 +56,3 @@ delete resultSet[k];

// 'foo bar'
if ('string' === argType) {
if (argType === 'string') {
_parseString(resultSet, arg);

@@ -63,7 +65,7 @@

// { 'foo': true, ... }
} else if ('object' === argType) {
} else if (argType === 'object') {
_parseObject(resultSet, arg);
// '130'
} else if ('number' === argType) {
} else if (argType === 'number') {
_parseNumber(resultSet, arg);

@@ -77,12 +79,6 @@ }

var classes = '';
for (var k in classSet) {
classes += ' ' + k;
}
return classes.substr(1);
return Object.keys(classSet).join(' ');
}
return _classNames;
})();

@@ -92,5 +88,5 @@

module.exports = classNames;
} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd){
// AMD. Register as an anonymous module.
define(function () {
} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {
// register as 'classnames', consistent with npm package name
define('classnames', function () {
return classNames;

@@ -101,3 +97,2 @@ });

}
}());
# Changelog
## v2.1.4 / 2015-09-30
* new case added to benchmarks
* safer `hasOwnProperty` check
* AMD module is now named, so you can do the following:
```
define(["classnames"], function (classNames) {
var style = classNames("foo", "bar");
// ...
});
```
## v2.1.3 / 2015-07-02

@@ -35,3 +48,3 @@

* added comprehensive support for array argiments, including nested arrays
* added comprehensive support for array arguments, including nested arrays
* simplified code slightly

@@ -38,0 +51,0 @@

@@ -6,2 +6,3 @@ /*!

*/
/* global define */

@@ -11,4 +12,5 @@ (function () {

var hasOwn = {}.hasOwnProperty;
function classNames () {
var classes = '';

@@ -22,11 +24,9 @@

if ('string' === argType || 'number' === argType) {
if (argType === 'string' || argType === 'number') {
classes += ' ' + arg;
} else if (Array.isArray(arg)) {
classes += ' ' + classNames.apply(null, arg);
} else if ('object' === argType) {
} else if (argType === 'object') {
for (var key in arg) {
if (arg.hasOwnProperty(key) && arg[key]) {
if (hasOwn.call(arg, key) && arg[key]) {
classes += ' ' + key;

@@ -43,5 +43,5 @@ }

module.exports = classNames;
} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd){
// AMD. Register as an anonymous module.
define(function () {
} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {
// register as 'classnames', consistent with npm package name
define('classnames', function () {
return classNames;

@@ -52,3 +52,2 @@ });

}
}());
{
"name": "classnames",
"version": "2.1.3",
"version": "2.1.4",
"description": "A simple utility for conditionally joining classNames together",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -79,2 +79,3 @@ Classnames

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`.

@@ -81,0 +82,0 @@ ## License

/* global describe, it */
var assert = require("assert");
var assert = require('assert');
var dedupe = require('../dedupe');
describe('dedupe', function () {
it('keeps object keys with truthy values', function() {
it('keeps object keys with truthy values', function () {
assert.equal(dedupe({

@@ -14,3 +14,3 @@ a: true,

e: undefined,
f: 1,
f: 1
}), 'a f');

@@ -29,28 +29,28 @@ });

assert.equal(dedupe('foo foo', 0, null, undefined, true, 1, 'b', { 'foo': false }), '1 b');
assert.equal(dedupe("foo", "foobar", "bar", { foo: false }), "foobar bar");
assert.equal(dedupe("foo", "foo-bar", "bar", { foo: false }), "foo-bar bar");
assert.equal(dedupe("foo", "-moz-foo-bar", "bar", { foo: false }), "-moz-foo-bar bar");
assert.equal(dedupe('foo', 'foobar', 'bar', { foo: false }), 'foobar bar');
assert.equal(dedupe('foo', 'foo-bar', 'bar', { foo: false }), 'foo-bar bar');
assert.equal(dedupe('foo', '-moz-foo-bar', 'bar', { foo: false }), '-moz-foo-bar bar');
});
it('joins arrays of class names and ignore falsy values', function() {
it('joins arrays of class names and ignore falsy values', function () {
assert.equal(dedupe('a', 0, null, undefined, true, 1, 'b'), '1 a b');
});
it('supports heterogenous arguments', function() {
it('supports heterogenous arguments', function () {
assert.equal(dedupe({a: true}, 'b', 0), 'a b');
});
it('should be trimmed', function() {
it('should be trimmed', function () {
assert.equal(dedupe('', 'b', {}, ''), 'b');
});
it('returns an empty string for an empty configuration', function() {
it('returns an empty string for an empty configuration', function () {
assert.equal(dedupe({}), '');
});
it('supports an array of class names', function() {
it('supports an array of class names', function () {
assert.equal(dedupe(['a', 'b']), 'a b');
});
it('joins array arguments with string arguments', function() {
it('joins array arguments with string arguments', function () {
assert.equal(dedupe(['a', 'b'], 'c'), 'a b c');

@@ -60,21 +60,21 @@ assert.equal(dedupe('c', ['a', 'b']), 'c a b');

it('handles multiple array arguments', function() {
it('handles multiple array arguments', function () {
assert.equal(dedupe(['a', 'b'], ['c', 'd']), 'a b c d');
});
it('handles arrays that include falsy and true values', function() {
it('handles arrays that include falsy and true values', function () {
assert.equal(dedupe(['a', 0, null, undefined, false, true, 'b']), 'a b');
});
it('handles arrays that include arrays', function() {
it('handles arrays that include arrays', function () {
assert.equal(dedupe(['a', ['b', 'c']]), 'a b c');
});
it('handles arrays that include objects', function() {
it('handles arrays that include objects', function () {
assert.equal(dedupe(['a', {b: true, c: false}]), 'a b');
});
it('handles deep array recursion', function() {
it('handles deep array recursion', function () {
assert.equal(dedupe(['a', ['b', ['c', {d: true}]]]), 'a b c d');
});
});
/* global describe, it */
var assert = require("assert");
var assert = require('assert');
var classNames = require('../');
describe('classNames', function() {
it('keeps object keys with truthy values', function() {
describe('classNames', function () {
it('keeps object keys with truthy values', function () {
assert.equal(classNames({

@@ -14,27 +14,27 @@ a: true,

e: undefined,
f: 1,
f: 1
}), 'a f');
});
it('joins arrays of class names and ignore falsy values', function() {
it('joins arrays of class names and ignore falsy values', function () {
assert.equal(classNames('a', 0, null, undefined, true, 1, 'b'), 'a 1 b');
});
it('supports heterogenous arguments', function() {
it('supports heterogenous arguments', function () {
assert.equal(classNames({a: true}, 'b', 0), 'a b');
});
it('should be trimmed', function() {
it('should be trimmed', function () {
assert.equal(classNames('', 'b', {}, ''), 'b');
});
it('returns an empty string for an empty configuration', function() {
it('returns an empty string for an empty configuration', function () {
assert.equal(classNames({}), '');
});
it('supports an array of class names', function() {
it('supports an array of class names', function () {
assert.equal(classNames(['a', 'b']), 'a b');
});
it('joins array arguments with string arguments', function() {
it('joins array arguments with string arguments', function () {
assert.equal(classNames(['a', 'b'], 'c'), 'a b c');

@@ -44,21 +44,21 @@ assert.equal(classNames('c', ['a', 'b']), 'c a b');

it('handles multiple array arguments', function() {
it('handles multiple array arguments', function () {
assert.equal(classNames(['a', 'b'], ['c', 'd']), 'a b c d');
});
it('handles arrays that include falsy and true values', function() {
it('handles arrays that include falsy and true values', function () {
assert.equal(classNames(['a', 0, null, undefined, false, true, 'b']), 'a b');
});
it('handles arrays that include arrays', function() {
it('handles arrays that include arrays', function () {
assert.equal(classNames(['a', ['b', 'c']]), 'a b c');
});
it('handles arrays that include objects', function() {
it('handles arrays that include objects', function () {
assert.equal(classNames(['a', {b: true, c: false}]), 'a b');
});
it('handles deep array recursion', function() {
it('handles deep array recursion', function () {
assert.equal(classNames(['a', ['b', ['c', {d: true}]]]), 'a b c d');
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc