unique-classnames
English | 简体中文
A simple javascript utility for conditionally joining classNames together, and none of the classNames are duplicated.
Install
npm install unique-classnames --save
or
yarn add unique-classnames
Usage
The arguments can be string, number, array and object.
string:
;; // => 'foo bar foo2 bar2'; // => 'foo bar bar2'
number:
;; // => '1 2 3'; // => '1 2 3'
array:
;; // => '1 2 foo bar'; // => '1 2 foo bar'
object:
;; // => 'foo bar'; // => 'foo' ; // => 'foo bar'; // => 'bar' ; // => 'foo bar'; // => 'foo'; // => 'foo bar'
All types can be combined with each others. And if there are more than one 'className' with the same name, and the last one will cover the front one. For example:
; // => 'foo bar'
The 'foo' of {foo: false} will cover the one in 'foo bar' of {'foo bar': true}, but it will be covered by the last argument 'foo', so the result is {foo: true, bar: true} => 'foo bar'