Socket
Socket
Sign inDemoInstall

merge-class-names

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    merge-class-names

A function that merges given class names, no matter their format: string with single or multiple class names or an array of class names. Filters out invalid class names as well.


Version published
Weekly downloads
508K
decreased by-17.21%
Maintainers
1
Install size
7.71 kB
Created
Weekly downloads
 

Readme

Source

npm downloads CI dependencies dev dependencies tested with jest

Merge-Class-Names

A function that merges given class names, no matter their format. Filters out invalid class names as well.

tl;dr

  • Install by executing npm install merge-class-names or yarn add merge-class-names.
  • Import by adding import mergeClassNames from 'merge-class-names'.
  • Use it in className like so: <div className={mergeClassNames('foo', condition && 'bar', arrayOfClasses)} />

Accepted formats

  • Strings with one or multiple class names: a, a b
  • Array of strings with one or multiple class names: ['a', 'b'], ['a b', 'c d'].

Examples

> mergeClassNames('a', 'b', 'c');
< 'a b c'

> mergeClassNames('a b', 'c d', 'e f');
< 'a b c d e f'

> mergeClassNames(['a', 'b'], ['c', 'd']);
< 'a b c d'

> mergeClassNames(['a b', 'c d'], ['e f', 'g h']);
< 'a b c d e f g h'

> mergeClassNames('a', 'b', falsyCondition && 'c');
< 'a b'

> mergeClassNames('a', 'b', 'c', null, ['d', null], () => {}, 'e', undefined);
< 'a b c d e'

License

The MIT License.

Author

Wojciech Maj
kontakt@wojtekmaj.pl
https://wojtekmaj.pl

Keywords

FAQs

Last updated on 26 Aug 2021

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