Socket
Socket
Sign inDemoInstall

dynamic-class-list

Package Overview
Dependencies
0
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    dynamic-class-list

A js package to get a string of dynamic and conditional css classes


Version published
Weekly downloads
2K
decreased by-27.49%
Maintainers
1
Install size
7.06 kB
Created
Weekly downloads
 

Readme

Source

css class conditional react dynamic

dynamic-class-list

A tiny, no-dependency library for creating conditional css classes.



Features:

  • Support string arguments.
  • Support number arguments.
  • Support object arguments.
  • Support array arguments.
  • Support function arguments.
  • No dependency.

Quickstart - CommonJS

npm install dynamic-class-list

Or using yarn

yarn add dynamic-class-list

Then require it in your module ...

var cl = require('dynamic-class-list').cl;

OR using ES6 imports

import { cl } from 'dynamic-class-list';

API

Arguments as strings

// As Arguments
cl('class1', 'class2'); // Output ==> "class1 class2"

Arguments as an array of strings

cl(['class1', 'class2']); // Output ==> "class1 class2"

cl([null, undefined, 3, 'class1', 'class2']); // Output ==> "3 class1 class2"

Arguments as an object

Note that the key is used as the class if its value is truthy

cl({ class1: true, class2: false }); // Output ==> "class1"

cl({ class1: undefined, class2: null, class3: true, class4: false }); // Output ==> "class3"

Note that the function must return a boolean.

cl({
  class1: function () {
    return false;
  },
  class2: function () {
    return true;
  },
});

// Output ==> "class2"

Mixed Arguments Types

cl('class1', 'class2', 2, null, undefined, ['class3', null, undefined, 4, 'class4'], {
  class5: function () {
    return false;
  },
  class6: function () {
    return true;
  },
  class7: undefined,
  class8: true,
  class9: false,
});

// Output ==> "class1 class2 2 class3 4 class4 class6 class8"

License

MIT © tusharf5

Keywords

FAQs

Last updated on 14 Sep 2022

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