Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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

320B JavaScript function for conditionally concatenating classNames.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Classwrap

Travis CI Codecov npm

Classwrap is a (320B) JavaScript function for conditionally concatenating classNames.

Hello World

Try it Online

function HelloButton(props) {
  const name = classwrap([
    "btn",
    "btn-large",
    {
      "btn-pressed": props.isPressed
    }
  ])
  return <button class={name}>{props.label}</button>
}

Installation

Install with npm / Yarn.

npm i classwrap

Then with a module bundler like rollup or webpack, use as you would anything else.

import wrap from "classwrap"

Or download the minified library from the CDN.

<script src="https://unpkg.com/classwrap"></script>

You can find the library 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, that key will be ignored.

classwrap([
  "btn",
  {
    "btn-active": true,
    "btn-large": false
  }
]) // => btn btn-active

Nested arrays or objects are supported too. This feature can be useful to create classes with a similar prefix.

classwrap([
  "tab",
  {
    tab: {
      "--success": true,
      "--error": false,
      "--pending": false
    }
  }
]) // => tab tab--success

Credits

Classwrap was inspired by JedWatson/classnames with support for nested objects and improved performance.

License

Classwrap is MIT licensed. See LICENSE.

Keywords

FAQs

Package last updated on 12 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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