Earlier quoted context omitted.
While I can understand your skepticism on the first one, the second package is actually very useful. It doesn't just concatenate strings filtering out falsy values, it supports the whole old AngularJS class format. You can, for example, pass an object {string:booleanish} and it will add only the keys whose values are truthy. Pretty neat, actually.
> You can, for example, pass an object {string:booleanish} and it will add only the keys whose values are truthy. Why is this something you can't do on your own in a few lines of code? const classNames = (o, c=[]) => { for (let k in o) if (o[k]) c.push(k) // booleanish return c.join(" ") } This is not cool at all! Why import a trivial function over NPM to do this for you? Better to lower your dependency count and hav…
export default function classNames(...args) {
return args.filter(valid).map(single);
}
function valid(arg) {
return arg && (!Array.isArray(arg) || arg.length);
}
function single(arg) {
if (typeof arg === 'string') {
return arg;
} else if (Array.isArray(arg)) {
return classNames(...arg);
} else {
return Object.keys(arg).filter(k => ………
This is getting similar…