Socket
Socket
Sign inDemoInstall

classname

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    classname

Easy configuration of class names


Version published
Weekly downloads
2.8K
decreased by-8.86%
Maintainers
1
Install size
8.71 kB
Created
Weekly downloads
 

Readme

Source

classname v.0.0.1

Simple tool to build (and apply) classes. This is very much inspired by Jed Watson's classnames, but with added functionality and slight differences in interface.

Install

Npm: npm install classname

Or just load classname.js in your browser, and call it directly.

Documentation

classname(1, 'one', false, 'two'); // '1 one two'

classname({
    one: true,
    two: false,
    three: true
});
// 'one three'

classname(['one', 'two'], {one: false, three: true});
// 'two three'

Objects always overwrite other types of parameters

classname({one: false}, ['one', 'two']);
// 'two'

classname handles more than string, numbers, arrays, and objects though. You can give it elements, nodelists, or jQuery elements too.

classname(document.querySelectorAll('.foo'), 'bar');
// 'foo bar' (assuming that the found elements do not have other class names as well)

classname can also set the class to the element for you. Use .setTo():

var el = document.getElementById('foo');

classname.setTo(el)('one', 'two');

el.className; // 'one two'

Keywords

FAQs

Last updated on 06 Apr 2015

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc