Comparing version 1.1.7 to 1.2.0
{ | ||
"name": "cnbuilder", | ||
"version": "1.1.7", | ||
"description": "Yet another classname string builder (the fastest one)", | ||
"version": "1.2.0", | ||
"main": "dist/cnbuilder.js", | ||
@@ -8,3 +9,3 @@ "module": "dist/cnbuilder.esm.js", | ||
"types": "dist/index.d.ts", | ||
"description": "Yet another classname string builder", | ||
"sideEffects": false, | ||
"files": [ | ||
@@ -34,48 +35,65 @@ "dist" | ||
"devDependencies": { | ||
"@types/jest": "^24.0.13", | ||
"codacy-coverage": "^3.4.0", | ||
"husky": "^2.3.0", | ||
"jest": "^24.8.0", | ||
"prettier": "^1.17.1", | ||
"pretty-quick": "^1.11.0", | ||
"rimraf": "^2.6.3", | ||
"rollup": "^1.12.3", | ||
"rollup-plugin-typescript2": "^0.21.1", | ||
"terser": "^3.17.0", | ||
"ts-jest": "^24.0.2", | ||
"typescript": "^3.4.5" | ||
"@semantic-release/changelog": "^3.0.6", | ||
"@semantic-release/git": "^8.0.0", | ||
"@semantic-release/npm": "^6.0.0", | ||
"@types/jest": "^25.1.2", | ||
"@xobotyi/eslint-config": "^1.3.1", | ||
"@xobotyi/preset-typescript": "^1.0.0", | ||
"eslint": "^6.8.0", | ||
"husky": "^4.2.3", | ||
"jest": "^25.1.0", | ||
"lint-staged": "^10.0.7", | ||
"prettier": "^1.19.1", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^1.31.1", | ||
"rollup-plugin-terser": "^5.2.0", | ||
"rollup-plugin-typescript2": "^0.26.0", | ||
"semantic-release": "^17.0.3", | ||
"ts-jest": "^25.2.0", | ||
"typescript": "^3.7.5" | ||
}, | ||
"scripts": { | ||
"push-codacy-coverage": "cat ./coverage/lcov.info | codacy-coverage", | ||
"format": "prettier --write src/**/*.ts tests/**/*.ts benchmark/src/**/*.ts src/**/*.js tests/**/*.js benchmark/src/**/*.js *.js *.ts", | ||
"build": "rimraf ./dist && rollup --config && npm run minify", | ||
"minify": "terser ./dist/cnbuilder.js -o ./dist/cnbuilder.js -mc pure_funcs=['Object.defineProperty'] --toplevel --source-map includeSources,url=cnbuilder.js.map", | ||
"lint": "eslint ./{src,tests}/**/*.ts ./*.{ts,js}", | ||
"lint:fix": "yarn lint --fix", | ||
"lint:types": "tsc --noEmit", | ||
"build": "rimraf ./dist && rollup --config", | ||
"test": "jest", | ||
"preversion": "npm run format && npm run build", | ||
"postversion": "git push && git push --tags", | ||
"prepublishOnly": "npm run format && npm run test && npm run build" | ||
"semantic-release": "semantic-release" | ||
}, | ||
"lint-staged": { | ||
"./{src,tests}/**/*.ts": [ | ||
"tslint --fix -t verbose", | ||
"git add" | ||
], | ||
"./*.{ts,js}": [ | ||
"tslint --fix -t verbose", | ||
"git add" | ||
] | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "pretty-quick --staged" | ||
"pre-commit": "yarn lint:types && lint-staged", | ||
"pre-push": "yarn lint:fix && rimraf dist && yarn build && yarn test" | ||
} | ||
}, | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"js" | ||
"release": { | ||
"branches": [ | ||
"master", | ||
{ | ||
"name": "next", | ||
"prerelease": "rc" | ||
} | ||
], | ||
"transform": { | ||
"\\.(ts|tsx)$": "ts-jest" | ||
}, | ||
"testRegex": "/tests/.*\\.spec\\.(ts|tsx)$", | ||
"coverageDirectory": "./coverage", | ||
"collectCoverage": true, | ||
"collectCoverageFrom": [ | ||
"src/**/*.ts" | ||
"verifyConditions": [ | ||
"@semantic-release/changelog", | ||
"@semantic-release/npm", | ||
"@semantic-release/git", | ||
"@semantic-release/github" | ||
], | ||
"prepare": [ | ||
"@semantic-release/changelog", | ||
"@semantic-release/npm", | ||
"@semantic-release/git" | ||
] | ||
}, | ||
"prettier": { | ||
"printWidth": 120 | ||
} | ||
} |
114
README.md
<div align="center"> | ||
<h1>cnbuilder</h1> | ||
<p>Yet another classname string builder (the fastest one)</p> | ||
<p> | ||
<a href="https://www.npmjs.com/package/cnbuilder"><img src="https://img.shields.io/badge/npm-cnbuilder-brightgreen.svg" /></a> | ||
<a href="https://www.npmjs.com/package/cnbuilder"><img src="https://img.shields.io/npm/v/cnbuilder.svg" /></a> | ||
<a href="https://www.npmjs.com/package/cnbuilder"><img src="https://img.shields.io/npm/dt/cnbuilder.svg" /></a> | ||
<a href="https://www.npmjs.com/package/cnbuilder"><img src="https://img.shields.io/travis/xobotyi/cnbuilder.svg" /></a> | ||
<a href="https://www.codacy.com/app/xobotyi/cnbuilder"><img src="https://api.codacy.com/project/badge/Grade/71cdf9626f264970a23706c93b83a4bb"/></a> | ||
<a href="https://www.codacy.com/app/xobotyi/cnbuilder"><img src="https://api.codacy.com/project/badge/Coverage/71cdf9626f264970a23706c93b83a4bb"/></a> | ||
<a href="https://www.npmjs.com/package/cnbuilder"><img src="https://img.shields.io/npm/l/cnbuilder.svg" /></a> | ||
<a href="https://www.npmjs.com/package/cnbuilder"> | ||
<img src="https://flat.badgen.net/travis/xobotyi/scrollbar-width" alt="Build status"/> | ||
</a> | ||
<a href="https://www.npmjs.com/package/cnbuilder"> | ||
<img src="https://flat.badgen.net/npm/v/cnbuilder" alt="NPM version"/> | ||
</a> | ||
<a href="https://www.npmjs.com/package/cnbuilder"> | ||
<img src="https://flat.badgen.net/npm/dw/cnbuilder" alt="NPM weekly downloads"/> | ||
</a> | ||
<a href="https://www.npmjs.com/package/cnbuilder"> | ||
<img src="https://flat.badgen.net/npm/license/cnbuilder" alt="License"/> | ||
</a> | ||
<a href="https://www.npmjs.com/package/cnbuilder"> | ||
<img src="https://flat.badgen.net/npm/types/cnbuilder" alt="Types definition"/> | ||
</a> | ||
<a href="https://www.npmjs.com/package/cnbuilder"> | ||
<img src="https://flat.badgen.net/codacy/grade/71cdf9626f264970a23706c93b83a4bb" alt="Codacy Code Grade"/> | ||
</a> | ||
<a href="https://www.npmjs.com/package/cnbuilder"> | ||
<img src="https://flat.badgen.net/codacy/coverage/71cdf9626f264970a23706c93b83a4bb" alt="Tests LOC"/> | ||
</a> | ||
</p> | ||
@@ -15,3 +30,3 @@ </div> | ||
One more DOM classname string builder if you not enough yet 😁 | ||
It is **[lightweight](https://bundlephobia.com/result?p=cnbuilder)**, **[fast](#performance-recent-benchmarks-results)** and has **no dependencies**! | ||
It is **[lightweight](https://bundlephobia.com/result?p=cnbuilder)**, **[fast](#performance-recent-benchmarks-results)** and has no dependencies! | ||
Designed to be fastest full-feature drop-in replacement for `classnames` package. | ||
@@ -27,2 +42,4 @@ | ||
Use it wherever and however you want - node.js or webpack, CJS or ESM modules! | ||
**INSTALLATION NOTE:** | ||
@@ -56,9 +73,9 @@ This lib is written in ES6+ and delivering with both, transpiled and untranspiled versions: | ||
`cnbuilder` is designed to be as lightweight and fast as possible, without loosing the functionality ([jorgebucaran/classcat](https://github.com/jorgebucaran/classcat) is faster in some cases but less handy because does not allow to pass variable count of arguments). | ||
It is written with power of [TypeScript](http://www.typescriptlang.org) and it's API is fully compatible with [JedWatson/classnames](https://github.com/JedWatson/classnames), so it wont be anyhow hard to migrate for you if you're already using `classnames` package. | ||
It is written with power of [TypeScript](http://www.typescriptlang.org) and it's API is fully compatible with [JedWatson/classnames](https://github.com/JedWatson/classnames), so it wont be anyhow hard to migrate if you're already using `classnames` package. | ||
### Usage | ||
As already said - API is the same with `classnames` pkg, and due to my laziness - i'll just copy-past their usage documentation (width small additions)😅😱 | ||
As already said - API is the same with `classnames` pkg, and due to my laziness - i'll just copy-past their usage documentation (with small additions)😅😱 | ||
The `classNames` function takes any number of arguments which can be a string, array or object. | ||
The `cnb` function takes any number of arguments which can be a string, array or object. Any other input will be ignored. | ||
The argument `'foo'` is short for `{ foo: true }` or `['foo']`. If the value associated with a given key is falsy, that key won't be included in the output. | ||
@@ -92,3 +109,3 @@ | ||
```javascript | ||
classnames("test", [], { a: false }); // => "test " (4 chars with space at the end) | ||
classnames("test", [], { a: false }); // => "test " (5 chars with space at the end) | ||
cnb("test", [], { a: false }); // => "test" (just 4 chars) | ||
@@ -114,3 +131,2 @@ ``` | ||
`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. | ||
`Array.reduce`: see [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce) for details about unsupported older browsers (e.g. <= IE10) and a simple polyfill. | ||
@@ -122,47 +138,47 @@ ### Performance (recent benchmarks results) | ||
```bash | ||
npm run build && npm i -C benchmark && npm -C benchmark start | ||
yarn && yarn build && cd ./benchmark && yarn && yarn start | ||
``` | ||
<pre> | ||
# STRINGS | ||
classcat × 7,817,007 ops/sec; | ||
classnames × 3,039,813 ops/sec; | ||
clsx × 8,455,870 ops/sec; | ||
<string><em>cnbuilder × 9,001,686 ops/sec;</em></string> | ||
# strings | ||
<string><em>cnbuilder x 9,269,882 ops/sec ±0.40% (96 runs sampled)</em></string> | ||
classcat x 8,420,286 ops/sec ±1.17% (95 runs sampled) | ||
classnames x 2,981,605 ops/sec ±0.39% (93 runs sampled) | ||
clsx x 7,922,417 ops/sec ±0.25% (93 runs sampled) | ||
# OBJECTS | ||
classcat × 6,783,071 ops/sec; | ||
classnames × 2,623,124 ops/sec; | ||
clsx × 5,247,541 ops/sec; | ||
<string><em>cnbuilder × 7,197,917 ops/sec;</em></string> | ||
# objects | ||
cnbuilder x 7,270,064 ops/sec ±0.65% (95 runs sampled) | ||
<string><em>classcat x 7,484,998 ops/sec ±0.70% (95 runs sampled)</em></string> | ||
classnames x 2,731,604 ops/sec ±0.45% (95 runs sampled) | ||
clsx x 5,370,626 ops/sec ±0.44% (96 runs sampled) | ||
# ARRAYS | ||
<string><em>classcat × 6,189,615 ops/sec;</em></string> | ||
classnames × 1,222,725 ops/sec; | ||
clsx × 5,512,391 ops/sec; | ||
cnbuilder × 5,839,618 ops/sec; | ||
# arrays | ||
<string><em>cnbuilder x 7,092,002 ops/sec ±0.42% (94 runs sampled)</em></string> | ||
classcat x 6,818,053 ops/sec ±0.29% (92 runs sampled) | ||
classnames x 1,676,201 ops/sec ±0.27% (96 runs sampled) | ||
clsx x 6,083,849 ops/sec ±0.22% (94 runs sampled) | ||
# NESTED ARRAYS | ||
classcat × 1,433,007 ops/sec; | ||
classnames × 821,668 ops/sec; | ||
<string><em>clsx × 4,064,528 ops/sec;</em></string> | ||
cnbuilder × 3,653,864 ops/sec; | ||
# nested arrays | ||
<string><em>cnbuilder x 5,828,441 ops/sec ±0.39% (96 runs sampled)</em></string> | ||
classcat x 5,609,506 ops/sec ±0.25% (96 runs sampled) | ||
classnames x 1,076,019 ops/sec ±0.45% (91 runs sampled) | ||
clsx x 4,910,528 ops/sec ±0.19% (96 runs sampled) | ||
# OBJECTS NESTED IN ARRAYS | ||
<string><em>classcat × 4,745,927 ops/sec;</em></string> | ||
classnames × 1,124,121 ops/sec; | ||
clsx × 3,393,440 ops/sec; | ||
cnbuilder × 3,894,376 ops/sec; | ||
# objects nested in arrays | ||
cnbuilder x 5,652,700 ops/sec ±0.83% (95 runs sampled) | ||
<string><em>classcat x 5,756,021 ops/sec ±0.73% (96 runs sampled)</em></string> | ||
classnames x 1,599,139 ops/sec ±0.27% (95 runs sampled) | ||
clsx x 4,677,370 ops/sec ±0.57% (95 runs sampled) | ||
# MIXED | ||
<string><em>classcat × 5,226,767 ops/sec;</em></string> | ||
classnames × 1,569,844 ops/sec; | ||
clsx × 3,857,523 ops/sec; | ||
cnbuilder × 4,430,334 ops/sec; | ||
# mixed | ||
cnbuilder x 6,000,100 ops/sec ±0.74% (94 runs sampled) | ||
<string><em>classcat x 6,028,224 ops/sec ±0.31% (94 runs sampled)</em></string> | ||
classnames x 1,971,724 ops/sec ±0.30% (93 runs sampled) | ||
clsx x 4,922,858 ops/sec ±0.35% (94 runs sampled) | ||
# MIXED WITH WRONG DATA | ||
classcat × 682,359 ops/sec; | ||
classnames × 737,083 ops/sec; | ||
<string><em>clsx × 1,107,078 ops/sec;</em></string> | ||
cnbuilder × 1,087,857 ops/sec; | ||
# mixed with wrong data | ||
<string><em>cnbuilder x 1,915,258 ops/sec ±0.71% (95 runs sampled)</em></string> | ||
classcat x 1,550,198 ops/sec ±0.38% (94 runs sampled) | ||
classnames x 1,032,770 ops/sec ±0.50% (91 runs sampled) | ||
clsx x 1,732,645 ops/sec ±0.75% (92 runs sampled) | ||
</pre> |
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
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
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
179
12705
18
4
0
1