/to-class

Build a string of conditional, deduplicated classNames using whatever you can throw at it.

Primary LanguageJavaScriptMIT LicenseMIT

to-class

Build status Coverage npm version Donate

Builds a string of conditional, deduplicated classNames using whatever you can throw at it.

# npm
npm install to-class

# yarn
yarn add to-class

Usage

import toClass from 'to-class';

toClass('foo', 'bar', 'foo'); // => 'foo bar'
toClass(['foo', 'bar', false]); // => 'foo bar'
toClass('foo', {bar: true}); // => 'foo bar'
toClass({foo: true}, {bar: true}); // => 'foo bar'
toClass({foo: true, bar: false}); // => 'foo'
toClass({foo: true, bar: true}, ['bar', 'baz', ['foo']], 'foo'); // => 'foo bar baz'

Polyfill

If you need to support browsers <= IE11 you can import the polyfilled version.

import toClass from 'to-class/polyfill';