classnames
Advanced tools
Comparing version 2.2.6 to 2.3.0
12
bind.js
/*! | ||
Copyright (c) 2017 Jed Watson. | ||
Copyright (c) 2018 Jed Watson. | ||
Licensed under the MIT License (MIT), see | ||
@@ -27,6 +27,10 @@ http://jedwatson.github.io/classnames | ||
} else if (argType === 'object') { | ||
for (var key in arg) { | ||
if (hasOwn.call(arg, key) && arg[key]) { | ||
classes.push(this && this[key] || key); | ||
if (arg.toString === Object.prototype.toString) { | ||
for (var key in arg) { | ||
if (hasOwn.call(arg, key) && arg[key]) { | ||
classes.push(this && this[key] || key); | ||
} | ||
} | ||
} else { | ||
classes.push(arg.toString()); | ||
} | ||
@@ -33,0 +37,0 @@ } |
/*! | ||
Copyright (c) 2017 Jed Watson. | ||
Copyright (c) 2018 Jed Watson. | ||
Licensed under the MIT License (MIT), see | ||
@@ -32,8 +32,12 @@ http://jedwatson.github.io/classnames | ||
function _parseObject (resultSet, object) { | ||
for (var k in object) { | ||
if (hasOwn.call(object, k)) { | ||
// set value to false instead of deleting it to avoid changing object structure | ||
// https://www.smashingmagazine.com/2012/11/writing-fast-memory-efficient-javascript/#de-referencing-misconceptions | ||
resultSet[k] = !!object[k]; | ||
if (object.toString === Object.prototype.toString) { | ||
for (var k in object) { | ||
if (hasOwn.call(object, k)) { | ||
// set value to false instead of deleting it to avoid changing object structure | ||
// https://www.smashingmagazine.com/2012/11/writing-fast-memory-efficient-javascript/#de-referencing-misconceptions | ||
resultSet[k] = !!object[k]; | ||
} | ||
} | ||
} else { | ||
resultSet[object.toString()] = true; | ||
} | ||
@@ -40,0 +44,0 @@ } |
# Changelog | ||
## v2.3.0 / 2021-04-01 | ||
- Added TypeScript types | ||
- Added consistent support for custom `.toString()` methods on arguments, thanks [Stanislav Titenko](https://github.com/resetko) | ||
## v2.2.6 / 2018-06-08 | ||
* Fixed compatibility issue with usage in an es module environment | ||
- Fixed compatibility issue with usage in an es module environment | ||
## v2.2.5 / 2016-05-02 | ||
* Improved performance of `dedupe` variant even further, thanks [Andres Suarez](https://github.com/zertosh) | ||
- Improved performance of `dedupe` variant even further, thanks [Andres Suarez](https://github.com/zertosh) | ||
## v2.2.4 / 2016-04-25 | ||
* Improved performance of `dedupe` variant by about 2x, thanks [Bartosz Gościński](https://github.com/bgoscinski) | ||
- Improved performance of `dedupe` variant by about 2x, thanks [Bartosz Gościński](https://github.com/bgoscinski) | ||
## v2.2.3 / 2016-01-05 | ||
* Updated `bind` variant to use `[].join(' ')` as per the main script in 2.2.2 | ||
- Updated `bind` variant to use `[].join(' ')` as per the main script in 2.2.2 | ||
## v2.2.2 / 2016-01-04 | ||
* Switched from string concatenation to `[].join(' ')` for a slight performance gain in the main function. | ||
- Switched from string concatenation to `[].join(' ')` for a slight performance gain in the main function. | ||
## v2.2.1 / 2015-11-26 | ||
* Add deps parameter to the AMD module, fixes an issue using the Dojo loader, thanks [Chris Jordan](https://github.com/flipperkid) | ||
- Add deps parameter to the AMD module, fixes an issue using the Dojo loader, thanks [Chris Jordan](https://github.com/flipperkid) | ||
## v2.2.0 / 2015-10-18 | ||
* added a new `bind` variant for use with [css-modules](https://github.com/css-modules/css-modules) and similar abstractions, thanks to [Kirill Yakovenko](https://github.com/blia) | ||
- added a new `bind` variant for use with [css-modules](https://github.com/css-modules/css-modules) and similar abstractions, thanks to [Kirill Yakovenko](https://github.com/blia) | ||
## v2.1.5 / 2015-09-30 | ||
* reverted a new usage of `Object.keys` in `dedupe.js` that slipped through in the last release | ||
- reverted a new usage of `Object.keys` in `dedupe.js` that slipped through in the last release | ||
## 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: | ||
- new case added to benchmarks | ||
- safer `hasOwnProperty` check | ||
- AMD module is now named, so you can do the following: | ||
@@ -50,34 +55,34 @@ ``` | ||
* updated UMD wrapper to support AMD and CommonJS on the same pacge | ||
- updated UMD wrapper to support AMD and CommonJS on the same pacge | ||
## v2.1.2 / 2015-05-28 | ||
* added a proper UMD wrapper | ||
- added a proper UMD wrapper | ||
## v2.1.1 / 2015-05-06 | ||
* minor performance improvement thanks to type caching | ||
* improved benchmarking and results output | ||
- minor performance improvement thanks to type caching | ||
- improved benchmarking and results output | ||
## v2.1.0 / 2015-05-05 | ||
* added alternate `dedupe` version of classNames, which is slower (10x) but ensures that if a class is added then overridden by a falsy value in a subsequent argument, it is excluded from the result. | ||
- added alternate `dedupe` version of classNames, which is slower (10x) but ensures that if a class is added then overridden by a falsy value in a subsequent argument, it is excluded from the result. | ||
## v2.0.0 / 2015-05-03 | ||
* performance improvement; switched to `Array.isArray` for type detection, which is much faster in modern browsers. A polyfill is now required for IE8 support, see the Readme for details. | ||
- performance improvement; switched to `Array.isArray` for type detection, which is much faster in modern browsers. A polyfill is now required for IE8 support, see the Readme for details. | ||
## v1.2.2 / 2015-04-28 | ||
* license comment updates to simiplify certain build scenarios | ||
- license comment updates to simiplify certain build scenarios | ||
## v1.2.1 / 2015-04-22 | ||
* added safe exporting for requireJS usage | ||
* clarified Bower usage and instructions | ||
- added safe exporting for requireJS usage | ||
- clarified Bower usage and instructions | ||
## v1.2.0 / 2015-03-17 | ||
* added comprehensive support for array arguments, including nested arrays | ||
* simplified code slightly | ||
- added comprehensive support for array arguments, including nested arrays | ||
- simplified code slightly | ||
@@ -84,0 +89,0 @@ ## Previous |
24
index.js
/*! | ||
Copyright (c) 2017 Jed Watson. | ||
Copyright (c) 2018 Jed Watson. | ||
Licensed under the MIT License (MIT), see | ||
@@ -13,3 +13,3 @@ http://jedwatson.github.io/classnames | ||
function classNames () { | ||
function classNames() { | ||
var classes = []; | ||
@@ -25,12 +25,18 @@ | ||
classes.push(arg); | ||
} else if (Array.isArray(arg) && arg.length) { | ||
var inner = classNames.apply(null, arg); | ||
if (inner) { | ||
classes.push(inner); | ||
} else if (Array.isArray(arg)) { | ||
if (arg.length) { | ||
var inner = classNames.apply(null, arg); | ||
if (inner) { | ||
classes.push(inner); | ||
} | ||
} | ||
} else if (argType === 'object') { | ||
for (var key in arg) { | ||
if (hasOwn.call(arg, key) && arg[key]) { | ||
classes.push(key); | ||
if (arg.toString === Object.prototype.toString) { | ||
for (var key in arg) { | ||
if (hasOwn.call(arg, key) && arg[key]) { | ||
classes.push(key); | ||
} | ||
} | ||
} else { | ||
classes.push(arg.toString()); | ||
} | ||
@@ -37,0 +43,0 @@ } |
{ | ||
"name": "classnames", | ||
"version": "2.2.6", | ||
"version": "2.3.0", | ||
"description": "A simple utility for conditionally joining classNames together", | ||
@@ -12,6 +12,6 @@ "main": "index.js", | ||
}, | ||
"types": "./index.d.ts", | ||
"scripts": { | ||
"benchmarks": "node ./benchmarks/run", | ||
"benchmarks-browserify": "./node_modules/.bin/browserify ./benchmarks/runInBrowser.js >./benchmarks/runInBrowser.bundle.js", | ||
"benchmarks-in-browser": "./node_modules/.bin/opn ./benchmarks/benchmarks.html", | ||
"test": "mocha tests/*.js" | ||
@@ -29,7 +29,6 @@ }, | ||
"devDependencies": { | ||
"benchmark": "^1.0.0", | ||
"browserify": "^14.1.0", | ||
"mocha": "^2.1.0", | ||
"opn-cli": "^3.1.0" | ||
"benchmark": "^2.1.4", | ||
"browserify": "^16.2.3", | ||
"mocha": "^8.3.2" | ||
} | ||
} |
Classnames | ||
=========== | ||
[![Version](http://img.shields.io/npm/v/classnames.svg)](https://www.npmjs.org/package/classnames) | ||
[![Build Status](https://travis-ci.org/JedWatson/classnames.svg?branch=master)](https://travis-ci.org/JedWatson/classnames) | ||
[![Supported by Thinkmill](https://thinkmill.github.io/badge/heart.svg)](http://thinkmill.com.au/?utm_source=github&utm_medium=badge&utm_campaign=classnames) | ||
[![NPM version](https://badgen.net/npm/v/classnames)](https://www.npmjs.com/package/classnames) | ||
[![Build status](https://badgen.net/travis/JedWatson/classnames)](https://travis-ci.org/JedWatson/classnames) | ||
[![NPM Weekly Downloads](https://badgen.net/npm/dw/classnames)](https://www.npmjs.com/package/classnames) | ||
[![License](https://badgen.net/npm/license/classnames)](https://www.npmjs.com/package/classnames) | ||
[![Supported by Thinkmill](https://thinkmill.github.io/badge/heart.svg)](https://thinkmill.com.au/?utm_source=github&utm_medium=badge&utm_campaign=classnames) | ||
@@ -12,18 +14,14 @@ A simple JavaScript utility for conditionally joining classNames together. | ||
npm: | ||
```sh | ||
npm install classnames --save | ||
``` | ||
```bash | ||
# via npm | ||
npm install classnames | ||
Bower: | ||
```sh | ||
bower install classnames --save | ||
``` | ||
# via Bower | ||
bower install classnames | ||
Yarn (note that `yarn add` automatically saves the package to the `dependencies` in `package.json`): | ||
```sh | ||
# or Yarn (note that it will automatically save the package to your `dependencies` in `package.json`) | ||
yarn add classnames | ||
``` | ||
Use with [Node.js](https://nodejs.org/en/), [Browserify](http://browserify.org/), or [webpack](https://webpack.github.io/): | ||
Use with [Node.js](https://nodejs.org/en/), [Browserify](https://browserify.org/), or [webpack](https://webpack.github.io/): | ||
@@ -41,3 +39,3 @@ ```js | ||
Classnames follows the [SemVer](http://semver.org/) standard for versioning. | ||
Classnames follows the [SemVer](https://semver.org/) standard for versioning. | ||
@@ -75,3 +73,3 @@ There is also a [Changelog](https://github.com/JedWatson/classnames/blob/master/HISTORY.md). | ||
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: | ||
If you're in an environment that supports [computed keys](https://www.ecma-international.org/ecma-262/6.0/#sec-object-initializer) (available in ES2015 and Babel) you can use dynamic class names: | ||
@@ -90,3 +88,3 @@ ```js | ||
```js | ||
var Button = React.createClass({ | ||
class Button extends React.Component { | ||
// ... | ||
@@ -99,3 +97,3 @@ render () { | ||
} | ||
}); | ||
} | ||
``` | ||
@@ -108,3 +106,3 @@ | ||
var Button = React.createClass({ | ||
class Button extends React.Component { | ||
// ... | ||
@@ -119,3 +117,3 @@ render () { | ||
} | ||
}); | ||
} | ||
``` | ||
@@ -203,6 +201,6 @@ | ||
`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 | ||
## LICENSE [MIT](LICENSE) | ||
[MIT](LICENSE). Copyright (c) 2017 Jed Watson. | ||
Copyright (c) 2018 Jed Watson. | ||
Copyright of the Typescript bindings are respective of each contributor listed in the definition file. |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
17646
3
10
210
199
1