1.1.3 • Published 5 years ago

cookednames v1.1.3

Weekly downloads
10
License
BSD-3-Clause
Repository
github
Last release
5 years ago

CookedNames

npm version npm package size

A simple JavaScript utility function for conditionally concatenating css class names and strings together.

Usage

The cookedNames function takes any number of arguments which can be a string, number, object or list. All truthy arguments will be kept while falsy are discarded.

cookedNames("Hello", "World"); // => "Hello World"
cookedNames("Hello", ["World"]); // => "Hello World"
cookedNames(["Hello"], ["World"]); // => "Hello World"
cookedNames("Hello", {World: true}); // => "Hello World"
cookedNames(["Hello"], {World: true}); // => "Hello World"
cookedNames({Hello: true, World: true}); // => "Hello World"
cookedNames({Hello: true}, {World: true}); // => "Hello World"

When used inside an environment with the ability to use computed keys, the function can be used to create compact class name combinations.

const { active, block, disabled, className } = this.props;
cookedNames(
  "button"
  {active},   // true
  {block},    // false
  {disabled}, // true
  className,  // error
); // => "button active disabled error"

Arrays will be recursively flattened to allow for nested collection of arguments if desirable.

cookedNames(["Hello", ["World", ["?", ["!"]]]]); // => "Hello World ? !"
1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago