New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

classname-js

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

classname-js

A JavaScript API for conditionally joining class names together.

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

className.JS

A JavaScript API for conditionally joining class names together.

Install

npm install --save-dev classname-js

Usage

Import className.JS
var className = require('classname-js');
In browser

To use className.JS in browser, just include className.js via <script> tag. The className method is attached to window.

Generate classNames
var className = require('classname-js');
className('foo', 'bar'); // 'foo bar'
Set classname of DOM elements

className.set(element, classnames...)

Set element's classname according to classnames spec.

  • element: DOM element or CSS selector.
  • classnames: Class names spec, same as regular className.

Example:

className.set('section .btn', 'btn', 'bar'); // all `section .btn` will become 'btn bar'
Supported types

className.js supports string, number, boolean, array, object, and even function.

For function:

  • If the function returns true, the class name will be its corresponding property name, e.g.: {hide: function () {return true}} // => 'hide'
  • If function returns a number greater than zero, the class name will be its corresponding property name, e.g.: {hide: function () {return 1}} // => 'hide'

For number:

If the number is greater than zero:

  • when in an object, the class name will be its corresponding property name, e.g.: {hide: 1} // => 'hide'
  • otherwise, the class name will simply be the number. e.g.: className(1) // => '1'

Below is a comprehensive example:

var className = require('classname-js');
className('btn', ['info', 'big'], {
        hide: function () {
            return btnElement.isActive ? true : false;
        },
        responsive: isResponsive || false
    });

// Suppose that `btnElement.isActive` and `isResponsive` are both true
// 'btn info big hide responsive'

License

MIT

Keywords

className

FAQs

Package last updated on 01 Jan 2016

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