Neoclassical Philosophic Musings

    merge-class-names

    1.4.2 • Public • Published

    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

    Install

    npm i merge-class-names

    DownloadsWeekly Downloads

    776,159

    Version

    1.4.2

    License

    MIT

    Unpacked Size

    6.89 kB

    Total Files

    7

    Last publish

    Collaborators

    • wojtekmaj