Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

classwrap

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

classwrap - npm Package Compare versions

Comparing version
1.2.3
to
2.0.0
+14
-38
package.json
{
"name": "classwrap",
"description": "0.3 KB JavaScript utility for conditionally concatenating class names.",
"version": "1.2.3",
"main": "dist/classwrap.js",
"jsnext:main": "src/index.js",
"module": "src/index.js",
"typings": "classwrap.d.ts",
"license": "MIT",
"repository": "JorgeBucaran/classwrap",
"files": [
"src",
"dist",
"classwrap.d.ts"
],
"author": "Jorge Bucaran",
"keywords": [
"css",
"jsx",
"string",
"classname"
],
"version": "2.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest --coverage --no-cache && tsc -p tests/ts",
"build": "npm run bundle && npm run minify",
"bundle": "rollup -i src/index.js -o dist/classwrap.js -m -f umd -n classwrap",
"minify": "uglifyjs dist/classwrap.js -o dist/classwrap.js --mangle --compress warnings=false --pure-funcs=Object.defineProperty -p relative --source-map dist/classwrap.js.map",
"bench": "node bench",
"prepare": "npm run build",
"format": "prettier --semi false --write 'src/**/*.js' '{,tests/ts/}*.ts'",
"release": "npm run build && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push origin master && git push --tags && npm publish"
"test": "echo \"Error: no test specified\" && exit 1"
},
"babel": {
"presets": "env"
"repository": {
"type": "git",
"url": "git+https://github.com/npm/deprecate-holder.git"
},
"devDependencies": {
"babel-preset-env": "^1.6.1",
"jest": "^21.2.1",
"prettier": "~1.7.4",
"rollup": "^0.50.0",
"typescript": "^2.5.3",
"uglify-js": "^2.7.5"
}
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/npm/deprecate-holder/issues"
},
"homepage": "https://github.com/npm/deprecate-holder#readme",
"dependencies": {}
}
+3
-104

@@ -1,106 +0,5 @@

# Classwrap
[![Travis CI](https://img.shields.io/travis/JorgeBucaran/classwrap/master.svg)](https://travis-ci.org/JorgeBucaran/classwrap)
[![Codecov](https://img.shields.io/codecov/c/github/JorgeBucaran/classwrap/master.svg)](https://codecov.io/gh/JorgeBucaran/classwrap)
[![npm](https://img.shields.io/npm/v/classwrap.svg)](https://www.npmjs.org/package/classwrap)
# Deprecated Package
Classwrap is a 0.3 KB JavaScript utility for conditionally concatenating [class names](https://developer.mozilla.org/en-US/docs/Web/API/Element/className).
This package is no longer supported and has been deprecated. To avoid malicious use, npm is hanging on to the package name.
[Try it Online](https://codepen.io/JorgeBucaran/pen/GMRjRB)
```js
import cw from "classwrap"
export function ToggleButton({ toggle, isOn }) {
return (
<div class="btn" onclick={toggle}>
<div
class={cw({
circle: true,
off: !isOn,
on: isOn
})}
/>
<span
class={cw({
textOff: !isOn
})}
>
{isOn ? "ON" : "OFF"}
</span>
</div>
)
}
```
Classwrap works in all browsers >=IE9. Use it with your favorite JavaScript view library.
[![Classwrap](https://user-images.githubusercontent.com/56996/30416101-cda83bd4-9965-11e7-9db5-230ba3fc83fd.gif)](https://codepen.io/JorgeBucaran/full/GMRjRB/)
## Installation
Install with npm / Yarn.
<pre>
npm i <a href="https://www.npmjs.com/package/classwrap">classwrap</a>
</pre>
Then with a module bundler like [Rollup](https://github.com/rollup/rollup) or [Webpack](https://github.com/webpack/webpack), use as you would anything else.
```js
import cw from "classwrap"
```
Or download the minified library from a [unpkg](https://unpkg.com/classwrap@latest/dist/classwrap.js) or [jsDelivr](https://cdn.jsdelivr.net/npm/classwrap@latest/dist/classwrap.js).
```html
<script src="https://unpkg.com/classwrap"></script>
```
Then find it on `window.classwrap`.
## Usage
Classwrap joins all elements of an array or keys of an object into a string. If the value associated with a given key is falsy, the key will be ignored.
```js
cw([
"btn",
{
"btn-active": true,
"btn-large": false
}
]) // => btn btn-active
```
Nested arrays or objects are supported too. Use this feature to assemble classes with a common prefix.
```js
cw([
"tab",
{
tab: {
"--success": true,
"--error": false,
"--pending": false
}
}
]) // => tab tab--success
```
## Credits
Classwrap was inspired by [JedWatson/classnames](https://github.com/JedWatson/classnames) with support for nested objects and [improved](/bench/README.md) performance. It differs from classnames in that it does not accept [variable arguments](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments).
```js
cw("foo", "bar", "baz") // => foo
```
To solve this, wrap the arguments inside an array.
```js
cw(["foo", "bar", "baz"]) // => foo bar baz
```
## License
Classwrap is MIT licensed. See [LICENSE](LICENSE.md).
Please contact support@npmjs.com if you have questions about this package.
export as namespace classwrap
export interface ClassSet {
[key: string]: boolean | any | ClassSet
}
export type Class = string | number | ClassSet
/**
* Join all elements of an array or keys of an object into a string.
* If the value associated with a given key is falsy, the key will
* be ignored
*
* @param classes
*/
export default function(classes: Class | Class[]): string
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):e.classwrap=r()}(this,function(){"use strict";function e(r,t){var n,o="",f=typeof r;if(r&&"string"===f||"number"===f)return r;if(t=t||" ",Array.isArray(r)&&r.length)for(var i=0,u=r.length;i<u;i++)(n=e(r[i],t))&&(o+=(o&&t)+n);else for(var i in r)r.hasOwnProperty(i)&&(n=r[i])&&(o+=(o&&t)+i+("object"==typeof n?e(n,t+i):""));return o}return e});
//# sourceMappingURL=classwrap.js.map

Sorry, the diff of this file is not supported yet

{"version":3,"sources":["classwrap.js"],"names":["global","factory","exports","module","define","amd","classwrap","this","wrap","classes","prefix","value","className","type","Array","isArray","length","i","len","hasOwnProperty"],"mappings":"CAAC,SAAUA,EAAQC,GACC,gBAAZC,UAA0C,mBAAXC,QAAyBA,OAAOD,QAAUD,IAC9D,kBAAXG,SAAyBA,OAAOC,IAAMD,OAAOH,GACnDD,EAAOM,UAAYL,KACnBM,KAAM,WAAe,YAEvB,SAASC,GAAKC,EAASC,GACrB,GAAIC,GACAC,EAAY,GACZC,QAAcJ,EAElB,IAAKA,GAAoB,WAATI,GAA+B,WAATA,EACpC,MAAOJ,EAKT,IAFAC,EAASA,GAAU,IAEfI,MAAMC,QAAQN,IAAYA,EAAQO,OACpC,IAAK,GAAIC,GAAI,EAAGC,EAAMT,EAAQO,OAAQC,EAAIC,EAAKD,KACxCN,EAAQH,EAAKC,EAAQQ,GAAIP,MAC5BE,IAAcA,GAAaF,GAAUC,OAIzC,KAAK,GAAIM,KAAKR,GACRA,EAAQU,eAAeF,KAAON,EAAQF,EAAQQ,MAChDL,IACGA,GAAaF,GACdO,GACkB,gBAAVN,GAAqBH,EAAKG,EAAOD,EAASO,GAAK,IAK/D,OAAOL,GAGT,MAAOJ","file":"classwrap.js"}
Copyright © 2017-present [Jorge Bucaran](https://github.com/JorgeBucaran)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
export default function wrap(classes, prefix) {
var value
var className = ""
var type = typeof classes
if ((classes && type === "string") || type === "number") {
return classes
}
prefix = prefix || " "
if (Array.isArray(classes) && classes.length) {
for (var i = 0, len = classes.length; i < len; i++) {
if ((value = wrap(classes[i], prefix))) {
className += (className && prefix) + value
}
}
} else {
for (var i in classes) {
if (classes.hasOwnProperty(i) && (value = classes[i])) {
className +=
(className && prefix) +
i +
(typeof value === "object" ? wrap(value, prefix + i) : "")
}
}
}
return className
}