@fvilers/cls
v2.0.0
Published
An helper function for constructing className strings conditionally
Downloads
6
Maintainers
Readme
@fvilers/cls
An helper function for constructing className strings conditionally
Installation
npm install @fvilers/cls
or
yarn add @fvilers/cls
ECMAScript module
Starting with version 2.0.0, this library will be published as an ECMAScript module.
Usage
import cls from "@fvilers/cls";
// Strings (variadic)
cls("foo", true && "bar", "baz");
// It will output: 'foo bar baz'
// Objects
cls({ foo: true, bar: false, baz: isTrue() });
// It will output: 'foo baz'
// Objects (variadic)
cls({ foo: true }, { bar: false }, null, { "--foobar": "hello" });
// It will output: 'foo --foobar'
// Arrays
cls(["foo", 0, false, "bar"]);
// It will output: 'foo bar'
// Arrays (variadic)
cls(["foo"], ["", 0, false, "bar"], [["baz", [["hello"], "there"]]]);
// It will output: 'foo bar baz hello there'
// Kitchen sink (with nesting)
cls(
"foo",
[1 && "bar", { baz: false, bat: null }, ["hello", ["world"]]],
"cya"
);
// It will output: 'foo bar hello world cya'